Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid ingress state build failure when ingresses reference non-existe… #33

Merged
merged 2 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Inbaraj-S marked this conversation as resolved.
Show resolved Hide resolved
#
# 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
Loading