Fix bug with ingress path cleanup

Signed-off-by: James Munnelly <james@munnelly.eu>
This commit is contained in:
James Munnelly 2018-11-16 12:19:53 +00:00
parent b279e3a3fc
commit a303056b16

View File

@ -233,23 +233,30 @@ func (s *Solver) cleanupIngresses(ch *v1alpha1.Challenge) error {
ingPathToDel := solverPathFn(ch.Spec.Token)
var ingRules []extv1beta1.IngressRule
for _, rule := range ing.Spec.Rules {
if rule.Host == ch.Spec.DNSName {
if rule.HTTP == nil {
ingRules = append(ingRules, rule)
continue
}
// check the rule for paths. If we find the ingress path we need to
// delete here, delete it
for i, path := range rule.HTTP.Paths {
if path.Path == ingPathToDel {
rule.HTTP.Paths = append(rule.HTTP.Paths[:i], rule.HTTP.Paths[i+1:]...)
}
}
// if there are still paths level on this rule, we should retain it
if len(rule.HTTP.Paths) > 0 {
ingRules = append(ingRules, rule)
// always retain rules that are not for the same DNSName
if rule.Host != ch.Spec.DNSName {
ingRules = append(ingRules, rule)
continue
}
// always retain rules that don't specify `HTTP`
if rule.HTTP == nil {
ingRules = append(ingRules, rule)
continue
}
// check the rule for paths. If we find the ingress path we need to
// delete here, delete it
for i, path := range rule.HTTP.Paths {
if path.Path == ingPathToDel {
rule.HTTP.Paths = append(rule.HTTP.Paths[:i], rule.HTTP.Paths[i+1:]...)
}
}
// if there are still paths level on this rule, we should retain it
if len(rule.HTTP.Paths) > 0 {
ingRules = append(ingRules, rule)
}
}
ing.Spec.Rules = ingRules