Skip to content

Commit

Permalink
add validation for additionalStableIngresses
Browse files Browse the repository at this point in the history
Signed-off-by: Travis Perdue <perduetravis@gmail.com>
Signed-off-by: Travis Perdue <travis.perdue@rallyhealth.com>
  • Loading branch information
tperdue321 authored and Travis Perdue committed Jan 12, 2023
1 parent 9cdf72b commit 62e9534
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions pkg/apis/rollouts/validation/validation_references.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,23 +218,39 @@ func setArgValuePlaceHolder(Args []v1alpha1.Argument) {
func ValidateIngress(rollout *v1alpha1.Rollout, ingress *ingressutil.Ingress) field.ErrorList {
allErrs := field.ErrorList{}
fldPath := field.NewPath("spec", "strategy", "canary", "trafficRouting")
canary := rollout.Spec.Strategy.Canary
var ingressName string
var serviceName string
if rollout.Spec.Strategy.Canary.TrafficRouting.Nginx != nil {
if canary.TrafficRouting.Nginx != nil {
// If there are additional stable ingresses
if len(canary.TrafficRouting.Nginx.AdditionalStableIngresses) > 0 {
// validate each ingress as valid
fldPath = fldPath.Child("nginx").Child("additionalStableIngresses")
serviceName = canary.StableService
for _, ing := range canary.TrafficRouting.Nginx.AdditionalStableIngresses {
ingressName = ing
allErrs = reportErrors(ingress, serviceName, ingressName, fldPath, allErrs)
}
}
fldPath = fldPath.Child("nginx").Child("stableIngress")
serviceName = rollout.Spec.Strategy.Canary.StableService
ingressName = rollout.Spec.Strategy.Canary.TrafficRouting.Nginx.StableIngress
} else if rollout.Spec.Strategy.Canary.TrafficRouting.ALB != nil {
serviceName = canary.StableService
ingressName = canary.TrafficRouting.Nginx.StableIngress

allErrs = reportErrors(ingress, serviceName, ingressName, fldPath, allErrs)
} else if canary.TrafficRouting.ALB != nil {
fldPath = fldPath.Child("alb").Child("ingress")
ingressName = rollout.Spec.Strategy.Canary.TrafficRouting.ALB.Ingress
serviceName = rollout.Spec.Strategy.Canary.StableService
if rollout.Spec.Strategy.Canary.TrafficRouting.ALB.RootService != "" {
serviceName = rollout.Spec.Strategy.Canary.TrafficRouting.ALB.RootService
ingressName = canary.TrafficRouting.ALB.Ingress
serviceName = canary.StableService
if canary.TrafficRouting.ALB.RootService != "" {
serviceName = canary.TrafficRouting.ALB.RootService
}

} else {
return allErrs
allErrs = reportErrors(ingress, serviceName, ingressName, fldPath, allErrs)
}

return allErrs
}

func reportErrors(ingress *ingressutil.Ingress, serviceName, ingressName string, fldPath *field.Path, allErrs field.ErrorList) field.ErrorList {
if !ingressutil.HasRuleWithService(ingress, serviceName) {
msg := fmt.Sprintf("ingress `%s` has no rules using service %s backend", ingress.GetName(), serviceName)
allErrs = append(allErrs, field.Invalid(fldPath, ingressName, msg))
Expand Down

0 comments on commit 62e9534

Please sign in to comment.