Refactor ingress validation in webhook

This commit is contained in:
Manuel Alejandro de Brito Fontes 2020-04-28 11:14:27 -04:00
parent c8eb914d8a
commit af910a16d4
7 changed files with 96 additions and 86 deletions

View file

@ -199,19 +199,18 @@ func (n *NGINXController) syncIngress(interface{}) error {
// CheckIngress returns an error in case the provided ingress, when added
// to the current configuration, generates an invalid configuration
func (n *NGINXController) CheckIngress(ing *networking.Ingress) error {
if ing == nil {
// no ingress to add, no state change
return nil
}
if !class.IsValid(ing) {
klog.Infof("ignoring ingress %v in %v based on annotation %v", ing.Name, ing.ObjectMeta.Namespace, class.IngressKey)
klog.Warningf("ignoring ingress %v in %v based on annotation %v", ing.Name, ing.ObjectMeta.Namespace, class.IngressKey)
return nil
}
if n.cfg.Namespace != "" && ing.ObjectMeta.Namespace != n.cfg.Namespace {
klog.Infof("ignoring ingress %v in namespace %v different from the namespace watched %s", ing.Name, ing.ObjectMeta.Namespace, n.cfg.Namespace)
klog.Warningf("ignoring ingress %v in namespace %v different from the namespace watched %s", ing.Name, ing.ObjectMeta.Namespace, n.cfg.Namespace)
return nil
}
@ -220,7 +219,7 @@ func (n *NGINXController) CheckIngress(ing *networking.Ingress) error {
toCheck.ObjectMeta.Name == ing.ObjectMeta.Name
}
k8s.SetDefaultPathTypeIfEmpty(ing)
k8s.SetDefaultNGINXPathType(ing)
ings := n.store.ListIngresses(filter)
ings = append(ings, &ingress.Ingress{

View file

@ -662,20 +662,11 @@ func (s *k8sStore) syncIngress(ing *networkingv1beta1.Ingress) {
if path.Path == "" {
copyIng.Spec.Rules[ri].HTTP.Paths[pi].Path = "/"
}
if path.PathType == nil {
copyIng.Spec.Rules[ri].HTTP.Paths[pi].PathType = &defaultPathType
continue
}
// PathType ImplementationSpecific is not supported.
// Set type to PathTypePrefix.
if *path.PathType == networkingv1beta1.PathTypeImplementationSpecific {
copyIng.Spec.Rules[ri].HTTP.Paths[pi].PathType = &defaultPathType
}
}
}
k8s.SetDefaultNGINXPathType(copyIng)
err := s.listers.IngressWithAnnotation.Update(&ingress.Ingress{
Ingress: *copyIng,
ParsedAnnotations: s.annotations.Extract(ing),
@ -963,12 +954,12 @@ func toIngress(obj interface{}) (*networkingv1beta1.Ingress, bool) {
return nil, false
}
k8s.SetDefaultPathTypeIfEmpty(ing)
k8s.SetDefaultNGINXPathType(ing)
return ing, true
}
if ing, ok := obj.(*networkingv1beta1.Ingress); ok {
k8s.SetDefaultPathTypeIfEmpty(ing)
k8s.SetDefaultNGINXPathType(ing)
return ing, true
}