From cb130d3239a1d04acc9aba026760d4c4d5028285 Mon Sep 17 00:00:00 2001 From: mathetake Date: Tue, 10 Mar 2020 09:43:23 +0900 Subject: [PATCH] add api changes for making mirrorPercentage configurable --- artifacts/flagger/crd.yaml | 3 +++ charts/flagger/crds/crd.yaml | 3 +++ kustomize/base/flagger/crd.yaml | 3 +++ pkg/apis/flagger/v1beta1/canary.go | 6 +++++- pkg/apis/istio/v1alpha3/virtual_service.go | 10 +++++++++ .../istio/v1alpha3/zz_generated.deepcopy.go | 21 +++++++++++++++++++ 6 files changed, 45 insertions(+), 1 deletion(-) diff --git a/artifacts/flagger/crd.yaml b/artifacts/flagger/crd.yaml index 0c37ebc3..c46128f6 100644 --- a/artifacts/flagger/crd.yaml +++ b/artifacts/flagger/crd.yaml @@ -528,6 +528,9 @@ spec: mirror: description: Mirror traffic to canary type: boolean + mirrorWeight: + description: Weight of traffic to be mirrored when + type: number match: description: A/B testing match conditions type: array diff --git a/charts/flagger/crds/crd.yaml b/charts/flagger/crds/crd.yaml index 0c37ebc3..c46128f6 100644 --- a/charts/flagger/crds/crd.yaml +++ b/charts/flagger/crds/crd.yaml @@ -528,6 +528,9 @@ spec: mirror: description: Mirror traffic to canary type: boolean + mirrorWeight: + description: Weight of traffic to be mirrored when + type: number match: description: A/B testing match conditions type: array diff --git a/kustomize/base/flagger/crd.yaml b/kustomize/base/flagger/crd.yaml index 0c37ebc3..c46128f6 100644 --- a/kustomize/base/flagger/crd.yaml +++ b/kustomize/base/flagger/crd.yaml @@ -528,6 +528,9 @@ spec: mirror: description: Mirror traffic to canary type: boolean + mirrorWeight: + description: Weight of traffic to be mirrored when + type: number match: description: A/B testing match conditions type: array diff --git a/pkg/apis/flagger/v1beta1/canary.go b/pkg/apis/flagger/v1beta1/canary.go index f13bd908..51e81c9b 100644 --- a/pkg/apis/flagger/v1beta1/canary.go +++ b/pkg/apis/flagger/v1beta1/canary.go @@ -175,10 +175,14 @@ type CanaryAnalysis struct { // +optional Iterations int `json:"iterations,omitempty"` - //Enable traffic mirroring for Blue/Green + // Enable traffic mirroring for Blue/Green // +optional Mirror bool `json:"mirror,omitempty"` + // Percentage of the traffic to be mirrored when mirroring is enabled + // +optional + MirrorWeight float64 `json:"mirror_weight,omitempty"` + // Max traffic percentage routed to canary // +optional MaxWeight int `json:"maxWeight,omitempty"` diff --git a/pkg/apis/istio/v1alpha3/virtual_service.go b/pkg/apis/istio/v1alpha3/virtual_service.go index d800142b..84ca29e2 100644 --- a/pkg/apis/istio/v1alpha3/virtual_service.go +++ b/pkg/apis/istio/v1alpha3/virtual_service.go @@ -325,6 +325,11 @@ type HTTPRoute struct { // destination. Mirror *Destination `json:"mirror,omitempty"` + // Percentage of the traffic to be mirrored by the `mirror` field. + // If this field is absent, all the traffic (100%) will be mirrored. + // Max value is 100. + MirrorPercentage *Percent `json:"mirror_percentage"` + // Cross-Origin Resource Sharing policy (CORS). Refer to // https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS // for further details about cross origin resource sharing. @@ -334,6 +339,11 @@ type HTTPRoute struct { Headers *Headers `json:"headers,omitempty"` } +// Percent specifies a percentage in the range of [0.0, 100.0]. +type Percent struct { + Value float64 `json:"value,omitempty"` +} + // Header manipulation rules type Headers struct { // Header manipulation rules to apply before forwarding a request diff --git a/pkg/apis/istio/v1alpha3/zz_generated.deepcopy.go b/pkg/apis/istio/v1alpha3/zz_generated.deepcopy.go index 9447a78e..a187f416 100644 --- a/pkg/apis/istio/v1alpha3/zz_generated.deepcopy.go +++ b/pkg/apis/istio/v1alpha3/zz_generated.deepcopy.go @@ -421,6 +421,11 @@ func (in *HTTPRoute) DeepCopyInto(out *HTTPRoute) { *out = new(Destination) (*in).DeepCopyInto(*out) } + if in.MirrorPercentage != nil { + in, out := &in.MirrorPercentage, &out.MirrorPercentage + *out = new(Percent) + **out = **in + } if in.CorsPolicy != nil { in, out := &in.CorsPolicy, &out.CorsPolicy *out = new(CorsPolicy) @@ -628,6 +633,22 @@ func (in *OutlierDetection) DeepCopy() *OutlierDetection { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Percent) DeepCopyInto(out *Percent) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Percent. +func (in *Percent) DeepCopy() *Percent { + if in == nil { + return nil + } + out := new(Percent) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PortSelector) DeepCopyInto(out *PortSelector) { *out = *in