Skip to content

Commit

Permalink
Support virtualService delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
kazukousen committed Oct 22, 2020
1 parent 4d9fbc5 commit a335ea2
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions artifacts/flagger/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ spec:
type: array
items:
type: string
isDelegation:
description: enable behaving as a delegate VirtualService
type: boolean
match:
description: URI match conditions
type: array
Expand Down
3 changes: 3 additions & 0 deletions charts/flagger/crds/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ spec:
type: array
items:
type: string
isDelegation:
description: enable behaving as a delegate VirtualService
type: boolean
match:
description: URI match conditions
type: array
Expand Down
3 changes: 3 additions & 0 deletions kustomize/base/flagger/crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ spec:
type: array
items:
type: string
isDelegation:
description: enable behaving as a delegate VirtualService
type: boolean
match:
description: URI match conditions
type: array
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/flagger/v1beta1/canary.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ type CanaryService struct {
// +optional
Hosts []string `json:"hosts,omitempty"`

// IsDelegation behaves as a delegate virtual service
// if enabled, the pilot env `PILOT_ENABLE_VIRTUAL_SERVICE_DELEGATE` must also be set to enabled.
// +optional
IsDelegation bool `json:"is_delegation,omitempty"`

// TrafficPolicy attached to the generated Istio destination rules
// +optional
TrafficPolicy *istiov1alpha3.TrafficPolicy `json:"trafficPolicy,omitempty"`
Expand Down
13 changes: 13 additions & 0 deletions pkg/router/istio.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ func (ir *IstioRouter) reconcileDestinationRule(canary *flaggerv1.Canary, name s
func (ir *IstioRouter) reconcileVirtualService(canary *flaggerv1.Canary) error {
apexName, primaryName, canaryName := canary.GetServiceNames()

if canary.Spec.Service.IsDelegation {
if len(canary.Spec.Service.Hosts) > 0 || len(canary.Spec.Service.Gateways) > 0 {
// delegate VirtualService cannot have hosts and gateways.
return fmt.Errorf("VirtualService %s.%s cannot have hosts and gateways", apexName, canary.Namespace)
}
}

// set hosts and add the ClusterIP service host if it doesn't exists
hosts := canary.Spec.Service.Hosts
var hasServiceHost bool
Expand Down Expand Up @@ -132,6 +139,12 @@ func (ir *IstioRouter) reconcileVirtualService(canary *flaggerv1.Canary) error {
makeDestination(canary, canaryName, 0),
}

if canary.Spec.Service.IsDelegation {
// delegate VirtualService requires the hosts and gateway empty.
hosts = []string{}
gateways = []string{}
}

newSpec := istiov1alpha3.VirtualServiceSpec{
Hosts: hosts,
Gateways: gateways,
Expand Down

0 comments on commit a335ea2

Please sign in to comment.