diff --git a/pkg/controller/scheduler.go b/pkg/controller/scheduler.go index 95dfda247..d60a7e953 100644 --- a/pkg/controller/scheduler.go +++ b/pkg/controller/scheduler.go @@ -92,7 +92,7 @@ func (c *Controller) advanceCanary(name string, namespace string, skipLivenessCh meshRouter = rf.IstioRouter() // create ClusterIP services and virtual service if needed - if err := rf.ServiceRouter().Sync(cd); err != nil { + if err := rf.KubernetesRouter().Sync(cd); err != nil { c.recordEventWarningf(cd, "%v", err) return } diff --git a/pkg/router/factory.go b/pkg/router/factory.go index 3c73abd28..332ff367f 100644 --- a/pkg/router/factory.go +++ b/pkg/router/factory.go @@ -26,8 +26,8 @@ func NewFactory(kubeClient kubernetes.Interface, } } -func (factory *Factory) ServiceRouter() *ServiceRouter { - return &ServiceRouter{ +func (factory *Factory) KubernetesRouter() *KubernetesRouter { + return &KubernetesRouter{ logger: factory.logger, flaggerClient: factory.flaggerClient, kubeClient: factory.kubeClient, diff --git a/pkg/router/istio.go b/pkg/router/istio.go index 17e39259a..9fcfb801b 100644 --- a/pkg/router/istio.go +++ b/pkg/router/istio.go @@ -126,20 +126,20 @@ func (ir *IstioRouter) Sync(cd *flaggerv1.Canary) error { } // GetRoutes returns the destinations weight for primary and canary -func (ir *IstioRouter) GetRoutes(cd *flaggerv1.Canary) ( +func (ir *IstioRouter) GetRoutes(canary *flaggerv1.Canary) ( primaryWeight int, canaryWeight int, err error, ) { - targetName := cd.Spec.TargetRef.Name + targetName := canary.Spec.TargetRef.Name vs := &istiov1alpha3.VirtualService{} - vs, err = ir.istioClient.NetworkingV1alpha3().VirtualServices(cd.Namespace).Get(targetName, v1.GetOptions{}) + vs, err = ir.istioClient.NetworkingV1alpha3().VirtualServices(canary.Namespace).Get(targetName, v1.GetOptions{}) if err != nil { if errors.IsNotFound(err) { - err = fmt.Errorf("VirtualService %s.%s not found", targetName, cd.Namespace) + err = fmt.Errorf("VirtualService %s.%s not found", targetName, canary.Namespace) return } - err = fmt.Errorf("VirtualService %s.%s query error %v", targetName, cd.Namespace, err) + err = fmt.Errorf("VirtualService %s.%s query error %v", targetName, canary.Namespace, err) return } @@ -156,7 +156,7 @@ func (ir *IstioRouter) GetRoutes(cd *flaggerv1.Canary) ( if primaryWeight == 0 && canaryWeight == 0 { err = fmt.Errorf("VirtualService %s.%s does not contain routes for %s-primary and %s-canary", - targetName, cd.Namespace, targetName, targetName) + targetName, canary.Namespace, targetName, targetName) } return @@ -164,34 +164,34 @@ func (ir *IstioRouter) GetRoutes(cd *flaggerv1.Canary) ( // SetRoutes updates the destinations weight for primary and canary func (ir *IstioRouter) SetRoutes( - cd *flaggerv1.Canary, + canary *flaggerv1.Canary, primaryWeight int, canaryWeight int, ) error { - targetName := cd.Spec.TargetRef.Name - vs, err := ir.istioClient.NetworkingV1alpha3().VirtualServices(cd.Namespace).Get(targetName, v1.GetOptions{}) + targetName := canary.Spec.TargetRef.Name + vs, err := ir.istioClient.NetworkingV1alpha3().VirtualServices(canary.Namespace).Get(targetName, v1.GetOptions{}) if err != nil { if errors.IsNotFound(err) { - return fmt.Errorf("VirtualService %s.%s not found", targetName, cd.Namespace) + return fmt.Errorf("VirtualService %s.%s not found", targetName, canary.Namespace) } - return fmt.Errorf("VirtualService %s.%s query error %v", targetName, cd.Namespace, err) + return fmt.Errorf("VirtualService %s.%s query error %v", targetName, canary.Namespace, err) } vsCopy := vs.DeepCopy() vsCopy.Spec.Http = []istiov1alpha3.HTTPRoute{ { - Match: cd.Spec.Service.Match, - Rewrite: cd.Spec.Service.Rewrite, - Timeout: cd.Spec.Service.Timeout, - Retries: cd.Spec.Service.Retries, - AppendHeaders: cd.Spec.Service.AppendHeaders, + Match: canary.Spec.Service.Match, + Rewrite: canary.Spec.Service.Rewrite, + Timeout: canary.Spec.Service.Timeout, + Retries: canary.Spec.Service.Retries, + AppendHeaders: canary.Spec.Service.AppendHeaders, Route: []istiov1alpha3.DestinationWeight{ { Destination: istiov1alpha3.Destination{ Host: fmt.Sprintf("%s-primary", targetName), Port: istiov1alpha3.PortSelector{ - Number: uint32(cd.Spec.Service.Port), + Number: uint32(canary.Spec.Service.Port), }, }, Weight: primaryWeight, @@ -200,7 +200,7 @@ func (ir *IstioRouter) SetRoutes( Destination: istiov1alpha3.Destination{ Host: fmt.Sprintf("%s-canary", targetName), Port: istiov1alpha3.PortSelector{ - Number: uint32(cd.Spec.Service.Port), + Number: uint32(canary.Spec.Service.Port), }, }, Weight: canaryWeight, @@ -209,9 +209,9 @@ func (ir *IstioRouter) SetRoutes( }, } - vs, err = ir.istioClient.NetworkingV1alpha3().VirtualServices(cd.Namespace).Update(vsCopy) + vs, err = ir.istioClient.NetworkingV1alpha3().VirtualServices(canary.Namespace).Update(vsCopy) if err != nil { - return fmt.Errorf("VirtualService %s.%s update failed: %v", targetName, cd.Namespace, err) + return fmt.Errorf("VirtualService %s.%s update failed: %v", targetName, canary.Namespace, err) } return nil diff --git a/pkg/router/service.go b/pkg/router/kubernetes.go similarity index 92% rename from pkg/router/service.go rename to pkg/router/kubernetes.go index ab2ac01b3..5e86e20f7 100644 --- a/pkg/router/service.go +++ b/pkg/router/kubernetes.go @@ -13,15 +13,15 @@ import ( "k8s.io/client-go/kubernetes" ) -// ServiceRouter is managing ClusterIP services -type ServiceRouter struct { +// KubernetesRouter is managing ClusterIP services +type KubernetesRouter struct { kubeClient kubernetes.Interface flaggerClient clientset.Interface logger *zap.SugaredLogger } // Sync creates to updates the primary and canary services -func (c *ServiceRouter) Sync(cd *flaggerv1.Canary) error { +func (c *KubernetesRouter) Sync(cd *flaggerv1.Canary) error { targetName := cd.Spec.TargetRef.Name primaryName := fmt.Sprintf("%s-primary", targetName) canaryService, err := c.kubeClient.CoreV1().Services(cd.Namespace).Get(targetName, metav1.GetOptions{}) @@ -143,10 +143,10 @@ func (c *ServiceRouter) Sync(cd *flaggerv1.Canary) error { return nil } -func (c *ServiceRouter) SetRoutes(canary flaggerv1.Canary, primaryRoute int, canaryRoute int) error { +func (c *KubernetesRouter) SetRoutes(canary *flaggerv1.Canary, primaryRoute int, canaryRoute int) error { return nil } -func (c *ServiceRouter) GetRoutes(canary flaggerv1.Canary) (primaryRoute int, canaryRoute int, err error) { +func (c *KubernetesRouter) GetRoutes(canary *flaggerv1.Canary) (primaryRoute int, canaryRoute int, err error) { return 0, 0, nil } diff --git a/pkg/router/service_test.go b/pkg/router/kubernetes_test.go similarity index 97% rename from pkg/router/service_test.go rename to pkg/router/kubernetes_test.go index 2cae1aa3c..f9fef48cf 100644 --- a/pkg/router/service_test.go +++ b/pkg/router/kubernetes_test.go @@ -7,7 +7,7 @@ import ( func TestServiceRouter_Sync(t *testing.T) { mocks := setupfakeClients() - router := &ServiceRouter{ + router := &KubernetesRouter{ kubeClient: mocks.kubeClient, flaggerClient: mocks.flaggerClient, logger: mocks.logger,