Skip to content

Commit

Permalink
Rename router sync to reconcile
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanprodan committed Mar 26, 2019
1 parent ddd3a82 commit ca074ef
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
20 changes: 10 additions & 10 deletions pkg/router/appmesh.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -37,38 +37,38 @@ 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
}

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{
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions pkg/router/appmesh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down Expand Up @@ -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())
}
Expand All @@ -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())
}
Expand All @@ -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())
}
Expand All @@ -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())
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/router/istio.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
16 changes: 8 additions & 8 deletions pkg/router/istio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down Expand Up @@ -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())
}
Expand Down Expand Up @@ -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())
}
Expand All @@ -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())
}
Expand Down Expand Up @@ -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())
}
Expand Down Expand Up @@ -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())
}
Expand Down Expand Up @@ -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())
}
Expand Down Expand Up @@ -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())
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/router/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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"
Expand Down
10 changes: 5 additions & 5 deletions pkg/router/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down Expand Up @@ -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())
}
Expand All @@ -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())
}
Expand All @@ -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())
}
Expand All @@ -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())
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit ca074ef

Please sign in to comment.