Skip to content

Commit

Permalink
chore: leave the validation of setHeaderRoute to the plugin if plugin…
Browse files Browse the repository at this point in the history
…s not empty.

Signed-off-by: andyliuliming <[email protected]>
  • Loading branch information
Ubuntu committed Jul 22, 2023
1 parent 45e549d commit 925ed82
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/apis/rollouts/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func ValidateRolloutStrategyCanary(rollout *v1alpha1.Rollout, fldPath *field.Pat

if step.SetHeaderRoute != nil {
trafficRouting := rollout.Spec.Strategy.Canary.TrafficRouting
if trafficRouting == nil || (trafficRouting.Istio == nil && trafficRouting.ALB == nil && trafficRouting.Apisix == nil) {
if trafficRouting == nil || (trafficRouting.Istio == nil && trafficRouting.ALB == nil && trafficRouting.Apisix == nil && len(trafficRouting.Plugins) == 0) {
allErrs = append(allErrs, field.Invalid(stepFldPath.Child("setHeaderRoute"), step.SetHeaderRoute, InvalidSetHeaderRouteTrafficPolicy))
} else if step.SetHeaderRoute.Match != nil && len(step.SetHeaderRoute.Match) > 0 {
for j, match := range step.SetHeaderRoute.Match {
Expand Down
37 changes: 37 additions & 0 deletions pkg/apis/rollouts/validation/validation_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package validation

import (
"encoding/json"
"fmt"
"testing"

Expand Down Expand Up @@ -305,6 +306,42 @@ func TestValidateRolloutStrategyCanarySetHeaderRoute(t *testing.T) {
})
}

func TestValidateRolloutStrategyCanarySetHeaderRoutePlugins(t *testing.T) {
ro := &v1alpha1.Rollout{}
ro.Spec.Strategy.Canary = &v1alpha1.CanaryStrategy{
CanaryService: "canary",
StableService: "stable",
}

t.Run("using SetHeaderRoute step with plugins", func(t *testing.T) {
invalidRo := ro.DeepCopy()
routeName := "test"
invalidRo.Spec.Strategy.Canary.Steps = []v1alpha1.CanaryStep{{
SetHeaderRoute: &v1alpha1.SetHeaderRoute{
Name: routeName,
Match: []v1alpha1.HeaderRoutingMatch{
{
HeaderName: "agent",
HeaderValue: &v1alpha1.StringMatch{Exact: "chrome"},
},
},
},
}}
invalidRo.Spec.Strategy.Canary.TrafficRouting = &v1alpha1.RolloutTrafficRouting{
ManagedRoutes: []v1alpha1.MangedRoutes{
{
Name: routeName,
},
},
Plugins: map[string]json.RawMessage{
"anyplugin": []byte(`{"key": "value"}`),
},
}
allErrs := ValidateRolloutStrategyCanary(invalidRo, field.NewPath(""))
assert.Equal(t, 0, len(allErrs))
})
}

func TestValidateRolloutStrategyCanarySetHeaderRouteIstio(t *testing.T) {
ro := &v1alpha1.Rollout{}
ro.Spec.Strategy.Canary = &v1alpha1.CanaryStrategy{
Expand Down

0 comments on commit 925ed82

Please sign in to comment.