|
74 | 74 | environmentAnnotation: "testing", |
75 | 75 | criticalityAnnotation: "low", |
76 | 76 | sensitivityAnnotation: "public", |
| 77 | + priorityAnnotation: "p1", |
77 | 78 | }, |
78 | 79 | }, |
79 | 80 | Spec: networkingv1.IngressSpec{ |
@@ -119,6 +120,33 @@ var ( |
119 | 120 | }, |
120 | 121 | }, |
121 | 122 | } |
| 123 | + |
| 124 | + testIngressMultiLabel = &networkingv1.Ingress{ |
| 125 | + ObjectMeta: metav1.ObjectMeta{ |
| 126 | + Name: "testMultiLabel", |
| 127 | + Namespace: "testNamespace", |
| 128 | + Annotations: map[string]string{ |
| 129 | + "com.uswitch.heimdall/5xx-rate": "0.001", |
| 130 | + ownerAnnotation: "testIngressOwner", |
| 131 | + environmentAnnotation: "testing", |
| 132 | + criticalityAnnotation: "low", |
| 133 | + sensitivityAnnotation: "public", |
| 134 | + "com.uswitch.heimdall/label-priority": "p2", |
| 135 | + "com.uswitch.heimdall/label-channel": "testing", |
| 136 | + "com.uswitch.heimdall/label-region": "eu-west-1", |
| 137 | + }, |
| 138 | + }, |
| 139 | + Spec: networkingv1.IngressSpec{ |
| 140 | + DefaultBackend: &networkingv1.IngressBackend{ |
| 141 | + Service: &networkingv1.IngressServiceBackend{ |
| 142 | + Name: "testService", |
| 143 | + Port: networkingv1.ServiceBackendPort{ |
| 144 | + Number: 80, |
| 145 | + }, |
| 146 | + }, |
| 147 | + }, |
| 148 | + }, |
| 149 | + } |
122 | 150 | ) |
123 | 151 |
|
124 | 152 | func TestIngressAnnotationsDefaultBackend(t *testing.T) { |
@@ -147,6 +175,10 @@ func TestIngressAnnotationsDefaultBackend(t *testing.T) { |
147 | 175 | assert.Assert(t, is.Len(promrules, 1)) |
148 | 176 | assert.Equal(t, promrules[0].Spec.Groups[0].Rules[0].Expr.StrVal, expr) |
149 | 177 | assert.Equal(t, promrules[0].Spec.Groups[0].Rules[0].Labels["owner"], "testIngressOwner") |
| 178 | + assert.Equal(t, promrules[0].Spec.Groups[0].Rules[0].Labels["environment"], "testing") |
| 179 | + assert.Equal(t, promrules[0].Spec.Groups[0].Rules[0].Labels["criticality"], "low") |
| 180 | + assert.Equal(t, promrules[0].Spec.Groups[0].Rules[0].Labels["sensitivity"], "public") |
| 181 | + assert.Equal(t, promrules[0].Spec.Groups[0].Rules[0].Labels["priority"], "p1") |
150 | 182 | } |
151 | 183 |
|
152 | 184 | func TestIngressAnnotationsRuleBackend(t *testing.T) { |
@@ -186,3 +218,19 @@ func TestNamesMatch(t *testing.T) { |
186 | 218 | service = checkNamesMatch(services) |
187 | 219 | assert.Equal(t, "", service) |
188 | 220 | } |
| 221 | + |
| 222 | +func TestIngressMultipleCustomLabels(t *testing.T) { |
| 223 | + log.Setup(log.DEBUG_LEVEL) |
| 224 | + |
| 225 | + client := fake.NewSimpleClientset(testService, testDeployment, testReplicaset, testPod) |
| 226 | + |
| 227 | + template, err := NewPrometheusRuleTemplateManager("../../kube/config/templates", client) |
| 228 | + |
| 229 | + promrules, err := template.CreateFromIngress(testIngressMultiLabel) |
| 230 | + assert.Assert(t, is.Nil(err)) |
| 231 | + assert.Assert(t, is.Len(promrules, 1)) |
| 232 | + assert.Equal(t, promrules[0].Spec.Groups[0].Rules[0].Labels["priority"], "p2") |
| 233 | + assert.Equal(t, promrules[0].Spec.Groups[0].Rules[0].Labels["channel"], "testing") |
| 234 | + assert.Equal(t, promrules[0].Spec.Groups[0].Rules[0].Labels["region"], "eu-west-1") |
| 235 | +} |
| 236 | + |
0 commit comments