Skip to content

Commit 089e252

Browse files
ivanmatmatiMo3m3n
authored andcommitted
MINOR: support default IngressClass
IngressClass resources marked as default via `ingressclass.kubernetes.io/is-default-class` annotations are now supported.
1 parent f1a4c87 commit 089e252

File tree

3 files changed

+47
-24
lines changed

3 files changed

+47
-24
lines changed

controller/ingress/ingress.go

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,26 +59,38 @@ func (i Ingress) supported(k8s store.K8s) (supported bool) {
5959
if igClassResource := k8s.IngressClasses[i.resource.Class]; igClassResource != nil && igClassResource.Status != store.DELETED {
6060
igClassSpec = igClassResource.Controller
6161
}
62-
63-
defer func() {
64-
if supported && i.resource.Ignored {
65-
i.resource.Status = store.ADDED
66-
i.resource.Ignored = false
62+
if igClassAnn == "" && i.resource.Class == "" {
63+
for _, ingressClass := range k8s.IngressClasses {
64+
if ingressClass.Annotations["ingressclass.kubernetes.io/is-default-class"] == "true" {
65+
igClassSpec = ingressClass.Controller
66+
break
67+
}
6768
}
68-
}()
69-
70-
emptyClass := igClassAnn == "" && i.resource.Class == ""
69+
}
7170

72-
if i.controllerClass == "" {
73-
supported = emptyClass || igClassSpec == CONTROLLER
74-
} else {
75-
supported = (emptyClass && i.allowEmptyClass) ||
76-
igClassAnn == i.controllerClass ||
77-
igClassSpec == filepath.Join(CONTROLLER, i.controllerClass)
71+
switch i.controllerClass {
72+
case "":
73+
if igClassAnn == "" {
74+
supported = (i.resource.Class == "" && igClassSpec == "") || igClassSpec == CONTROLLER
75+
} else if igClassSpec == CONTROLLER {
76+
logger.Warningf("Ingress '%s/%s': conflicting ingress class mechanisms", i.resource.Namespace, i.resource.Name)
77+
}
78+
case igClassAnn:
79+
supported = true
80+
default:
81+
if igClassAnn == "" {
82+
supported = i.resource.Class == "" && i.allowEmptyClass || igClassSpec == filepath.Join(CONTROLLER, i.controllerClass)
83+
} else if igClassSpec == filepath.Join(CONTROLLER, i.controllerClass) {
84+
logger.Warningf("Ingress '%s/%s': conflicting ingress class mechanisms", i.resource.Namespace, i.resource.Name)
85+
}
7886
}
7987
if !supported {
8088
i.resource.Ignored = true
8189
}
90+
if supported && i.resource.Ignored {
91+
i.resource.Status = store.ADDED
92+
i.resource.Ignored = false
93+
}
8294
return
8395
}
8496

controller/store/convert.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,15 @@ func (n ingressNetworkingV1Beta1Strategy) ConvertIngress() *Ingress {
163163
}
164164

165165
func (n ingressNetworkingV1Beta1Strategy) ConvertClass() *IngressClass {
166+
annotations := make(map[string]string, len(n.class.Annotations))
167+
for key, value := range n.class.Annotations {
168+
annotations[key] = value
169+
}
166170
return &IngressClass{
167-
APIVersion: NETWORKINGV1BETA1,
168-
Name: n.class.GetName(),
169-
Controller: n.class.Spec.Controller,
171+
APIVersion: NETWORKINGV1BETA1,
172+
Name: n.class.GetName(),
173+
Controller: n.class.Spec.Controller,
174+
Annotations: annotations,
170175
Status: func() Status {
171176
if n.class.ObjectMeta.GetDeletionTimestamp() != nil {
172177
return DELETED
@@ -353,10 +358,15 @@ func (n ingressNetworkingV1Strategy) ConvertIngress() *Ingress {
353358
}
354359

355360
func (n ingressNetworkingV1Strategy) ConvertClass() *IngressClass {
361+
annotations := make(map[string]string, len(n.class.Annotations))
362+
for key, value := range n.class.Annotations {
363+
annotations[key] = value
364+
}
356365
return &IngressClass{
357-
APIVersion: NETWORKINGV1,
358-
Name: n.class.GetName(),
359-
Controller: n.class.Spec.Controller,
366+
APIVersion: NETWORKINGV1,
367+
Name: n.class.GetName(),
368+
Controller: n.class.Spec.Controller,
369+
Annotations: annotations,
360370
Status: func() Status {
361371
if n.class.ObjectMeta.GetDeletionTimestamp() != nil {
362372
return DELETED

controller/store/types.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,11 @@ type CustomResources struct {
9595
}
9696

9797
type IngressClass struct {
98-
APIVersion string
99-
Name string
100-
Controller string
101-
Status Status
98+
APIVersion string
99+
Name string
100+
Controller string
101+
Annotations map[string]string
102+
Status Status
102103
}
103104

104105
// IngressPath is useful data from k8s structures about ingress path

0 commit comments

Comments
 (0)