MCPcopy Create free account
hub / github.com/cloudnative-pg/cloudnative-pg / AllPodsHaveAnnotations

Function AllPodsHaveAnnotations

tests/utils/clusterutils/cluster.go:68–91  ·  view source on GitHub ↗

AllPodsHaveAnnotations verifies if the annotations defined in a map are included in all the pods of a cluster

(
	ctx context.Context,
	crudClient client.Client,
	namespace, clusterName string,
	annotations map[string]string,
)

Source from the content-addressed store, hash-verified

66// AllPodsHaveAnnotations verifies if the annotations defined in a map are included
67// in all the pods of a cluster
68func AllPodsHaveAnnotations(
69 ctx context.Context,
70 crudClient client.Client,
71 namespace, clusterName string,
72 annotations map[string]string,
73) (bool, error) {
74 cluster, err := Get(ctx, crudClient, namespace, clusterName)
75 if err != nil {
76 return false, err
77 }
78 podList, err := ListPods(ctx, crudClient, namespace, clusterName)
79 if err != nil {
80 return false, err
81 }
82 if len(podList.Items) != cluster.Spec.Instances {
83 return false, fmt.Errorf("%v found instances, %v expected", len(podList.Items), cluster.Spec.Instances)
84 }
85 for _, pod := range podList.Items {
86 if !pods.HasAnnotations(pod, annotations) {
87 return false, fmt.Errorf("%v found annotations, %v expected", pod.Annotations, annotations)
88 }
89 }
90 return true, nil
91}
92
93// HasLabels verifies that the labels of a cluster contain a specified
94// labels map

Callers 1

Calls 3

HasAnnotationsFunction · 0.92
ListPodsFunction · 0.85
GetFunction · 0.70

Tested by

no test coverage detected