From 9a9964c968834cfe2f890a6f2b212a8d08b509e1 Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Tue, 5 Mar 2019 02:27:56 +0200 Subject: [PATCH] Add ClusterIP host to virtual service --- pkg/router/istio.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/pkg/router/istio.go b/pkg/router/istio.go index 9fcfb801..18b49bd3 100644 --- a/pkg/router/istio.go +++ b/pkg/router/istio.go @@ -24,22 +24,38 @@ type IstioRouter struct { logger *zap.SugaredLogger } -// Sync creates or updates the the Istio virtual service. +// Sync creates or updates the Istio virtual service func (ir *IstioRouter) Sync(cd *flaggerv1.Canary) error { targetName := cd.Spec.TargetRef.Name primaryName := fmt.Sprintf("%s-primary", targetName) - hosts := append(cd.Spec.Service.Hosts, targetName) + + // set hosts and add the ClusterIP service host if it doesn't exists + hosts := cd.Spec.Service.Hosts + var hasServiceHost bool + for _, h := range hosts { + if h == targetName { + hasServiceHost = true + break + } + } + if !hasServiceHost { + hosts = append(hosts, targetName) + } + + // set gateways and add the mesh gateway if it doesn't exists gateways := cd.Spec.Service.Gateways var hasMeshGateway bool for _, g := range gateways { if g == "mesh" { hasMeshGateway = true + break } } if !hasMeshGateway { gateways = append(gateways, "mesh") } + // create destinations with primary weight 100% and canary weight 0% route := []istiov1alpha3.DestinationWeight{ { Destination: istiov1alpha3.Destination{