Ensure webhook validation ingress has a PathTypePrefix

This commit is contained in:
Manuel Alejandro de Brito Fontes 2020-04-27 07:03:07 -04:00
parent bae9043171
commit dbaefc8ee9
3 changed files with 25 additions and 17 deletions

View file

@ -149,3 +149,22 @@ func NetworkingIngressAvailable(client clientset.Interface) (bool, bool) {
return runningVersion.AtLeast(version114), runningVersion.AtLeast(version118)
}
// Default path type is Prefix to not break existing definitions
var defaultPathType = networkingv1beta1.PathTypePrefix
// SetDefaultPathTypeIfEmpty sets a default PathType when is not defined.
func SetDefaultPathTypeIfEmpty(ing *networkingv1beta1.Ingress) {
for _, rule := range ing.Spec.Rules {
if rule.IngressRuleValue.HTTP == nil {
continue
}
for idx := range rule.IngressRuleValue.HTTP.Paths {
p := &rule.IngressRuleValue.HTTP.Paths[idx]
if p.PathType == nil {
p.PathType = &defaultPathType
}
}
}
}