Skip to content

Commit 375ac6f

Browse files
authored
feat(events) list Kong name for multi-Services (#3318)
Include the Kong service name when emitting Events related to multi-Service backend annotation inconsistency. This name indicates the parent route resource. Reviewing the route resource will show the other Services used by the problem rule.
1 parent 207810f commit 375ac6f

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,9 @@ Adding a new version? You'll need three changes:
9292
- Change existing `resolvedRefs` condition in status `HTTPRoute` if there is
9393
already one to avoid multiple appearance of conditions with same type
9494
[#3386](https://github.com/Kong/kubernetes-ingress-controller/pull/3386)
95+
- Event messages for invalid multi-Service backends now indicate their derived
96+
Kong resource name.
97+
[#3318](https://github.com/Kong/kubernetes-ingress-controller/pull/3318)
9598

9699
### Deprecated
97100

internal/dataplane/parser/ingressrules.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (ir *ingressRules) populateServices(log logrus.FieldLogger, s store.Storer,
5959

6060
// if the Kubernetes services have been deemed invalid, log an error message
6161
// and skip the current service.
62-
if !servicesAllUseTheSameKongAnnotations(k8sServices, seenAnnotations, failuresCollector) {
62+
if !servicesAllUseTheSameKongAnnotations(k8sServices, seenAnnotations, failuresCollector, key) {
6363
// The Kong services not having all the k8s services correctly annotated must be marked
6464
// as to be skipped.
6565
serviceNamesToSkip[key] = nil
@@ -255,6 +255,7 @@ func servicesAllUseTheSameKongAnnotations(
255255
services []*corev1.Service,
256256
annotations map[string]string,
257257
failuresCollector *failures.ResourceFailuresCollector,
258+
kongServiceName string,
258259
) bool {
259260
match := true
260261
for _, service := range services {
@@ -270,9 +271,10 @@ func servicesAllUseTheSameKongAnnotations(
270271
valueForThisObject, ok := service.Annotations[k]
271272
if !ok {
272273
failuresCollector.PushResourceFailure(
273-
fmt.Sprintf("in the backend group of %d kubernetes services some have the %s annotation while others don't. "+
274-
"this is not supported: when multiple services comprise a backend all kong annotations "+
275-
"between them must be set to the same value", len(services), k),
274+
fmt.Sprintf("Service has inconsistent %s annotation and is used in multi-Service backend %s. "+
275+
"All Services in a multi-Service backend must have matching Kong annotations. Review the "+
276+
"associated route resource and align annotations in its multi-Service backends.",
277+
k, kongServiceName),
276278
service.DeepCopy(),
277279
)
278280
match = false
@@ -282,9 +284,10 @@ func servicesAllUseTheSameKongAnnotations(
282284

283285
if valueForThisObject != v {
284286
failuresCollector.PushResourceFailure(
285-
fmt.Sprintf("the value of annotation %s is different between the %d services which comprise this backend. "+
286-
"this is not supported: when multiple services comprise a backend all kong annotations "+
287-
"between them must be set to the same value", k, len(services)),
287+
fmt.Sprintf("Service has inconsistent %s annotation and is used in multi-Service backend %s. "+
288+
"All Services in a multi-Service backend must have matching Kong annotations. Review the "+
289+
"associated route resource and align annotations in its multi-Service backends.",
290+
k, kongServiceName),
288291
service.DeepCopy(),
289292
)
290293
match = false

internal/dataplane/parser/ingressrules_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ func TestDoK8sServicesMatchAnnotations(t *testing.T) {
477477
},
478478
expected: false,
479479
expectedLogEntries: []string{
480-
"in the backend group of 3 kubernetes services some have the konghq.com/foo annotation while others don't",
480+
"Service has inconsistent konghq.com/foo annotation and is used in multi-Service backend",
481481
},
482482
},
483483
{
@@ -519,16 +519,16 @@ func TestDoK8sServicesMatchAnnotations(t *testing.T) {
519519
},
520520
expected: false,
521521
expectedLogEntries: []string{
522-
"the value of annotation konghq.com/foo is different between the 3 services which comprise this backend.",
523-
"the value of annotation konghq.com/foo is different between the 3 services which comprise this backend.",
522+
"Service has inconsistent konghq.com/foo annotation and is used in multi-Service backend",
523+
"Service has inconsistent konghq.com/foo annotation and is used in multi-Service backend",
524524
},
525525
},
526526
} {
527527
t.Run(tt.name, func(t *testing.T) {
528528
logger, loggerHook := test.NewNullLogger()
529529
failuresCollector, err := failures.NewResourceFailuresCollector(logger)
530530
require.NoError(t, err)
531-
assert.Equal(t, tt.expected, servicesAllUseTheSameKongAnnotations(tt.services, tt.annotations, failuresCollector))
531+
assert.Equal(t, tt.expected, servicesAllUseTheSameKongAnnotations(tt.services, tt.annotations, failuresCollector, ""))
532532
assert.Len(t, failuresCollector.PopResourceFailures(), len(tt.expectedLogEntries), "expecting as many translation failures as log entries")
533533
for i := range tt.expectedLogEntries {
534534
assert.Contains(t, loggerHook.AllEntries()[i].Message, tt.expectedLogEntries[i])

test/integration/translation_failures_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ func TestTranslationFailures(t *testing.T) {
127127
return expectedTranslationFailure{
128128
// expect event for service2 as it doesn't have annotations that service1 has
129129
causingObjects: []client.Object{service2},
130-
reasonContains: "when multiple services comprise a backend all kong annotations between them must be set to the same value",
130+
reasonContains: "All Services in a multi-Service backend must have matching Kong annotations. " +
131+
"Review the associated route resource and align annotations in its multi-Service backends.",
131132
}
132133
},
133134
},

0 commit comments

Comments
 (0)