Skip to content

Commit

Permalink
feat: add Ingress class validation (#154)
Browse files Browse the repository at this point in the history
Signed-off-by: Matthis Holleville <matthish29@gmail.com>
  • Loading branch information
matthisholleville committed Mar 30, 2023
1 parent be061da commit b061566
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/analyzer/ingressAnalyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ func AnalyzeIngress(ctx context.Context, config *AnalysisConfiguration, client *

for _, ing := range list.Items {
var failures []string

// get ingressClassName
ingressClassName := ing.Spec.IngressClassName
if ingressClassName == nil {
ingClassValue := ing.Annotations["kubernetes.io/ingress.class"]
if ingClassValue == "" {
failures = append(failures, fmt.Sprintf("Ingress %s/%s does not specify an Ingress class.", ing.Namespace, ing.Name))
} else {
ingressClassName = &ingClassValue
}
}

// check if ingressclass exist
if ingressClassName != nil {
_, err := client.GetClient().NetworkingV1().IngressClasses().Get(ctx, *ingressClassName, metav1.GetOptions{})
if err != nil {
failures = append(failures, fmt.Sprintf("Ingress uses the ingress class %s which does not exist.", *ingressClassName))
}
}

// loop over rules
for _, rule := range ing.Spec.Rules {
// loop over paths
Expand Down

0 comments on commit b061566

Please sign in to comment.