oracle / oci-native-ingress-controller

OCI Native Ingress Controller
https://blogs.oracle.com/cloud-infrastructure/post/oracle-cloud-native-ingress-controller-kubernetes
Universal Permissive License v1.0
17 stars 19 forks source link

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

Closed mtweten closed 4 months ago

mtweten commented 7 months ago

…nt ingress classes

Problem

If any Ingress exists that references a non-existent IngressClass, oci-native-ingress-controller will no longer be able to build the ingress state for any IngressClass, rendering it non-functional

Cause

When building the ingress state for a given IngressClass, this code lists and iterates through all Ingress objects, and tries to determine if the Ingress is tied to the IngressClass being processed (i.e. via ingressClassName, or, if the Ingress has no ingressClassName defined, if the IngressClass is the default ingress class).

In doing this, for each Ingress object, it's calling util.GetIngressClass, which internally lists all IngressClasses and returns the IngressClass that is tied to the Ingress. However, if the Ingress in question references an IngressClass by name that doesn't exist, util.GetIngressClass will return an error (ingress class not found for ingress). The state building code will then exit early and return that error up the stack, meaning no Ingress state will be built and no load balancer will be updated. As long as ANY Ingress object exists that references an IngressClass that doesn't exist, no state can ever be built.

Solution

Since the ingress state building code is already operating on a specific IngressClass, we don't need to use the util.GetIngressClass code which lists all IngressClasses for every Ingress being processed. Instead, we can just compare the ingressClassName of each ingress against the name of the IngressClass being processed. If it matches, we include it in the group. If the ingressClassName is nil, we only include it if the IngressClass being processed is the default ingress class

coveralls commented 4 months ago

Pull Request Test Coverage Report for Build 7795412898

Warning: This coverage report may be inaccurate.

We've detected an issue with your CI configuration that might affect the accuracy of this pull request's coverage report. To ensure accuracy in future PRs, please see these guidelines. A quick fix for this PR: rebase it; your next report should be accurate.


Totals Coverage Status
Change from base Build 6861469711: 0.04%
Covered Lines: 2234
Relevant Lines: 3421

💛 - Coveralls