Skip to content

Commit

Permalink
Merge pull request kubernetes-retired#1336 from aledbf/skip-ingress-r…
Browse files Browse the repository at this point in the history
…ules

[nginx-ingress-controller]: Add annotation to skip ingress rule
  • Loading branch information
bprashanth authored Jul 20, 2016
2 parents ce7085d + 89bbb8d commit fe59e29
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
5 changes: 5 additions & 0 deletions controllers/nginx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down
16 changes: 14 additions & 2 deletions controllers/nginx/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
27 changes: 27 additions & 0 deletions controllers/nginx/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

0 comments on commit fe59e29

Please sign in to comment.