diff --git a/internal/ingress/annotations/annotations.go b/internal/ingress/annotations/annotations.go index 727e9f68c9..a59198bc65 100644 --- a/internal/ingress/annotations/annotations.go +++ b/internal/ingress/annotations/annotations.go @@ -31,12 +31,12 @@ const ( ) const ( - ingressClassKey = "kubernetes.io/ingress.class" + IngressClassKey = "kubernetes.io/ingress.class" deprecatedAnnotationPrefix = "configuration.konghq.com" annotationPrefix = "konghq.com" - deprecatedPluginsKey = "plugins.konghq.com" + DeprecatedPluginsKey = "plugins.konghq.com" deprecatedConfigurationKey = deprecatedAnnotationPrefix configurationKey = "/override" @@ -80,7 +80,7 @@ func IngressClassValidatorFunc( ingressClass string) func(obj metav1.Object, handling ClassMatching) bool { return func(obj metav1.Object, handling ClassMatching) bool { - ingress := obj.GetAnnotations()[ingressClassKey] + ingress := obj.GetAnnotations()[IngressClassKey] return validIngress(ingress, ingressClass, handling) } } @@ -91,7 +91,7 @@ func IngressClassValidatorFuncFromObjectMeta( ingressClass string) func(obj *metav1.ObjectMeta, handling ClassMatching) bool { return func(obj *metav1.ObjectMeta, handling ClassMatching) bool { - ingress := obj.GetAnnotations()[ingressClassKey] + ingress := obj.GetAnnotations()[IngressClassKey] return validIngress(ingress, ingressClass, handling) } } @@ -114,7 +114,7 @@ func pluginsFromAnnotations(anns map[string]string) (string, bool) { if exists { return value, exists } - value, exists = anns[deprecatedPluginsKey] + value, exists = anns[DeprecatedPluginsKey] return value, exists } diff --git a/internal/ingress/annotations/annotations_test.go b/internal/ingress/annotations/annotations_test.go index 205dd62928..d55c04a5d5 100644 --- a/internal/ingress/annotations/annotations_test.go +++ b/internal/ingress/annotations/annotations_test.go @@ -60,7 +60,7 @@ func TestIngressClassValidatorFunc(t *testing.T) { data := map[string]string{} ing.SetAnnotations(data) for _, test := range tests { - ing.Annotations[ingressClassKey] = test.ingress + ing.Annotations[IngressClassKey] = test.ingress f := IngressClassValidatorFunc(test.controller) result := f(&ing.ObjectMeta, test.classMatching) @@ -190,7 +190,7 @@ func TestExtractKongPluginsFromAnnotations(t *testing.T) { name: "legacy annotation", args: args{ anns: map[string]string{ - "plugins.konghq.com": "kp-rl, kp-cors", + DeprecatedPluginsKey: "kp-rl, kp-cors", }, }, want: []string{"kp-rl", "kp-cors"}, @@ -208,7 +208,7 @@ func TestExtractKongPluginsFromAnnotations(t *testing.T) { name: "annotation prioriy", args: args{ anns: map[string]string{ - "plugins.konghq.com": "a,b", + DeprecatedPluginsKey: "a,b", "konghq.com/plugins": "kp-rl, kp-cors", }, }, diff --git a/internal/ingress/controller/parser/parser_test.go b/internal/ingress/controller/parser/parser_test.go index 87bae3eb68..4d29afc6d0 100644 --- a/internal/ingress/controller/parser/parser_test.go +++ b/internal/ingress/controller/parser/parser_test.go @@ -9,6 +9,7 @@ import ( "time" "github.com/kong/go-kong/kong" + "github.com/kong/kubernetes-ingress-controller/internal/ingress/annotations" "github.com/kong/kubernetes-ingress-controller/internal/ingress/store" "github.com/kong/kubernetes-ingress-controller/internal/ingress/utils" configurationv1 "github.com/kong/kubernetes-ingress-controller/pkg/apis/configuration/v1" @@ -149,7 +150,7 @@ func TestGlobalPlugin(t *testing.T) { "global": "true", }, Annotations: map[string]string{ - "kubernetes.io/ingress.class": "kong", + annotations.IngressClassKey: annotations.DefaultIngressClass, }, }, Protocols: []string{"http"}, @@ -197,8 +198,8 @@ func TestSecretConfigurationPlugin(t *testing.T) { Name: "foo", Namespace: "default", Annotations: map[string]string{ - "plugins.konghq.com": "foo-plugin", - "kubernetes.io/ingress.class": "kong", + annotations.DeprecatedPluginsKey: "foo-plugin", + annotations.IngressClassKey: annotations.DefaultIngressClass, }, }, Spec: networking.IngressSpec{ @@ -227,8 +228,8 @@ func TestSecretConfigurationPlugin(t *testing.T) { Name: "bar", Namespace: "default", Annotations: map[string]string{ - "plugins.konghq.com": "bar-plugin", - "kubernetes.io/ingress.class": "kong", + annotations.DeprecatedPluginsKey: "bar-plugin", + annotations.IngressClassKey: annotations.DefaultIngressClass, }, }, Spec: networking.IngressSpec{ @@ -279,7 +280,7 @@ func TestSecretConfigurationPlugin(t *testing.T) { "global": "true", }, Annotations: map[string]string{ - "kubernetes.io/ingress.class": "kong", + annotations.IngressClassKey: annotations.DefaultIngressClass, }, }, Protocols: []string{"http"}, @@ -712,6 +713,9 @@ func TestCACertificate(t *testing.T) { Labels: map[string]string{ "konghq.com/ca-cert": "true", }, + Annotations: map[string]string{ + annotations.IngressClassKey: annotations.DefaultIngressClass, + }, }, Data: map[string][]byte{ "id": []byte("8214a145-a328-4c56-ab72-2973a56d4eae"), @@ -744,6 +748,9 @@ func TestCACertificate(t *testing.T) { Labels: map[string]string{ "konghq.com/ca-cert": "true", }, + Annotations: map[string]string{ + annotations.IngressClassKey: annotations.DefaultIngressClass, + }, }, Data: map[string][]byte{ "id": []byte("8214a145-a328-4c56-ab72-2973a56d4eae"), @@ -757,6 +764,9 @@ func TestCACertificate(t *testing.T) { Labels: map[string]string{ "konghq.com/ca-cert": "true", }, + Annotations: map[string]string{ + annotations.IngressClassKey: annotations.DefaultIngressClass, + }, }, Data: map[string][]byte{ "id": []byte("570c28aa-e784-43c1-8ec7-ae7f4ce40189"), @@ -785,6 +795,9 @@ func TestCACertificate(t *testing.T) { Labels: map[string]string{ "konghq.com/ca-cert": "true", }, + Annotations: map[string]string{ + annotations.IngressClassKey: annotations.DefaultIngressClass, + }, }, Data: map[string][]byte{ "id": []byte("8214a145-a328-4c56-ab72-2973a56d4eae"), @@ -798,6 +811,9 @@ func TestCACertificate(t *testing.T) { Labels: map[string]string{ "konghq.com/ca-cert": "true", }, + Annotations: map[string]string{ + annotations.IngressClassKey: annotations.DefaultIngressClass, + }, }, Data: map[string][]byte{ "id": []byte("570c28aa-e784-43c1-8ec7-ae7f4ce40189"), @@ -811,6 +827,9 @@ func TestCACertificate(t *testing.T) { Labels: map[string]string{ "konghq.com/ca-cert": "true", }, + Annotations: map[string]string{ + annotations.IngressClassKey: annotations.DefaultIngressClass, + }, }, Data: map[string][]byte{ // id is missing @@ -845,7 +864,7 @@ func TestServiceClientCertificate(t *testing.T) { Name: "foo", Namespace: "default", Annotations: map[string]string{ - "kubernetes.io/ingress.class": "kong", + annotations.IngressClassKey: annotations.DefaultIngressClass, }, }, Spec: networking.IngressSpec{ @@ -927,7 +946,7 @@ func TestServiceClientCertificate(t *testing.T) { Name: "foo", Namespace: "default", Annotations: map[string]string{ - "kubernetes.io/ingress.class": "kong", + annotations.IngressClassKey: annotations.DefaultIngressClass, }, }, Spec: networking.IngressSpec{ @@ -997,7 +1016,7 @@ func TestKongRouteAnnotations(t *testing.T) { Namespace: "default", Annotations: map[string]string{ "configuration.konghq.com/strip-path": "trUe", - "kubernetes.io/ingress.class": "kong", + annotations.IngressClassKey: "kong", }, }, Spec: networking.IngressSpec{ @@ -1074,7 +1093,7 @@ func TestKongRouteAnnotations(t *testing.T) { Name: "bar", Namespace: "default", Annotations: map[string]string{ - "kubernetes.io/ingress.class": "kong", + annotations.IngressClassKey: "kong", "configuration.konghq.com/strip-path": "false", }, }, @@ -1153,7 +1172,7 @@ func TestKongRouteAnnotations(t *testing.T) { Name: "bar", Namespace: "default", Annotations: map[string]string{ - "kubernetes.io/ingress.class": "kong", + annotations.IngressClassKey: "kong", "konghq.com/https-redirect-status-code": "301", }, }, @@ -1233,7 +1252,7 @@ func TestKongRouteAnnotations(t *testing.T) { Name: "bar", Namespace: "default", Annotations: map[string]string{ - "kubernetes.io/ingress.class": "kong", + annotations.IngressClassKey: "kong", "konghq.com/https-redirect-status-code": "whoops", }, }, @@ -1312,8 +1331,8 @@ func TestKongRouteAnnotations(t *testing.T) { Name: "bar", Namespace: "default", Annotations: map[string]string{ - "konghq.com/preserve-host": "faLsE", - "kubernetes.io/ingress.class": "kong", + "konghq.com/preserve-host": "faLsE", + annotations.IngressClassKey: annotations.DefaultIngressClass, }, }, Spec: networking.IngressSpec{ @@ -1391,8 +1410,8 @@ func TestKongRouteAnnotations(t *testing.T) { Name: "bar", Namespace: "default", Annotations: map[string]string{ - "kubernetes.io/ingress.class": "kong", - "konghq.com/preserve-host": "wiggle wiggle wiggle", + annotations.IngressClassKey: annotations.DefaultIngressClass, + "konghq.com/preserve-host": "wiggle wiggle wiggle", }, }, Spec: networking.IngressSpec{ @@ -1470,8 +1489,8 @@ func TestKongRouteAnnotations(t *testing.T) { Name: "bar", Namespace: "default", Annotations: map[string]string{ - "konghq.com/regex-priority": "10", - "kubernetes.io/ingress.class": "kong", + "konghq.com/regex-priority": "10", + annotations.IngressClassKey: annotations.DefaultIngressClass, }, }, Spec: networking.IngressSpec{ @@ -1549,8 +1568,8 @@ func TestKongRouteAnnotations(t *testing.T) { Name: "bar", Namespace: "default", Annotations: map[string]string{ - "konghq.com/regex-priority": "IAmAString", - "kubernetes.io/ingress.class": "kong", + "konghq.com/regex-priority": "IAmAString", + annotations.IngressClassKey: annotations.DefaultIngressClass, }, }, Spec: networking.IngressSpec{ @@ -1631,7 +1650,7 @@ func TestKongProcessClasslessIngress(t *testing.T) { Name: "bar", Namespace: "default", Annotations: map[string]string{ - "kubernetes.io/ingress.class": "kong", + annotations.IngressClassKey: annotations.DefaultIngressClass, }, }, Spec: networking.IngressSpec{ @@ -1739,6 +1758,9 @@ func TestKnativeIngressAndPlugins(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "knative-ingress", Namespace: "foo-ns", + Annotations: map[string]string{ + "networking.knative.dev/ingress.class": annotations.DefaultIngressClass, + }, }, Spec: knative.IngressSpec{ Rules: []knative.IngressRule{ @@ -1775,7 +1797,8 @@ func TestKnativeIngressAndPlugins(t *testing.T) { Name: "foo-svc", Namespace: "foo-ns", Annotations: map[string]string{ - "plugins.konghq.com": "knative-key-auth", + annotations.DeprecatedPluginsKey: "knative-key-auth", + "networking.knative.dev/ingress.class": annotations.DefaultIngressClass, }, }, }, @@ -1867,7 +1890,7 @@ func TestKongServiceAnnotations(t *testing.T) { Name: "bar", Namespace: "default", Annotations: map[string]string{ - "kubernetes.io/ingress.class": "kong", + annotations.IngressClassKey: annotations.DefaultIngressClass, }, }, Spec: networking.IngressSpec{ @@ -1948,7 +1971,7 @@ func TestKongServiceAnnotations(t *testing.T) { Name: "bar", Namespace: "default", Annotations: map[string]string{ - "kubernetes.io/ingress.class": "kong", + annotations.IngressClassKey: annotations.DefaultIngressClass, }, }, Spec: networking.IngressSpec{ @@ -2037,8 +2060,8 @@ func TestKongServiceAnnotations(t *testing.T) { Name: "bar", Namespace: "default", Annotations: map[string]string{ - "konghq.com/methods": "POST,GET", - "kubernetes.io/ingress.class": "kong", + "konghq.com/methods": "POST,GET", + annotations.IngressClassKey: annotations.DefaultIngressClass, }, }, Spec: networking.IngressSpec{ @@ -2120,7 +2143,7 @@ func TestDefaultBackend(t *testing.T) { Name: "ing-with-default-backend", Namespace: "default", Annotations: map[string]string{ - "kubernetes.io/ingress.class": "kong", + annotations.IngressClassKey: annotations.DefaultIngressClass, }, }, Spec: networking.IngressSpec{ @@ -2166,7 +2189,7 @@ func TestDefaultBackend(t *testing.T) { Name: "foo", Namespace: "default", Annotations: map[string]string{ - "kubernetes.io/ingress.class": "kong", + annotations.IngressClassKey: annotations.DefaultIngressClass, }, }, Spec: networking.IngressSpec{ @@ -2235,7 +2258,7 @@ func TestParserSecret(t *testing.T) { Name: "foo", Namespace: "default", Annotations: map[string]string{ - "kubernetes.io/ingress.class": "kong", + annotations.IngressClassKey: annotations.DefaultIngressClass, }, }, Spec: networking.IngressSpec{ @@ -2294,7 +2317,7 @@ func TestParserSecret(t *testing.T) { Name: "foo", Namespace: "default", Annotations: map[string]string{ - "kubernetes.io/ingress.class": "kong", + annotations.IngressClassKey: annotations.DefaultIngressClass, }, }, Spec: networking.IngressSpec{ @@ -2311,7 +2334,7 @@ func TestParserSecret(t *testing.T) { Name: "bar", Namespace: "ns1", Annotations: map[string]string{ - "kubernetes.io/ingress.class": "kong", + annotations.IngressClassKey: annotations.DefaultIngressClass, }, }, Spec: networking.IngressSpec{ @@ -2389,7 +2412,7 @@ func TestParserSecret(t *testing.T) { Name: "foo", Namespace: "default", Annotations: map[string]string{ - "kubernetes.io/ingress.class": "kong", + annotations.IngressClassKey: annotations.DefaultIngressClass, }, }, Spec: networking.IngressSpec{ @@ -2471,8 +2494,8 @@ func TestPluginAnnotations(t *testing.T) { Name: "foo", Namespace: "default", Annotations: map[string]string{ - "plugins.konghq.com": "foo-plugin", - "kubernetes.io/ingress.class": "kong", + annotations.DeprecatedPluginsKey: "foo-plugin", + annotations.IngressClassKey: annotations.DefaultIngressClass, }, }, Spec: networking.IngressSpec{ @@ -2561,8 +2584,8 @@ func TestPluginAnnotations(t *testing.T) { Name: "foo", Namespace: "default", Annotations: map[string]string{ - "plugins.konghq.com": "foo-plugin", - "kubernetes.io/ingress.class": "kong", + annotations.DeprecatedPluginsKey: "foo-plugin", + annotations.IngressClassKey: annotations.DefaultIngressClass, }, }, Spec: networking.IngressSpec{ @@ -2646,8 +2669,8 @@ func TestPluginAnnotations(t *testing.T) { Name: "foo", Namespace: "default", Annotations: map[string]string{ - "plugins.konghq.com": "foo-plugin", - "kubernetes.io/ingress.class": "kong", + annotations.DeprecatedPluginsKey: "foo-plugin", + annotations.IngressClassKey: annotations.DefaultIngressClass, }, }, Spec: networking.IngressSpec{ @@ -2708,8 +2731,8 @@ func TestPluginAnnotations(t *testing.T) { Name: "foo", Namespace: "default", Annotations: map[string]string{ - "plugins.konghq.com": "does-not-exist", - "kubernetes.io/ingress.class": "kong", + annotations.DeprecatedPluginsKey: "does-not-exist", + annotations.IngressClassKey: annotations.DefaultIngressClass, }, }, Spec: networking.IngressSpec{ @@ -2760,7 +2783,7 @@ func TestParseIngressRules(t *testing.T) { Name: "foo", Namespace: "foo-namespace", Annotations: map[string]string{ - "kubernetes.io/ingress.class": "kong", + annotations.IngressClassKey: annotations.DefaultIngressClass, }, }, Spec: networking.IngressSpec{ @@ -4924,7 +4947,7 @@ func Test_getPluginRelations(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Namespace: "ns1", Annotations: map[string]string{ - "plugins.konghq.com": "foo,bar", + annotations.DeprecatedPluginsKey: "foo,bar", }, }, }, @@ -4950,7 +4973,7 @@ func Test_getPluginRelations(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Namespace: "ns1", Annotations: map[string]string{ - "plugins.konghq.com": "foo,bar", + annotations.DeprecatedPluginsKey: "foo,bar", }, }, }, @@ -4982,7 +5005,7 @@ func Test_getPluginRelations(t *testing.T) { Name: "some-ingress", Namespace: "ns2", Annotations: map[string]string{ - "plugins.konghq.com": "foo,bar", + annotations.DeprecatedPluginsKey: "foo,bar", }, }, }, @@ -5016,7 +5039,7 @@ func Test_getPluginRelations(t *testing.T) { Name: "some-ingress", Namespace: "ns2", Annotations: map[string]string{ - "plugins.konghq.com": "foo,bar", + annotations.DeprecatedPluginsKey: "foo,bar", }, }, }, @@ -5030,7 +5053,7 @@ func Test_getPluginRelations(t *testing.T) { Name: "some-ingress", Namespace: "ns2", Annotations: map[string]string{ - "plugins.konghq.com": "bar,baz", + annotations.DeprecatedPluginsKey: "bar,baz", }, }, }, @@ -5059,7 +5082,7 @@ func Test_getPluginRelations(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Namespace: "ns1", Annotations: map[string]string{ - "plugins.konghq.com": "foo,bar", + annotations.DeprecatedPluginsKey: "foo,bar", }, }, }, @@ -5072,7 +5095,7 @@ func Test_getPluginRelations(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Namespace: "ns2", Annotations: map[string]string{ - "plugins.konghq.com": "foo,bar", + annotations.DeprecatedPluginsKey: "foo,bar", }, }, }, @@ -5085,7 +5108,7 @@ func Test_getPluginRelations(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Namespace: "ns1", Annotations: map[string]string{ - "plugins.konghq.com": "foobar", + annotations.DeprecatedPluginsKey: "foobar", }, }, }, @@ -5100,7 +5123,7 @@ func Test_getPluginRelations(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Namespace: "ns1", Annotations: map[string]string{ - "plugins.konghq.com": "foo,bar", + annotations.DeprecatedPluginsKey: "foo,bar", }, }, }, @@ -5114,7 +5137,7 @@ func Test_getPluginRelations(t *testing.T) { Name: "some-ingress", Namespace: "ns2", Annotations: map[string]string{ - "plugins.konghq.com": "foo,bar", + annotations.DeprecatedPluginsKey: "foo,bar", }, }, }, @@ -5128,7 +5151,7 @@ func Test_getPluginRelations(t *testing.T) { Name: "some-ingress", Namespace: "ns2", Annotations: map[string]string{ - "plugins.konghq.com": "bar,baz", + annotations.DeprecatedPluginsKey: "bar,baz", }, }, }, diff --git a/internal/ingress/store/fake_store.go b/internal/ingress/store/fake_store.go index 571a0f99b1..ce0cf8092e 100644 --- a/internal/ingress/store/fake_store.go +++ b/internal/ingress/store/fake_store.go @@ -139,7 +139,8 @@ func NewFakeStore( KnativeIngress: knativeIngressStore, }, - isValidIngressClass: annotations.IngressClassValidatorFuncFromObjectMeta("kong"), + ingressClass: annotations.DefaultIngressClass, + isValidIngressClass: annotations.IngressClassValidatorFuncFromObjectMeta(annotations.DefaultIngressClass), ingressClassMatching: annotations.ExactClassMatch, kongConsumerClassMatching: annotations.ExactClassMatch, } diff --git a/internal/ingress/store/fake_store_test.go b/internal/ingress/store/fake_store_test.go index 9991909090..b223013f24 100644 --- a/internal/ingress/store/fake_store_test.go +++ b/internal/ingress/store/fake_store_test.go @@ -4,6 +4,7 @@ import ( "errors" "testing" + "github.com/kong/kubernetes-ingress-controller/internal/ingress/annotations" configurationv1 "github.com/kong/kubernetes-ingress-controller/pkg/apis/configuration/v1" configurationv1beta1 "github.com/kong/kubernetes-ingress-controller/pkg/apis/configuration/v1beta1" "github.com/stretchr/testify/assert" @@ -95,7 +96,7 @@ func TestFakeStoreIngress(t *testing.T) { Name: "foo", Namespace: "default", Annotations: map[string]string{ - "kubernetes.io/ingress.class": "kong", + annotations.IngressClassKey: annotations.DefaultIngressClass, }, }, Spec: networking.IngressSpec{ @@ -124,7 +125,7 @@ func TestFakeStoreIngress(t *testing.T) { Name: "bar", Namespace: "default", Annotations: map[string]string{ - "kubernetes.io/ingress.class": "not-kong", + annotations.IngressClassKey: "not-kong", }, }, Spec: networking.IngressSpec{ @@ -164,7 +165,7 @@ func TestFakeStoreListTCPIngress(t *testing.T) { Name: "foo", Namespace: "default", Annotations: map[string]string{ - "kubernetes.io/ingress.class": "kong", + annotations.IngressClassKey: annotations.DefaultIngressClass, }, }, Spec: configurationv1beta1.IngressSpec{ @@ -202,7 +203,7 @@ func TestFakeStoreListTCPIngress(t *testing.T) { Name: "bar", Namespace: "default", Annotations: map[string]string{ - "kubernetes.io/ingress.class": "not-kong", + annotations.IngressClassKey: "not-kong", }, }, Spec: configurationv1beta1.IngressSpec{ @@ -234,6 +235,37 @@ func TestFakeStoreListKnativeIngress(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "foo", Namespace: "default", + Annotations: map[string]string{ + "networking.knative.dev/ingress.class": annotations.DefaultIngressClass, + }, + }, + Spec: knative.IngressSpec{ + Rules: []knative.IngressRule{ + { + Hosts: []string{"example.com"}, + HTTP: &knative.HTTPIngressRuleValue{ + Paths: []knative.HTTPIngressPath{ + { + Path: "/", + Splits: []knative.IngressBackendSplit{ + { + IngressBackend: knative.IngressBackend{ + ServiceName: "foo-svc", + ServicePort: intstr.FromInt(80), + }, + }, + }, + }, + }, + }, + }, + }, + }, + }, + { + ObjectMeta: metav1.ObjectMeta{ + Name: "i-dont-get-processed-because-i-have-no-class-annotation", + Namespace: "default", }, Spec: knative.IngressSpec{ Rules: []knative.IngressRule{ @@ -324,7 +356,7 @@ func TestFakeStoreConsumer(t *testing.T) { Name: "foo", Namespace: "default", Annotations: map[string]string{ - "kubernetes.io/ingress.class": "kong", + annotations.IngressClassKey: annotations.DefaultIngressClass, }, }, }, @@ -402,7 +434,7 @@ func TestFakeStoreClusterPlugins(t *testing.T) { "global": "true", }, Annotations: map[string]string{ - "kubernetes.io/ingress.class": "kong", + annotations.IngressClassKey: annotations.DefaultIngressClass, }, }, }, @@ -535,6 +567,9 @@ func TestFakeStore_ListCACerts(t *testing.T) { Labels: map[string]string{ "konghq.com/ca-cert": "true", }, + Annotations: map[string]string{ + annotations.IngressClassKey: annotations.DefaultIngressClass, + }, }, }, { @@ -544,6 +579,9 @@ func TestFakeStore_ListCACerts(t *testing.T) { Labels: map[string]string{ "konghq.com/ca-cert": "true", }, + Annotations: map[string]string{ + annotations.IngressClassKey: annotations.DefaultIngressClass, + }, }, }, } diff --git a/internal/ingress/store/store.go b/internal/ingress/store/store.go index 1cac583fd6..1172d86846 100644 --- a/internal/ingress/store/store.go +++ b/internal/ingress/store/store.go @@ -194,10 +194,6 @@ func (s Store) ListTCPIngresses() ([]*configurationv1beta1.TCPIngress, error) { func (s Store) validKnativeIngressClass(objectMeta *metav1.ObjectMeta) bool { ingressAnnotationValue := objectMeta.GetAnnotations()[knativeIngressClassKey] - if ingressAnnotationValue == "" && - s.ingressClass == annotations.DefaultIngressClass { - return true - } return ingressAnnotationValue == s.ingressClass } @@ -211,6 +207,9 @@ func (s Store) ListKnativeIngresses() ([]*knative.Ingress, error) { err := cache.ListAll(s.stores.KnativeIngress, labels.NewSelector(), func(ob interface{}) { ing, ok := ob.(*knative.Ingress) + // this is implemented directly in store as s.isValidIngressClass only checks the value of the + // kubernetes.io/ingress.class annotation (annotations.ingressClassKey), not + // networking.knative.dev/ingress.class (knativeIngressClassKey) if ok && s.validKnativeIngressClass(&ing.ObjectMeta) { ingresses = append(ingresses, ing) } @@ -331,7 +330,7 @@ func (s Store) ListGlobalKongPlugins() ([]*configurationv1.KongPlugin, error) { labels.NewSelector().Add(*req), func(ob interface{}) { p, ok := ob.(*configurationv1.KongPlugin) - if ok && s.isValidIngressClass(&p.ObjectMeta, s.ingressClassMatching) { + if ok && s.isValidIngressClass(&p.ObjectMeta, annotations.ExactOrEmptyClassMatch) { plugins = append(plugins, p) } }) @@ -378,7 +377,7 @@ func (s Store) ListCACerts() ([]*apiv1.Secret, error) { labels.NewSelector().Add(*req), func(ob interface{}) { p, ok := ob.(*apiv1.Secret) - if ok { + if ok && s.isValidIngressClass(&p.ObjectMeta, annotations.ExactClassMatch) { secrets = append(secrets, p) } })