From 0ca48d77be5b3adb08476ab767d6bcb5cc2084bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Cantournet?= Date: Thu, 1 Aug 2019 14:49:22 +0200 Subject: [PATCH] Fix Port discovery with multiple port services This fixes issue https://github.com/weaveworks/flagger/issues/263 We actually don't need to specify any ports in the VirtualService and DestinationRules. Istio will create clusters/listerners for each named port we have declared in the kubernetes services and the router can be shared as it operates only on L7 criterias Also contains a tiny clean-up of imports --- pkg/router/istio.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/pkg/router/istio.go b/pkg/router/istio.go index e7f45122..cb80a819 100644 --- a/pkg/router/istio.go +++ b/pkg/router/istio.go @@ -2,6 +2,7 @@ package router import ( "fmt" + "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" flaggerv1 "github.com/weaveworks/flagger/pkg/apis/flagger/v1alpha3" @@ -9,7 +10,6 @@ import ( clientset "github.com/weaveworks/flagger/pkg/client/clientset/versioned" "go.uber.org/zap" "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/client-go/kubernetes" @@ -236,7 +236,7 @@ func (ir *IstioRouter) GetRoutes(canary *flaggerv1.Canary) ( ) { targetName := canary.Spec.TargetRef.Name vs := &istiov1alpha3.VirtualService{} - vs, err = ir.istioClient.NetworkingV1alpha3().VirtualServices(canary.Namespace).Get(targetName, v1.GetOptions{}) + vs, err = ir.istioClient.NetworkingV1alpha3().VirtualServices(canary.Namespace).Get(targetName, metav1.GetOptions{}) if err != nil { if errors.IsNotFound(err) { err = fmt.Errorf("VirtualService %s.%s not found", targetName, canary.Namespace) @@ -283,7 +283,7 @@ func (ir *IstioRouter) SetRoutes( primaryName := fmt.Sprintf("%s-primary", targetName) canaryName := fmt.Sprintf("%s-canary", targetName) - vs, err := ir.istioClient.NetworkingV1alpha3().VirtualServices(canary.Namespace).Get(targetName, v1.GetOptions{}) + vs, err := ir.istioClient.NetworkingV1alpha3().VirtualServices(canary.Namespace).Get(targetName, metav1.GetOptions{}) if err != nil { if errors.IsNotFound(err) { return fmt.Errorf("VirtualService %s.%s not found", targetName, canary.Namespace) @@ -383,12 +383,5 @@ func makeDestination(canary *flaggerv1.Canary, host string, weight int) istiov1a Weight: weight, } - // if port discovery is enabled then we need to explicitly set the destination port - if canary.Spec.Service.PortDiscovery { - dest.Destination.Port = &istiov1alpha3.PortSelector{ - Number: uint32(canary.Spec.Service.Port), - } - } - return dest }