if oldIngress == nil {
return false
}
- // If feature gate is disabled, check if any service names in the old Ingresss
+
+ // Check if default backend service names in the old Ingress
+ if oldIngress.Spec.DefaultBackend != nil && oldIngress.Spec.DefaultBackend.Service != nil {
+ serviceName := oldIngress.Spec.DefaultBackend.Service.Name
+ // If a name doesn't validate with apimachineryvalidation.NameIsDNS1035Label, but does validate with apimachineryvalidation.NameIsDNSLabel,
+ // then we allow it to be used as a Service name in an Ingress.
+ dnsLabelValidationErrors := apimachineryvalidation.NameIsDNSLabel(serviceName, false)
+ dns1035LabelValidationErrors := apimachineryvalidation.NameIsDNS1035Label(serviceName, false)
+ if len(dnsLabelValidationErrors) == 0 && len(dns1035LabelValidationErrors) > 0 {
+ return true
+ }
+ }
+
+ // If feature gate is disabled, check if any service names in the old Ingress
for _, rule := range oldIngress.Spec.Rules {
if rule.HTTP == nil {
continue
return &networking.Ingress{Spec: networking.IngressSpec{Rules: rules}}
}
+ ingressWithDefaultBackend := func(defaultBackendName string, ruleServiceNames ...string) *networking.Ingress {
+ ing := basicIngress(ruleServiceNames...)
+ if defaultBackendName != "" {
+ ing.Spec.DefaultBackend = &networking.IngressBackend{
+ Service: &networking.IngressServiceBackend{
+ Name: defaultBackendName,
+ Port: networking.ServiceBackendPort{Number: 80},
+ },
+ }
+ }
+ return ing
+ }
+
tests := []struct {
name string
ingress *networking.Ingress
ingress: basicIngress("validname", "1abc-def"),
expect: true,
},
+ {
+ name: "defaultBackend with valid DNS1035 name",
+ ingress: ingressWithDefaultBackend("validname"),
+ expect: false,
+ },
+ {
+ name: "defaultBackend with DNS1123 valid but DNS1035 invalid name (starts with digit)",
+ ingress: ingressWithDefaultBackend("1-default-service"),
+ expect: true,
+ },
+ {
+ name: "defaultBackend relaxed name with valid rules",
+ ingress: ingressWithDefaultBackend("1-default", "valid-rule-service"),
+ expect: true,
+ },
+ {
+ name: "only rules have relaxed name, defaultBackend is valid",
+ ingress: ingressWithDefaultBackend("valid-default", "1-rule-service"),
+ expect: true,
+ },
}
for _, tc := range tests {