From ca074ef13fb7a922b85c061d1d74082032d0b0d9 Mon Sep 17 00:00:00 2001 From: stefanprodan Date: Tue, 26 Mar 2019 16:07:38 +0200 Subject: [PATCH] Rename router sync to reconcile --- pkg/controller/deployer.go | 2 +- pkg/controller/scheduler.go | 6 +++--- pkg/router/appmesh.go | 20 ++++++++++---------- pkg/router/appmesh_test.go | 10 +++++----- pkg/router/istio.go | 4 ++-- pkg/router/istio_test.go | 16 ++++++++-------- pkg/router/kubernetes.go | 12 ++++++------ pkg/router/kubernetes_test.go | 10 +++++----- pkg/router/router.go | 2 +- 9 files changed, 41 insertions(+), 41 deletions(-) diff --git a/pkg/controller/deployer.go b/pkg/controller/deployer.go index 1959f5d2..8bd0c80c 100644 --- a/pkg/controller/deployer.go +++ b/pkg/controller/deployer.go @@ -323,7 +323,7 @@ func (c *CanaryDeployer) Scale(cd *flaggerv1.Canary, replicas int32) error { return nil } -// Sync creates the primary deployment and hpa +// Reconcile creates the primary deployment and hpa // and scales to zero the canary deployment func (c *CanaryDeployer) Sync(cd *flaggerv1.Canary) error { primaryName := fmt.Sprintf("%s-primary", cd.Spec.TargetRef.Name) diff --git a/pkg/controller/scheduler.go b/pkg/controller/scheduler.go index 69f982cb..e277ed88 100644 --- a/pkg/controller/scheduler.go +++ b/pkg/controller/scheduler.go @@ -99,14 +99,14 @@ func (c *Controller) advanceCanary(name string, namespace string, skipLivenessCh routerFactory := router.NewFactory(c.kubeClient, c.flaggerClient, c.logger, c.istioClient) meshRouter := routerFactory.MeshRouter(c.meshProvider) - // create ClusterIP services and virtual service if needed - if err := routerFactory.KubernetesRouter().Sync(cd); err != nil { + // create or update ClusterIP services + if err := routerFactory.KubernetesRouter().Reconcile(cd); err != nil { c.recordEventWarningf(cd, "%v", err) return } // create or update virtual service - if err := meshRouter.Sync(cd); err != nil { + if err := meshRouter.Reconcile(cd); err != nil { c.recordEventWarningf(cd, "%v", err) return } diff --git a/pkg/router/appmesh.go b/pkg/router/appmesh.go index 92610674..027917d1 100644 --- a/pkg/router/appmesh.go +++ b/pkg/router/appmesh.go @@ -22,8 +22,8 @@ type AppMeshRouter struct { logger *zap.SugaredLogger } -// Sync creates or updates App Mesh virtual nodes and virtual services -func (ar *AppMeshRouter) Sync(canary *flaggerv1.Canary) error { +// Reconcile creates or updates App Mesh virtual nodes and virtual services +func (ar *AppMeshRouter) Reconcile(canary *flaggerv1.Canary) error { if canary.Spec.Service.MeshName == "" { return fmt.Errorf("mesh name cannot be empty") } @@ -37,28 +37,28 @@ func (ar *AppMeshRouter) Sync(canary *flaggerv1.Canary) error { // sync virtual node e.g. app-namespace // DNS app.namespace - err := ar.syncVirtualNode(canary, targetName, primaryHost) + err := ar.reconcileVirtualNode(canary, targetName, primaryHost) if err != nil { return err } // sync virtual node e.g. app-primary-namespace // DNS app-primary.namespace - err = ar.syncVirtualNode(canary, primaryName, primaryHost) + err = ar.reconcileVirtualNode(canary, primaryName, primaryHost) if err != nil { return err } // sync virtual node e.g. app-canary-namespace // DNS app-canary.namespace - err = ar.syncVirtualNode(canary, canaryName, canaryHost) + err = ar.reconcileVirtualNode(canary, canaryName, canaryHost) if err != nil { return err } // sync virtual service e.g. app.namespace // DNS app.namespace - err = ar.syncVirtualService(canary, targetHost) + err = ar.reconcileVirtualService(canary, targetHost) if err != nil { return err } @@ -66,9 +66,9 @@ func (ar *AppMeshRouter) Sync(canary *flaggerv1.Canary) error { return nil } -// syncVirtualNode creates or updates a virtual node +// reconcileVirtualNode creates or updates a virtual node // the virtual node naming format is name-role-namespace -func (ar *AppMeshRouter) syncVirtualNode(canary *flaggerv1.Canary, name string, host string) error { +func (ar *AppMeshRouter) reconcileVirtualNode(canary *flaggerv1.Canary, name string, host string) error { vnSpec := &appmeshv1alpha1.VirtualNodeSpec{ MeshName: canary.Spec.Service.MeshName, Listeners: []appmeshv1alpha1.Listener{ @@ -147,8 +147,8 @@ func (ar *AppMeshRouter) syncVirtualNode(canary *flaggerv1.Canary, name string, return nil } -// syncVirtualService creates or updates a virtual service -func (ar *AppMeshRouter) syncVirtualService(canary *flaggerv1.Canary, name string) error { +// reconcileVirtualService creates or updates a virtual service +func (ar *AppMeshRouter) reconcileVirtualService(canary *flaggerv1.Canary, name string) error { targetName := canary.Spec.TargetRef.Name canaryVirtualNode := fmt.Sprintf("%s-canary", targetName) primaryVirtualNode := fmt.Sprintf("%s-primary", targetName) diff --git a/pkg/router/appmesh_test.go b/pkg/router/appmesh_test.go index 8f7a20d1..756a77f1 100644 --- a/pkg/router/appmesh_test.go +++ b/pkg/router/appmesh_test.go @@ -15,7 +15,7 @@ func TestAppmeshRouter_Sync(t *testing.T) { kubeClient: mocks.kubeClient, } - err := router.Sync(mocks.appmeshCanary) + err := router.Reconcile(mocks.appmeshCanary) if err != nil { t.Fatal(err.Error()) } @@ -66,7 +66,7 @@ func TestAppmeshRouter_Sync(t *testing.T) { } // apply change - err = router.Sync(canary) + err = router.Reconcile(canary) if err != nil { t.Fatal(err.Error()) } @@ -92,7 +92,7 @@ func TestAppmeshRouter_Sync(t *testing.T) { } // apply change - err = router.Sync(canary) + err = router.Reconcile(canary) if err != nil { t.Fatal(err.Error()) } @@ -115,7 +115,7 @@ func TestAppmeshRouter_Sync(t *testing.T) { } // apply change - err = router.Sync(canary) + err = router.Reconcile(canary) if err != nil { t.Fatal(err.Error()) } @@ -139,7 +139,7 @@ func TestAppmeshRouter_GetSetRoutes(t *testing.T) { kubeClient: mocks.kubeClient, } - err := router.Sync(mocks.appmeshCanary) + err := router.Reconcile(mocks.appmeshCanary) if err != nil { t.Fatal(err.Error()) } diff --git a/pkg/router/istio.go b/pkg/router/istio.go index a1415809..b65bae7a 100644 --- a/pkg/router/istio.go +++ b/pkg/router/istio.go @@ -23,8 +23,8 @@ type IstioRouter struct { logger *zap.SugaredLogger } -// Sync creates or updates the Istio virtual service -func (ir *IstioRouter) Sync(canary *flaggerv1.Canary) error { +// Reconcile creates or updates the Istio virtual service +func (ir *IstioRouter) Reconcile(canary *flaggerv1.Canary) error { targetName := canary.Spec.TargetRef.Name primaryName := fmt.Sprintf("%s-primary", targetName) diff --git a/pkg/router/istio_test.go b/pkg/router/istio_test.go index de3b332b..3d7b4214 100644 --- a/pkg/router/istio_test.go +++ b/pkg/router/istio_test.go @@ -16,7 +16,7 @@ func TestIstioRouter_Sync(t *testing.T) { kubeClient: mocks.kubeClient, } - err := router.Sync(mocks.canary) + err := router.Reconcile(mocks.canary) if err != nil { t.Fatal(err.Error()) } @@ -51,7 +51,7 @@ func TestIstioRouter_Sync(t *testing.T) { } // apply change - err = router.Sync(canary) + err = router.Reconcile(canary) if err != nil { t.Fatal(err.Error()) } @@ -80,7 +80,7 @@ func TestIstioRouter_Sync(t *testing.T) { } // undo change - err = router.Sync(mocks.canary) + err = router.Reconcile(mocks.canary) if err != nil { t.Fatal(err.Error()) } @@ -104,7 +104,7 @@ func TestIstioRouter_SetRoutes(t *testing.T) { kubeClient: mocks.kubeClient, } - err := router.Sync(mocks.canary) + err := router.Reconcile(mocks.canary) if err != nil { t.Fatal(err.Error()) } @@ -159,7 +159,7 @@ func TestIstioRouter_GetRoutes(t *testing.T) { kubeClient: mocks.kubeClient, } - err := router.Sync(mocks.canary) + err := router.Reconcile(mocks.canary) if err != nil { t.Fatal(err.Error()) } @@ -187,7 +187,7 @@ func TestIstioRouter_HTTPRequestHeaders(t *testing.T) { kubeClient: mocks.kubeClient, } - err := router.Sync(mocks.canary) + err := router.Reconcile(mocks.canary) if err != nil { t.Fatal(err.Error()) } @@ -216,7 +216,7 @@ func TestIstioRouter_CORS(t *testing.T) { kubeClient: mocks.kubeClient, } - err := router.Sync(mocks.canary) + err := router.Reconcile(mocks.canary) if err != nil { t.Fatal(err.Error()) } @@ -249,7 +249,7 @@ func TestIstioRouter_ABTest(t *testing.T) { kubeClient: mocks.kubeClient, } - err := router.Sync(mocks.abtest) + err := router.Reconcile(mocks.abtest) if err != nil { t.Fatal(err.Error()) } diff --git a/pkg/router/kubernetes.go b/pkg/router/kubernetes.go index c2e3f76d..38d6165b 100644 --- a/pkg/router/kubernetes.go +++ b/pkg/router/kubernetes.go @@ -21,26 +21,26 @@ type KubernetesRouter struct { logger *zap.SugaredLogger } -// Sync creates or updates the primary and canary services -func (c *KubernetesRouter) Sync(canary *flaggerv1.Canary) error { +// Reconcile creates or updates the primary and canary services +func (c *KubernetesRouter) Reconcile(canary *flaggerv1.Canary) error { targetName := canary.Spec.TargetRef.Name primaryName := fmt.Sprintf("%s-primary", targetName) canaryName := fmt.Sprintf("%s-canary", targetName) // main svc - err := c.syncService(canary, targetName, primaryName) + err := c.reconcileService(canary, targetName, primaryName) if err != nil { return err } // canary svc - err = c.syncService(canary, canaryName, targetName) + err = c.reconcileService(canary, canaryName, targetName) if err != nil { return err } // primary svc - err = c.syncService(canary, primaryName, primaryName) + err = c.reconcileService(canary, primaryName, primaryName) if err != nil { return err } @@ -56,7 +56,7 @@ func (c *KubernetesRouter) GetRoutes(canary *flaggerv1.Canary) (primaryRoute int return 0, 0, nil } -func (c *KubernetesRouter) syncService(canary *flaggerv1.Canary, name string, target string) error { +func (c *KubernetesRouter) reconcileService(canary *flaggerv1.Canary, name string, target string) error { portName := canary.Spec.Service.PortName if portName == "" { portName = "http" diff --git a/pkg/router/kubernetes_test.go b/pkg/router/kubernetes_test.go index 77469f0c..94588e37 100644 --- a/pkg/router/kubernetes_test.go +++ b/pkg/router/kubernetes_test.go @@ -13,7 +13,7 @@ func TestServiceRouter_Create(t *testing.T) { logger: mocks.logger, } - err := router.Sync(mocks.canary) + err := router.Reconcile(mocks.canary) if err != nil { t.Fatal(err.Error()) } @@ -53,7 +53,7 @@ func TestServiceRouter_Update(t *testing.T) { logger: mocks.logger, } - err := router.Sync(mocks.canary) + err := router.Reconcile(mocks.canary) if err != nil { t.Fatal(err.Error()) } @@ -72,7 +72,7 @@ func TestServiceRouter_Update(t *testing.T) { } // apply changes - err = router.Sync(c) + err = router.Reconcile(c) if err != nil { t.Fatal(err.Error()) } @@ -95,7 +95,7 @@ func TestServiceRouter_Undo(t *testing.T) { logger: mocks.logger, } - err := router.Sync(mocks.canary) + err := router.Reconcile(mocks.canary) if err != nil { t.Fatal(err.Error()) } @@ -115,7 +115,7 @@ func TestServiceRouter_Undo(t *testing.T) { } // undo changes - err = router.Sync(mocks.canary) + err = router.Reconcile(mocks.canary) if err != nil { t.Fatal(err.Error()) } diff --git a/pkg/router/router.go b/pkg/router/router.go index 0c81eaa5..1729b3a2 100644 --- a/pkg/router/router.go +++ b/pkg/router/router.go @@ -3,7 +3,7 @@ package router import flaggerv1 "github.com/weaveworks/flagger/pkg/apis/flagger/v1alpha3" type Interface interface { - Sync(canary *flaggerv1.Canary) error + Reconcile(canary *flaggerv1.Canary) error SetRoutes(canary *flaggerv1.Canary, primaryWeight int, canaryWeight int) error GetRoutes(canary *flaggerv1.Canary) (primaryWeight int, canaryWeight int, err error) }