From 28903516fd3ed0ea51cd73316687a7af7833a3b6 Mon Sep 17 00:00:00 2001 From: Manuel Alejandro de Brito Fontes Date: Mon, 20 Apr 2020 17:38:50 -0400 Subject: [PATCH] Add support for IngressClass and ingress.class annotation --- internal/ingress/annotations/class/main.go | 33 +++++++++++----------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/internal/ingress/annotations/class/main.go b/internal/ingress/annotations/class/main.go index a20507d135cf..2cae3ee88a15 100644 --- a/internal/ingress/annotations/class/main.go +++ b/internal/ingress/annotations/class/main.go @@ -18,6 +18,7 @@ package class import ( networking "k8s.io/api/networking/v1beta1" + "k8s.io/ingress-nginx/internal/k8s" ) const ( @@ -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