@@ -29,7 +29,13 @@ import (
29
29
func TestPodDisruptionBudgetStore (t * testing.T ) {
30
30
// Fixed metadata on type and help text. We prepend this to every expected
31
31
// output so we only have to modify a single place when doing adjustments.
32
- const metadata = `
32
+ const labelsAndAnnotationsMetaData = `
33
+ # HELP kube_poddisruptionbudget_annotations Kubernetes annotations converted to Prometheus labels.
34
+ # TYPE kube_poddisruptionbudget_annotations gauge
35
+ # HELP kube_poddisruptionbudget_labels Kubernetes labels converted to Prometheus labels.
36
+ # TYPE kube_poddisruptionbudget_labels gauge
37
+ `
38
+ const metadata = labelsAndAnnotationsMetaData + `
33
39
# HELP kube_poddisruptionbudget_created Unix creation timestamp
34
40
# TYPE kube_poddisruptionbudget_created gauge
35
41
# HELP kube_poddisruptionbudget_status_current_healthy Current number of healthy pods
@@ -61,6 +67,8 @@ func TestPodDisruptionBudgetStore(t *testing.T) {
61
67
},
62
68
},
63
69
Want : metadata + `
70
+ kube_poddisruptionbudget_annotations{namespace="ns1",poddisruptionbudget="pdb1"} 1
71
+ kube_poddisruptionbudget_labels{namespace="ns1",poddisruptionbudget="pdb1"} 1
64
72
kube_poddisruptionbudget_created{namespace="ns1",poddisruptionbudget="pdb1"} 1.5e+09
65
73
kube_poddisruptionbudget_status_current_healthy{namespace="ns1",poddisruptionbudget="pdb1"} 12
66
74
kube_poddisruptionbudget_status_desired_healthy{namespace="ns1",poddisruptionbudget="pdb1"} 10
@@ -85,17 +93,49 @@ func TestPodDisruptionBudgetStore(t *testing.T) {
85
93
},
86
94
},
87
95
Want : metadata + `
96
+ kube_poddisruptionbudget_annotations{namespace="ns2",poddisruptionbudget="pdb2"} 1
97
+ kube_poddisruptionbudget_labels{namespace="ns2",poddisruptionbudget="pdb2"} 1
88
98
kube_poddisruptionbudget_status_current_healthy{namespace="ns2",poddisruptionbudget="pdb2"} 8
89
99
kube_poddisruptionbudget_status_desired_healthy{namespace="ns2",poddisruptionbudget="pdb2"} 9
90
100
kube_poddisruptionbudget_status_pod_disruptions_allowed{namespace="ns2",poddisruptionbudget="pdb2"} 0
91
101
kube_poddisruptionbudget_status_expected_pods{namespace="ns2",poddisruptionbudget="pdb2"} 10
92
102
kube_poddisruptionbudget_status_observed_generation{namespace="ns2",poddisruptionbudget="pdb2"} 1111
93
103
` ,
94
104
},
105
+ {
106
+ AllowAnnotationsList : []string {
107
+ "app.k8s.io/owner" ,
108
+ },
109
+ AllowLabelsList : []string {
110
+ "app" ,
111
+ },
112
+ Obj : & v1beta1.PodDisruptionBudget {
113
+ ObjectMeta : metav1.ObjectMeta {
114
+ Name : "pdb_with_allowed_labels_and_annotations" ,
115
+ Namespace : "ns" ,
116
+ Annotations : map [string ]string {
117
+ "app.k8s.io/owner" : "mysql-server" ,
118
+ "foo" : "bar" ,
119
+ },
120
+ Labels : map [string ]string {
121
+ "app" : "mysql-server" ,
122
+ "hello" : "world" ,
123
+ },
124
+ },
125
+ },
126
+ Want : labelsAndAnnotationsMetaData + `
127
+ kube_poddisruptionbudget_annotations{annotation_app_k8s_io_owner="mysql-server",namespace="ns",poddisruptionbudget="pdb_with_allowed_labels_and_annotations"} 1
128
+ kube_poddisruptionbudget_labels{label_app="mysql-server",namespace="ns",poddisruptionbudget="pdb_with_allowed_labels_and_annotations"} 1
129
+ ` ,
130
+ MetricNames : []string {
131
+ "kube_poddisruptionbudget_annotations" ,
132
+ "kube_poddisruptionbudget_labels" ,
133
+ },
134
+ },
95
135
}
96
136
for i , c := range cases {
97
- c .Func = generator .ComposeMetricGenFuncs (podDisruptionBudgetMetricFamilies )
98
- c .Headers = generator .ExtractMetricFamilyHeaders (podDisruptionBudgetMetricFamilies )
137
+ c .Func = generator .ComposeMetricGenFuncs (podDisruptionBudgetMetricFamilies ( c . AllowAnnotationsList , c . AllowLabelsList ) )
138
+ c .Headers = generator .ExtractMetricFamilyHeaders (podDisruptionBudgetMetricFamilies ( c . AllowAnnotationsList , c . AllowLabelsList ) )
99
139
if err := c .run (); err != nil {
100
140
t .Errorf ("unexpected collecting result in %vth run:\n %s" , i , err )
101
141
}
0 commit comments