Skip to content

Commit

Permalink
adding validation so ping-pong feature support only ALB traffic routing
Browse files Browse the repository at this point in the history
Signed-off-by: Andrii Perenesenko <[email protected]>
  • Loading branch information
perenesenko committed Feb 1, 2022
1 parent 0d1d08e commit 85888d6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 3 additions & 1 deletion pkg/apis/rollouts/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,9 @@ func ValidateRolloutStrategyCanary(rollout *v1alpha1.Rollout, fldPath *field.Pat
allErrs = append(allErrs, field.Invalid(fldPath.Child("stableService"), canary.StableService, DuplicatedServicesCanaryMessage))
}
if canary.PingPong != nil {
if canary.TrafficRouting == nil || canary.TrafficRouting.ALB == nil {
if canary.TrafficRouting == nil {
allErrs = append(allErrs, field.Invalid(fldPath.Child("trafficRouting"), canary.TrafficRouting, PingPongWithAlbOnlyMessage))
} else if canary.TrafficRouting.ALB == nil {
allErrs = append(allErrs, field.Invalid(fldPath.Child("trafficRouting").Child("alb"), canary.TrafficRouting.ALB, PingPongWithAlbOnlyMessage))
}
if canary.PingPong.PingService == "" {
Expand Down
13 changes: 9 additions & 4 deletions pkg/apis/rollouts/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,12 @@ func TestValidateRolloutStrategyCanary(t *testing.T) {
CanaryService: "canary",
StableService: "stable",
TrafficRouting: &v1alpha1.RolloutTrafficRouting{
SMI: &v1alpha1.SMITrafficRouting{},
ALB: &v1alpha1.ALBTrafficRouting{RootService: "root-service"},
},
Steps: []v1alpha1.CanaryStep{{}},
}
ro := &v1alpha1.Rollout{}
ro.Spec.Strategy.Canary = canaryStrategy
ro.Spec.Strategy.Canary.TrafficRouting = &v1alpha1.RolloutTrafficRouting{
ALB: &v1alpha1.ALBTrafficRouting{RootService: "root-service"},
}

invalidArgs := []v1alpha1.AnalysisRunArgument{
{
Expand Down Expand Up @@ -211,6 +208,14 @@ func TestValidateRolloutStrategyCanary(t *testing.T) {
assert.Equal(t, PingPongWithAlbOnlyMessage, allErrs[0].Detail)
})

t.Run("ping-pong feature without the ALB traffic routing", func(t *testing.T) {
invalidRo := ro.DeepCopy()
invalidRo.Spec.Strategy.Canary.PingPong = &v1alpha1.PingPongSpec{PingService: "ping", PongService: "pong"}
invalidRo.Spec.Strategy.Canary.TrafficRouting = nil
allErrs := ValidateRolloutStrategyCanary(invalidRo, field.NewPath(""))
assert.Equal(t, PingPongWithAlbOnlyMessage, allErrs[0].Detail)
})

t.Run("invalid traffic routing", func(t *testing.T) {
invalidRo := ro.DeepCopy()
invalidRo.Spec.Strategy.Canary.CanaryService = ""
Expand Down

0 comments on commit 85888d6

Please sign in to comment.