Fix ingress.class annotation
This commit is contained in:
parent
9e189b4eb9
commit
f7e910e960
4 changed files with 7 additions and 8 deletions
|
@ -35,7 +35,7 @@ var (
|
||||||
// IngressClass sets the runtime ingress class to use
|
// IngressClass sets the runtime ingress class to use
|
||||||
// An empty string means accept all ingresses without
|
// An empty string means accept all ingresses without
|
||||||
// annotation and the ones configured with class nginx
|
// annotation and the ones configured with class nginx
|
||||||
IngressClass = ""
|
IngressClass = "nginx"
|
||||||
)
|
)
|
||||||
|
|
||||||
// IsValid returns true if the given Ingress either doesn't specify
|
// IsValid returns true if the given Ingress either doesn't specify
|
||||||
|
|
|
@ -44,7 +44,6 @@ func TestIsValidClass(t *testing.T) {
|
||||||
{"nginx", "nginx", "nginx", true},
|
{"nginx", "nginx", "nginx", true},
|
||||||
{"custom", "custom", "nginx", true},
|
{"custom", "custom", "nginx", true},
|
||||||
{"", "killer", "nginx", false},
|
{"", "killer", "nginx", false},
|
||||||
{"", "", "nginx", true},
|
|
||||||
{"custom", "nginx", "nginx", false},
|
{"custom", "nginx", "nginx", false},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,6 @@ import (
|
||||||
|
|
||||||
"k8s.io/ingress-nginx/internal/ingress"
|
"k8s.io/ingress-nginx/internal/ingress"
|
||||||
"k8s.io/ingress-nginx/internal/ingress/annotations/class"
|
"k8s.io/ingress-nginx/internal/ingress/annotations/class"
|
||||||
"k8s.io/ingress-nginx/internal/ingress/annotations/parser"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type cacheController struct {
|
type cacheController struct {
|
||||||
|
@ -66,7 +65,7 @@ func (n *NGINXController) createListers(stopCh chan struct{}) (*ingress.StoreLis
|
||||||
AddFunc: func(obj interface{}) {
|
AddFunc: func(obj interface{}) {
|
||||||
addIng := obj.(*extensions.Ingress)
|
addIng := obj.(*extensions.Ingress)
|
||||||
if !class.IsValid(addIng) {
|
if !class.IsValid(addIng) {
|
||||||
a, _ := parser.GetStringAnnotation(class.IngressKey, addIng)
|
a := addIng.GetAnnotations()[class.IngressKey]
|
||||||
glog.Infof("ignoring add for ingress %v based on annotation %v with value %v", addIng.Name, class.IngressKey, a)
|
glog.Infof("ignoring add for ingress %v based on annotation %v with value %v", addIng.Name, class.IngressKey, a)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -103,11 +102,13 @@ func (n *NGINXController) createListers(stopCh chan struct{}) (*ingress.StoreLis
|
||||||
curIng := cur.(*extensions.Ingress)
|
curIng := cur.(*extensions.Ingress)
|
||||||
validOld := class.IsValid(oldIng)
|
validOld := class.IsValid(oldIng)
|
||||||
validCur := class.IsValid(curIng)
|
validCur := class.IsValid(curIng)
|
||||||
|
|
||||||
|
c := curIng.GetAnnotations()[class.IngressKey]
|
||||||
if !validOld && validCur {
|
if !validOld && validCur {
|
||||||
glog.Infof("creating ingress %v based on annotation %v", curIng.Name, class.IngressKey)
|
glog.Infof("creating ingress %v/%v based on annotation %v with value '%v'", curIng.Namespace, curIng.Name, class.IngressKey, c)
|
||||||
n.recorder.Eventf(curIng, apiv1.EventTypeNormal, "CREATE", fmt.Sprintf("Ingress %s/%s", curIng.Namespace, curIng.Name))
|
n.recorder.Eventf(curIng, apiv1.EventTypeNormal, "CREATE", fmt.Sprintf("Ingress %s/%s", curIng.Namespace, curIng.Name))
|
||||||
} else if validOld && !validCur {
|
} else if validOld && !validCur {
|
||||||
glog.Infof("removing ingress %v based on annotation %v", curIng.Name, class.IngressKey)
|
glog.Infof("removing ingress %v/%v based on annotation %v with value '%v'", curIng.Namespace, curIng.Name, class.IngressKey, c)
|
||||||
n.recorder.Eventf(curIng, apiv1.EventTypeNormal, "DELETE", fmt.Sprintf("Ingress %s/%s", curIng.Namespace, curIng.Name))
|
n.recorder.Eventf(curIng, apiv1.EventTypeNormal, "DELETE", fmt.Sprintf("Ingress %s/%s", curIng.Namespace, curIng.Name))
|
||||||
} else if validCur && !reflect.DeepEqual(old, cur) {
|
} else if validCur && !reflect.DeepEqual(old, cur) {
|
||||||
n.recorder.Eventf(curIng, apiv1.EventTypeNormal, "UPDATE", fmt.Sprintf("Ingress %s/%s", curIng.Namespace, curIng.Name))
|
n.recorder.Eventf(curIng, apiv1.EventTypeNormal, "UPDATE", fmt.Sprintf("Ingress %s/%s", curIng.Namespace, curIng.Name))
|
||||||
|
|
|
@ -47,7 +47,6 @@ import (
|
||||||
"k8s.io/ingress-nginx/internal/ingress"
|
"k8s.io/ingress-nginx/internal/ingress"
|
||||||
"k8s.io/ingress-nginx/internal/ingress/annotations"
|
"k8s.io/ingress-nginx/internal/ingress/annotations"
|
||||||
"k8s.io/ingress-nginx/internal/ingress/annotations/class"
|
"k8s.io/ingress-nginx/internal/ingress/annotations/class"
|
||||||
"k8s.io/ingress-nginx/internal/ingress/annotations/parser"
|
|
||||||
ngx_config "k8s.io/ingress-nginx/internal/ingress/controller/config"
|
ngx_config "k8s.io/ingress-nginx/internal/ingress/controller/config"
|
||||||
"k8s.io/ingress-nginx/internal/ingress/controller/process"
|
"k8s.io/ingress-nginx/internal/ingress/controller/process"
|
||||||
ngx_template "k8s.io/ingress-nginx/internal/ingress/controller/template"
|
ngx_template "k8s.io/ingress-nginx/internal/ingress/controller/template"
|
||||||
|
@ -258,7 +257,7 @@ func (n *NGINXController) Start() {
|
||||||
ing := obj.(*extensions.Ingress)
|
ing := obj.(*extensions.Ingress)
|
||||||
|
|
||||||
if !class.IsValid(ing) {
|
if !class.IsValid(ing) {
|
||||||
a, _ := parser.GetStringAnnotation(class.IngressKey, ing)
|
a := ing.GetAnnotations()[class.IngressKey]
|
||||||
glog.Infof("ignoring add for ingress %v based on annotation %v with value %v", ing.Name, class.IngressKey, a)
|
glog.Infof("ignoring add for ingress %v based on annotation %v with value %v", ing.Name, class.IngressKey, a)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue