Add support for IngressClass and ingress.class annotation

This commit is contained in:
Manuel Alejandro de Brito Fontes 2020-04-20 17:38:50 -04:00
parent d4e0657991
commit efbb3f9fc8
17 changed files with 350 additions and 53 deletions

View file

@ -190,8 +190,7 @@ func TestCheckIngress(t *testing.T) {
}
t.Run("When the ingress class differs from nginx", func(t *testing.T) {
class := "different"
ing.Spec.IngressClassName = &class
ing.ObjectMeta.Annotations["kubernetes.io/ingress.class"] = "different"
nginx.command = testNginxTestCommand{
t: t,
err: fmt.Errorf("test error"),
@ -202,8 +201,7 @@ func TestCheckIngress(t *testing.T) {
})
t.Run("when the class is the nginx one", func(t *testing.T) {
class := "nginx"
ing.Spec.IngressClassName = &class
ing.ObjectMeta.Annotations["kubernetes.io/ingress.class"] = "nginx"
nginx.command = testNginxTestCommand{
t: t,
err: nil,

View file

@ -949,30 +949,18 @@ func toIngress(obj interface{}) (*networkingv1beta1.Ingress, bool) {
return nil, false
}
ing.Spec.IngressClassName = extractClassName(ing)
setDefaultPathTypeIfEmpty(ing)
return ing, true
}
if ing, ok := obj.(*networkingv1beta1.Ingress); ok {
ing.Spec.IngressClassName = extractClassName(ing)
setDefaultPathTypeIfEmpty(ing)
return ing, true
}
return nil, false
}
func extractClassName(ing *networkingv1beta1.Ingress) *string {
if c, ok := ing.Annotations[class.IngressKey]; ok {
return &c
}
return nil
}
// Default path type is Prefix to not break existing definitions
var defaultPathType = networkingv1beta1.PathTypePrefix