Skip to content

Commit 9041045

Browse files
fix: allows plugins to implement traffic mirroring (and not just Istio) (#4643)
fix: allows plugins to implement traffic mirroring Signed-off-by: Kostis Kapelonis <kostis.kapelonis@octopus.com>
1 parent 0a1568d commit 9041045

2 files changed

Lines changed: 67 additions & 7 deletions

File tree

pkg/apis/rollouts/validation/validation.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ const (
3636
InvalidSetCanaryScaleTrafficPolicy = "SetCanaryScale requires TrafficRouting to be set"
3737
// InvalidSetHeaderRouteTrafficPolicy indicates that TrafficRouting required for SetHeaderRoute is missing
3838
InvalidSetHeaderRouteTrafficPolicy = "SetHeaderRoute requires TrafficRouting, supports Istio and ALB and Apisix"
39-
// InvalidSetMirrorRouteTrafficPolicy indicates that TrafficRouting, required for SetCanaryScale, is missing
40-
InvalidSetMirrorRouteTrafficPolicy = "SetMirrorRoute requires TrafficRouting, supports Istio only"
39+
// InvalidSetMirrorRouteTrafficPolicy indicates that TrafficRouting, required for SetMirrorRoute, is missing
40+
InvalidSetMirrorRouteTrafficPolicy = "SetMirrorRoute requires TrafficRouting, supports Istio and Plugins"
4141
// InvalidStringMatchMultipleValuePolicy indicates that SetCanaryScale, has multiple values set
4242
InvalidStringMatchMultipleValuePolicy = "StringMatch match value must have exactly one of the following: exact, regex, prefix"
4343
// InvalidStringMatchMissedValuePolicy indicates that SetCanaryScale, has multiple values set
@@ -350,8 +350,8 @@ func ValidateRolloutStrategyCanary(rollout *v1alpha1.Rollout, fldPath *field.Pat
350350

351351
if step.SetMirrorRoute != nil {
352352
trafficRouting := rollout.Spec.Strategy.Canary.TrafficRouting
353-
if trafficRouting == nil || trafficRouting.Istio == nil {
354-
allErrs = append(allErrs, field.Invalid(stepFldPath.Child("setMirrorRoute"), step.SetMirrorRoute, "SetMirrorRoute requires TrafficRouting, supports Istio only"))
353+
if trafficRouting == nil || (trafficRouting.Istio == nil && len(trafficRouting.Plugins) == 0) {
354+
allErrs = append(allErrs, field.Invalid(stepFldPath.Child("setMirrorRoute"), step.SetMirrorRoute, InvalidSetMirrorRouteTrafficPolicy))
355355
}
356356
if step.SetMirrorRoute.Match != nil && len(step.SetMirrorRoute.Match) > 0 {
357357
for j, match := range step.SetMirrorRoute.Match {

pkg/apis/rollouts/validation/validation_test.go

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -539,9 +539,9 @@ func TestValidateRolloutStrategyCanarySetHeaderRoutePlugins(t *testing.T) {
539539
}
540540

541541
t.Run("using SetHeaderRoute step with plugins", func(t *testing.T) {
542-
invalidRo := ro.DeepCopy()
542+
validRo := ro.DeepCopy()
543543
routeName := "test"
544-
invalidRo.Spec.Strategy.Canary.Steps = []v1alpha1.CanaryStep{{
544+
validRo.Spec.Strategy.Canary.Steps = []v1alpha1.CanaryStep{{
545545
SetHeaderRoute: &v1alpha1.SetHeaderRoute{
546546
Name: routeName,
547547
Match: []v1alpha1.HeaderRoutingMatch{
@@ -552,7 +552,7 @@ func TestValidateRolloutStrategyCanarySetHeaderRoutePlugins(t *testing.T) {
552552
},
553553
},
554554
}}
555-
invalidRo.Spec.Strategy.Canary.TrafficRouting = &v1alpha1.RolloutTrafficRouting{
555+
validRo.Spec.Strategy.Canary.TrafficRouting = &v1alpha1.RolloutTrafficRouting{
556556
ManagedRoutes: []v1alpha1.MangedRoutes{
557557
{
558558
Name: routeName,
@@ -562,7 +562,67 @@ func TestValidateRolloutStrategyCanarySetHeaderRoutePlugins(t *testing.T) {
562562
"anyplugin": []byte(`{"key": "value"}`),
563563
},
564564
}
565+
allErrs := ValidateRolloutStrategyCanary(validRo, field.NewPath(""))
566+
assert.Equal(t, 0, len(allErrs))
567+
})
568+
}
569+
570+
func TestValidateRolloutStrategyCanarySetMirrorRoute(t *testing.T) {
571+
ro := &v1alpha1.Rollout{}
572+
ro.Spec.Strategy.Canary = &v1alpha1.CanaryStrategy{
573+
CanaryService: "canary",
574+
StableService: "stable",
575+
}
576+
577+
t.Run("using SetMirrorRoute step without the traffic routing", func(t *testing.T) {
578+
invalidRo := ro.DeepCopy()
579+
invalidRo.Spec.Strategy.Canary.Steps = []v1alpha1.CanaryStep{{
580+
SetMirrorRoute: &v1alpha1.SetMirrorRoute{
581+
Name: "test-mirror-1",
582+
Match: nil,
583+
Percentage: nil,
584+
},
585+
}}
565586
allErrs := ValidateRolloutStrategyCanary(invalidRo, field.NewPath(""))
587+
assert.Equal(t, InvalidSetMirrorRouteTrafficPolicy, allErrs[0].Detail)
588+
})
589+
}
590+
591+
func TestValidateRolloutStrategyCanarySetMirrorRoutePlugins(t *testing.T) {
592+
ro := &v1alpha1.Rollout{}
593+
ro.Spec.Strategy.Canary = &v1alpha1.CanaryStrategy{
594+
CanaryService: "canary",
595+
StableService: "stable",
596+
}
597+
598+
t.Run("using SetMirrorRoute step with plugins", func(t *testing.T) {
599+
validRo := ro.DeepCopy()
600+
routeName := "test-mirror-1"
601+
validRo.Spec.Strategy.Canary.Steps = []v1alpha1.CanaryStep{{
602+
SetMirrorRoute: &v1alpha1.SetMirrorRoute{
603+
Name: routeName,
604+
Match: []v1alpha1.RouteMatch{{
605+
Method: &v1alpha1.StringMatch{
606+
Exact: "GET",
607+
},
608+
Path: &v1alpha1.StringMatch{
609+
Prefix: "/api",
610+
},
611+
}},
612+
Percentage: ptr.To[int32](50),
613+
},
614+
}}
615+
validRo.Spec.Strategy.Canary.TrafficRouting = &v1alpha1.RolloutTrafficRouting{
616+
ManagedRoutes: []v1alpha1.MangedRoutes{
617+
{
618+
Name: routeName,
619+
},
620+
},
621+
Plugins: map[string]json.RawMessage{
622+
"anyplugin": []byte(`{"key": "value"}`),
623+
},
624+
}
625+
allErrs := ValidateRolloutStrategyCanary(validRo, field.NewPath(""))
566626
assert.Equal(t, 0, len(allErrs))
567627
})
568628
}

0 commit comments

Comments
 (0)