From 647ded58250f7d5ed3f1ebfc0139df46c1017838 Mon Sep 17 00:00:00 2001 From: Liming Liu Date: Sat, 9 Dec 2023 00:26:21 +0800 Subject: [PATCH 1/2] chore: leave the validation of setHeaderRoute to the plugin when plugins is not empty. (#2898) chore: leave the validation of setHeaderRoute to the plugin if plugins not empty. Signed-off-by: Liming Liu Co-authored-by: Ubuntu --- pkg/apis/rollouts/validation/validation.go | 2 +- .../rollouts/validation/validation_test.go | 37 +++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/pkg/apis/rollouts/validation/validation.go b/pkg/apis/rollouts/validation/validation.go index 34c4e3cbf9..94ba58f59b 100644 --- a/pkg/apis/rollouts/validation/validation.go +++ b/pkg/apis/rollouts/validation/validation.go @@ -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 { diff --git a/pkg/apis/rollouts/validation/validation_test.go b/pkg/apis/rollouts/validation/validation_test.go index 9722d0d093..58a4571ae7 100644 --- a/pkg/apis/rollouts/validation/validation_test.go +++ b/pkg/apis/rollouts/validation/validation_test.go @@ -1,6 +1,7 @@ package validation import ( + "encoding/json" "fmt" "testing" @@ -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{ From 594f87acf09af6a6e32dd10655b9b734ebf53158 Mon Sep 17 00:00:00 2001 From: Denys Melnyk Date: Tue, 2 Jul 2024 19:09:10 +0300 Subject: [PATCH 2/2] bump --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 691a5db1f8..40bdab01a0 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.6.1-additional-logs +v1.6.1-CR-23199