Skip to content

Commit

Permalink
bugfix: ingress state build failure when ingress class non-existent (#33
Browse files Browse the repository at this point in the history
)

* Avoid ingress state build failure when ingresses reference non-existent ingress classes

Signed-off-by: Michael Tweten <Michael.Tweten@oracle.com>

* Test case file update

- Update test-ingress-state_withnamedclasses.yaml

---------

Signed-off-by: Michael Tweten <Michael.Tweten@oracle.com>
Co-authored-by: Inbaraj S <contactsinbaraj@gmail.com>
  • Loading branch information
mtweten and Inbaraj-S authored Feb 6, 2024
1 parent d9394c2 commit 913ccdd
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 5 deletions.
8 changes: 3 additions & 5 deletions pkg/state/ingressstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down
20 changes: 20 additions & 0 deletions pkg/state/ingressstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
Expand Down
123 changes: 123 additions & 0 deletions pkg/state/test-ingress-state_withnamedclasses.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 913ccdd

Please sign in to comment.