Merge pull request #1336 from aledbf/skip-ingress-rules

[nginx-ingress-controller]: Add annotation to skip ingress rule
This commit is contained in:
Prashanth B 2016-07-20 10:33:17 -07:00 committed by GitHub
commit fe59e29f5e
3 changed files with 46 additions and 2 deletions

View file

@ -17,6 +17,7 @@ This is a nginx Ingress controller that uses [ConfigMap](https://github.com/kube
* [Proxy Protocol](#proxy-protocol)
* [NGINX customization](configuration.md)
* [NGINX status page](#nginx-status-page)
* [Disabling NGINX ingress controller](#disabling-nginx-ingress-controller)
* [Debug & Troubleshooting](#troubleshooting)
* [Limitations](#limitations)
* [NGINX Notes](#nginx-notes)
@ -233,6 +234,10 @@ Please check the example `example/rc-default.yaml`
To extract the information in JSON format the module provides a custom URL: `/nginx_status/format/json`
### Disabling NGINX ingress controller
Setting the annotation `kubernetes.io/ingress.class` to any value other than "nginx" or the empty string, will force the NGINX Ingress controller to ignore your Ingress. Do this if you wish to use one of the other Ingress controllers at the same time as the NGINX controller.
### Debug & Troubleshooting

View file

@ -150,16 +150,28 @@ func newLoadBalancerController(kubeClient *client.Client, resyncPeriod time.Dura
ingEventHandler := framework.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
addIng := obj.(*extensions.Ingress)
if !isNGINXIngress(addIng) {
glog.Infof("Ignoring add for ingress %v based on annotation %v", addIng.Name, ingressClassKey)
return
}
lbc.recorder.Eventf(addIng, api.EventTypeNormal, "CREATE", fmt.Sprintf("%s/%s", addIng.Namespace, addIng.Name))
lbc.ingQueue.enqueue(obj)
lbc.syncQueue.enqueue(obj)
},
DeleteFunc: func(obj interface{}) {
upIng := obj.(*extensions.Ingress)
lbc.recorder.Eventf(upIng, api.EventTypeNormal, "DELETE", fmt.Sprintf("%s/%s", upIng.Namespace, upIng.Name))
delIng := obj.(*extensions.Ingress)
if !isNGINXIngress(delIng) {
glog.Infof("Ignoring add for ingress %v based on annotation %v", delIng.Name, ingressClassKey)
return
}
lbc.recorder.Eventf(delIng, api.EventTypeNormal, "DELETE", fmt.Sprintf("%s/%s", delIng.Namespace, delIng.Name))
lbc.syncQueue.enqueue(obj)
},
UpdateFunc: func(old, cur interface{}) {
curIng := cur.(*extensions.Ingress)
if !isNGINXIngress(curIng) {
return
}
if !reflect.DeepEqual(old, cur) {
upIng := cur.(*extensions.Ingress)
lbc.recorder.Eventf(upIng, api.EventTypeNormal, "UPDATE", fmt.Sprintf("%s/%s", upIng.Namespace, upIng.Name))

View file

@ -26,6 +26,7 @@ import (
"k8s.io/kubernetes/pkg/api"
apierrs "k8s.io/kubernetes/pkg/api/errors"
"k8s.io/kubernetes/pkg/apis/extensions"
"k8s.io/kubernetes/pkg/client/cache"
"k8s.io/kubernetes/pkg/client/unversioned"
"k8s.io/kubernetes/pkg/util/wait"
@ -246,3 +247,29 @@ func waitForPodCondition(kubeClient *unversioned.Client, ns, podName string, con
return false, nil
})
}
// ingAnnotations represents Ingress annotations.
type ingAnnotations map[string]string
const (
// ingressClassKey picks a specific "class" for the Ingress. The controller
// only processes Ingresses with this annotation either unset, or set
// to either nginxIngressClass or the empty string.
ingressClassKey = "kubernetes.io/ingress.class"
nginxIngressClass = "nginx"
)
func (ing ingAnnotations) ingressClass() string {
val, ok := ing[ingressClassKey]
if !ok {
return ""
}
return val
}
// isNGINXIngress returns true if the given Ingress either doesn't specify the
// ingress.class annotation, or it's set to "nginx".
func isNGINXIngress(ing *extensions.Ingress) bool {
class := ingAnnotations(ing.ObjectMeta.Annotations).ingressClass()
return class == "" || class == nginxIngressClass
}