...
1 package k8s
2
3 import (
4 "testing"
5
6 "github.com/go-test/deep"
7 appsv1 "k8s.io/api/apps/v1"
8 corev1 "k8s.io/api/core/v1"
9 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10 )
11
12 func TestGetPodLabels(t *testing.T) {
13 t.Run("Maps proxy labels to prometheus labels", func(t *testing.T) {
14 pod := &corev1.Pod{
15 ObjectMeta: metav1.ObjectMeta{
16 Name: "test-pod",
17 Namespace: "test-ns",
18 Labels: map[string]string{
19 ControllerNSLabel: "linkerd-namespace",
20 appsv1.DefaultDeploymentUniqueLabelKey: "test-pth",
21 },
22 },
23 Spec: corev1.PodSpec{
24 ServiceAccountName: "test-sa",
25 },
26 }
27
28 ownerKind := "deployment"
29 ownerName := "test-deployment"
30
31 expectedLabels := map[string]string{
32 "control_plane_ns": "linkerd-namespace",
33 "deployment": "test-deployment",
34 "pod": "test-pod",
35 "pod_template_hash": "test-pth",
36 "serviceaccount": "test-sa",
37 }
38
39 podLabels := GetPodLabels(ownerKind, ownerName, pod)
40
41 if diff := deep.Equal(podLabels, expectedLabels); diff != nil {
42 t.Errorf("labels %+v", diff)
43 }
44 })
45 }
46
View as plain text