Skip to content

Commit

Permalink
bugfix: ingress state build error
Browse files Browse the repository at this point in the history
  • Loading branch information
Inbaraj-S committed Feb 1, 2024
1 parent d9394c2 commit 398a3a2
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 10 deletions.
9 changes: 5 additions & 4 deletions pkg/state/ingressstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,11 @@ func (s *StateStore) BuildState(ingressClass *networkingv1.IngressClass) error {
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) {
ingressGroup = append(ingressGroup, ing)
klog.Errorf("IngressClass not found for ingress: %s. Skipping ingress.", ing.Name)
} else {
if ingIc != nil && ingressClass.Name == ingIc.Name && !util.IsIngressDeleting(ing) {
ingressGroup = append(ingressGroup, ing)
}
}
}

Expand Down
32 changes: 26 additions & 6 deletions pkg/state/ingressstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@ import (
)

const (
TlsConfigValidationsFilePath = "validate-tls-config.yaml"
HealthCheckerConfigValidationsFilePath = "validate-hc-config.yaml"
BackendSetPolicyConfigValidationsFilePath = "validate-bs-policy-config.yaml"
ListenerProtocolConfigValidationsFilePath = "validate-listener-protocol-config.yaml"
TestIngressStateFilePath = "test-ingress-state.yaml"
TestIngressStateWithPortNameFilePath = "test-ingress-state_withportname.yaml"
TlsConfigValidationsFilePath = "validate-tls-config.yaml"
HealthCheckerConfigValidationsFilePath = "validate-hc-config.yaml"
BackendSetPolicyConfigValidationsFilePath = "validate-bs-policy-config.yaml"
ListenerProtocolConfigValidationsFilePath = "validate-listener-protocol-config.yaml"
TestIngressStateFilePath = "test-ingress-state.yaml"
TestIngressStateFilePathMissingIngressClass = "test-ingress-state-missing-class.yaml"
TestIngressStateWithPortNameFilePath = "test-ingress-state_withportname.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 @@ -398,3 +399,22 @@ func TestValidateProtocolConfigWithConflict(t *testing.T) {

Expect(err.Error()).Should(ContainSubstring(fmt.Sprintf(ProtocolConflictMessage, 900)))
}

func TestIngressStateWithMissingIngressClass(t *testing.T) {
RegisterTestingT(t)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

ingressClassList := testutil.GetIngressClassList()

ingressList := testutil.ReadResourceAsIngressList(TestIngressStateFilePathMissingIngressClass)

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)
}
122 changes: 122 additions & 0 deletions pkg/state/test-ingress-state-missing-class.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#
# 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-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
---
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

0 comments on commit 398a3a2

Please sign in to comment.