Skip to content

Commit 913ccdd

Browse files
mtwetenInbaraj-S
andauthored
bugfix: ingress state build failure when ingress class non-existent (#33)
* Avoid ingress state build failure when ingresses reference non-existent ingress classes Signed-off-by: Michael Tweten <[email protected]> * Test case file update - Update test-ingress-state_withnamedclasses.yaml --------- Signed-off-by: Michael Tweten <[email protected]> Co-authored-by: Inbaraj S <[email protected]>
1 parent d9394c2 commit 913ccdd

File tree

3 files changed

+146
-5
lines changed

3 files changed

+146
-5
lines changed

pkg/state/ingressstate.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,9 @@ func (s *StateStore) BuildState(ingressClass *networkingv1.IngressClass) error {
9090

9191
var ingressGroup []*networkingv1.Ingress
9292
for _, ing := range ingressList {
93-
ingIc, err := util.GetIngressClass(ing, s.IngressClassLister)
94-
if err != nil {
95-
return errors.Wrap(err, "error getting ingress class")
96-
}
97-
if ingIc != nil && ingressClass.Name == ingIc.Name && !util.IsIngressDeleting(ing) {
93+
if ((ing.Spec.IngressClassName == nil && ingressClass.Annotations[util.IngressClassIsDefault] == "true") ||
94+
(ing.Spec.IngressClassName != nil && ingressClass.Name == *ing.Spec.IngressClassName)) &&
95+
!util.IsIngressDeleting(ing) {
9896
ingressGroup = append(ingressGroup, ing)
9997
}
10098
}

pkg/state/ingressstate_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const (
3434
ListenerProtocolConfigValidationsFilePath = "validate-listener-protocol-config.yaml"
3535
TestIngressStateFilePath = "test-ingress-state.yaml"
3636
TestIngressStateWithPortNameFilePath = "test-ingress-state_withportname.yaml"
37+
TestIngressStateWithNamedClassesFilePath = "test-ingress-state_withnamedclasses.yaml"
3738
)
3839

3940
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) {
226227
assertCases(stateStore)
227228
}
228229

230+
func TestIngressStateWithNamedClasses(t *testing.T) {
231+
RegisterTestingT(t)
232+
ctx, cancel := context.WithCancel(context.Background())
233+
defer cancel()
234+
235+
ingressClassList := testutil.GetIngressClassList()
236+
237+
ingressList := testutil.ReadResourceAsIngressList(TestIngressStateWithNamedClassesFilePath)
238+
239+
testService := testutil.GetServiceListResourceWithPortName("default", "tls-test", 80, "tls-port")
240+
ingressClassLister, ingressLister, serviceLister := setUp(ctx, ingressClassList, ingressList, testService)
241+
242+
stateStore := NewStateStore(ingressClassLister, ingressLister, serviceLister, nil)
243+
err := stateStore.BuildState(&ingressClassList.Items[0])
244+
Expect(err).NotTo(HaveOccurred())
245+
246+
assertCases(stateStore)
247+
}
248+
229249
func assertCases(stateStore *StateStore) {
230250
ingressName := "ingress-state"
231251
allBs := stateStore.GetAllBackendSetForIngressClass()
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
#
2+
# OCI Native Ingress Controller
3+
#
4+
# Copyright (c) 2023 Oracle America, Inc. and its affiliates.
5+
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
6+
#
7+
apiVersion: networking.k8s.io/v1
8+
kind: Ingress
9+
metadata:
10+
name: ingress-state
11+
namespace: default
12+
spec:
13+
ingressClassName: default-ingress-class
14+
tls:
15+
- hosts:
16+
- foo.bar.com
17+
secretName: secret_name
18+
rules:
19+
- host: "foo.bar.com"
20+
http:
21+
paths:
22+
- pathType: Prefix
23+
path: "/PrefixEcho1"
24+
backend:
25+
service:
26+
name: tls-test
27+
port:
28+
number: 80
29+
- host: "foo.bar.com"
30+
http:
31+
paths:
32+
- pathType: Prefix
33+
path: "/ExactEcho1"
34+
backend:
35+
service:
36+
name: tls-test
37+
port:
38+
number: 70
39+
---
40+
41+
apiVersion: networking.k8s.io/v1
42+
kind: Ingress
43+
metadata:
44+
name: ingress-state-excluded
45+
namespace: default
46+
spec:
47+
ingressClassName: missing-ingress-class
48+
tls:
49+
- hosts:
50+
- foo.bar.com
51+
secretName: secret_name
52+
rules:
53+
- host: "foo.bar.com"
54+
http:
55+
paths:
56+
- pathType: Prefix
57+
path: "/PrefixEcho1/aa"
58+
backend:
59+
service:
60+
name: tls-test
61+
port:
62+
number: 80
63+
- host: "foo.bar.com"
64+
http:
65+
paths:
66+
- pathType: Prefix
67+
path: "/ExactEcho1"
68+
backend:
69+
service:
70+
name: tls-test
71+
port:
72+
number: 90
73+
- http:
74+
paths:
75+
- pathType: Prefix
76+
path: "/PrefixEcho1"
77+
backend:
78+
service:
79+
name: tls-test
80+
port:
81+
number: 100
82+
---
83+
apiVersion: networking.k8s.io/v1
84+
kind: Ingress
85+
metadata:
86+
name: ingress-state-new
87+
namespace: default
88+
spec:
89+
ingressClassName: default-ingress-class
90+
tls:
91+
- hosts:
92+
- foo.bar.com
93+
secretName: secret_name
94+
rules:
95+
- host: "foo.bar.com"
96+
http:
97+
paths:
98+
- pathType: Prefix
99+
path: "/PrefixEcho1/aa"
100+
backend:
101+
service:
102+
name: tls-test
103+
port:
104+
number: 80
105+
- host: "foo.bar.com"
106+
http:
107+
paths:
108+
- pathType: Prefix
109+
path: "/ExactEcho1"
110+
backend:
111+
service:
112+
name: tls-test
113+
port:
114+
number: 90
115+
- http:
116+
paths:
117+
- pathType: Prefix
118+
path: "/PrefixEcho1"
119+
backend:
120+
service:
121+
name: tls-test
122+
port:
123+
number: 100

0 commit comments

Comments
 (0)