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, )
| 39 | // AllPodsHaveLabels verifies if the labels defined in a map are included |
| 40 | // in all the pods of a cluster |
| 41 | func 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 |
no test coverage detected