Skip to content

Commit

Permalink
Merge pull request #303 from codefresh-io/skip-validation-with-plugin
Browse files Browse the repository at this point in the history
chore: leave the validation of setHeaderRoute to the plugin when plug…
  • Loading branch information
denis-codefresh authored Jul 3, 2024
2 parents f626e34 + 594f87a commit 791f6b3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.6.1-additional-logs
v1.6.1-CR-23199
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 791f6b3

Please sign in to comment.