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

Function AllPodsHaveLabels

tests/utils/clusterutils/cluster.go:41–64  ·  view source on GitHub ↗

AllPodsHaveLabels verifies if the labels defined in a map are included in all the pods of a cluster

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

Source from the content-addressed store, hash-verified

39// AllPodsHaveLabels verifies if the labels defined in a map are included
40// in all the pods of a cluster
41func AllPodsHaveLabels(
42 ctx context.Context,
43 crudClient client.Client,
44 namespace, clusterName string,
45 labels map[string]string,
46) (bool, error) {
47 cluster, err := Get(ctx, crudClient, namespace, clusterName)
48 if err != nil {
49 return false, err
50 }
51 podList, err := ListPods(ctx, crudClient, namespace, clusterName)
52 if err != nil {
53 return false, err
54 }
55 if len(podList.Items) != cluster.Spec.Instances {
56 return false, fmt.Errorf("%v found instances, %v expected", len(podList.Items), cluster.Spec.Instances)
57 }
58 for _, pod := range podList.Items {
59 if !pods.HasLabels(pod, labels) {
60 return false, fmt.Errorf("%v found labels, expected %v", pod.Labels, labels)
61 }
62 }
63 return true, nil
64}
65
66// AllPodsHaveAnnotations verifies if the annotations defined in a map are included
67// in all the pods of a cluster

Callers 1

Calls 3

HasLabelsFunction · 0.92
ListPodsFunction · 0.85
GetFunction · 0.70

Tested by

no test coverage detected