diff --git a/pkg/state/ingressstate.go b/pkg/state/ingressstate.go index e049dbef..ea67f69b 100644 --- a/pkg/state/ingressstate.go +++ b/pkg/state/ingressstate.go @@ -90,11 +90,9 @@ func (s *StateStore) BuildState(ingressClass *networkingv1.IngressClass) error { var ingressGroup []*networkingv1.Ingress for _, ing := range ingressList { - ingIc, err := util.GetIngressClass(ing, s.IngressClassLister) - if err != nil { - return errors.Wrap(err, "error getting ingress class") - } - if ingIc != nil && ingressClass.Name == ingIc.Name && !util.IsIngressDeleting(ing) { + if ((ing.Spec.IngressClassName == nil && ingressClass.Annotations[util.IngressClassIsDefault] == "true") || + (ing.Spec.IngressClassName != nil && ingressClass.Name == *ing.Spec.IngressClassName)) && + !util.IsIngressDeleting(ing) { ingressGroup = append(ingressGroup, ing) } } diff --git a/pkg/state/ingressstate_test.go b/pkg/state/ingressstate_test.go index 88d0a87b..92efa31a 100644 --- a/pkg/state/ingressstate_test.go +++ b/pkg/state/ingressstate_test.go @@ -34,6 +34,7 @@ const ( ListenerProtocolConfigValidationsFilePath = "validate-listener-protocol-config.yaml" TestIngressStateFilePath = "test-ingress-state.yaml" TestIngressStateWithPortNameFilePath = "test-ingress-state_withportname.yaml" + TestIngressStateWithNamedClassesFilePath = "test-ingress-state_withnamedclasses.yaml" ) func setUp(ctx context.Context, ingressClassList *networkingv1.IngressClassList, ingressList *networkingv1.IngressList, testService *v1.ServiceList) (networkinglisters.IngressClassLister, networkinglisters.IngressLister, corelisters.ServiceLister) { @@ -226,6 +227,25 @@ func TestIngressStateWithPortName(t *testing.T) { assertCases(stateStore) } +func TestIngressStateWithNamedClasses(t *testing.T) { + RegisterTestingT(t) + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + ingressClassList := testutil.GetIngressClassList() + + ingressList := testutil.ReadResourceAsIngressList(TestIngressStateWithNamedClassesFilePath) + + testService := testutil.GetServiceListResourceWithPortName("default", "tls-test", 80, "tls-port") + ingressClassLister, ingressLister, serviceLister := setUp(ctx, ingressClassList, ingressList, testService) + + stateStore := NewStateStore(ingressClassLister, ingressLister, serviceLister, nil) + err := stateStore.BuildState(&ingressClassList.Items[0]) + Expect(err).NotTo(HaveOccurred()) + + assertCases(stateStore) +} + func assertCases(stateStore *StateStore) { ingressName := "ingress-state" allBs := stateStore.GetAllBackendSetForIngressClass() diff --git a/pkg/state/test-ingress-state_withnamedclasses.yaml b/pkg/state/test-ingress-state_withnamedclasses.yaml new file mode 100644 index 00000000..f45ea3d4 --- /dev/null +++ b/pkg/state/test-ingress-state_withnamedclasses.yaml @@ -0,0 +1,123 @@ +# +# OCI Native Ingress Controller +# +# Copyright (c) 2023 Oracle America, Inc. and its affiliates. +# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/ +# +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-state + namespace: default +spec: + ingressClassName: default-ingress-class + tls: + - hosts: + - foo.bar.com + secretName: secret_name + rules: + - host: "foo.bar.com" + http: + paths: + - pathType: Prefix + path: "/PrefixEcho1" + backend: + service: + name: tls-test + port: + number: 80 + - host: "foo.bar.com" + http: + paths: + - pathType: Prefix + path: "/ExactEcho1" + backend: + service: + name: tls-test + port: + number: 70 +--- + +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-state-excluded + namespace: default +spec: + ingressClassName: missing-ingress-class + tls: + - hosts: + - foo.bar.com + secretName: secret_name + rules: + - host: "foo.bar.com" + http: + paths: + - pathType: Prefix + path: "/PrefixEcho1/aa" + backend: + service: + name: tls-test + port: + number: 80 + - host: "foo.bar.com" + http: + paths: + - pathType: Prefix + path: "/ExactEcho1" + backend: + service: + name: tls-test + port: + number: 90 + - http: + paths: + - pathType: Prefix + path: "/PrefixEcho1" + backend: + service: + name: tls-test + port: + number: 100 +--- +apiVersion: networking.k8s.io/v1 +kind: Ingress +metadata: + name: ingress-state-new + namespace: default +spec: + ingressClassName: default-ingress-class + tls: + - hosts: + - foo.bar.com + secretName: secret_name + rules: + - host: "foo.bar.com" + http: + paths: + - pathType: Prefix + path: "/PrefixEcho1/aa" + backend: + service: + name: tls-test + port: + number: 80 + - host: "foo.bar.com" + http: + paths: + - pathType: Prefix + path: "/ExactEcho1" + backend: + service: + name: tls-test + port: + number: 90 + - http: + paths: + - pathType: Prefix + path: "/PrefixEcho1" + backend: + service: + name: tls-test + port: + number: 100