Skip to content

Commit

Permalink
Add support for IngressClass and ingress.class annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
aledbf committed Apr 20, 2020
1 parent 837d370 commit 2890351
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions internal/ingress/annotations/class/main.go
Expand Up @@ -18,6 +18,7 @@ package class

import (
networking "k8s.io/api/networking/v1beta1"
"k8s.io/ingress-nginx/internal/k8s"
)

const (
Expand All @@ -41,25 +42,25 @@ var (
// the ingress.class annotation, or it's set to the configured in the
// ingress controller.
func IsValid(ing *networking.Ingress) bool {
className := ing.Spec.IngressClassName
ingress, ok := ing.GetAnnotations()[IngressKey]
if ok {
// we have 2 valid combinations
// 1 - ingress with default class | blank annotation on ingress
// 2 - ingress with specific class | same annotation on ingress
//
// and 2 invalid combinations
// 3 - ingress with default class | fixed annotation on ingress
// 4 - ingress with specific class | different annotation on ingress
if ingress == "" && IngressClass == DefaultClass {
return true
}

// we have 2 valid combinations
// 1 - ingress with default class | blank annotation on ingress
// 2 - ingress with specific class | same annotation on ingress
//
// and 2 invalid combinations
// 3 - ingress with default class | fixed annotation on ingress
// 4 - ingress with specific class | different annotation on ingress
if className != nil {
return *className == IngressClass
return ingress == IngressClass
}

if IngressClass == DefaultClass {
return true
}

if IngressClass == "" {
return true
// Not running k8s v1.18 or higher and not annotation
if !k8s.IsIngressV1Ready {
return IngressClass == DefaultClass
}

return false
Expand Down

0 comments on commit 2890351

Please sign in to comment.