Rename router sync to reconcile

This commit is contained in:
stefanprodan
2019-03-26 17:12:46 +02:00
parent ddd3a8251e
commit ca074ef13f
9 changed files with 41 additions and 41 deletions
+1 -1
View File
@@ -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)
+3 -3
View File
@@ -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
}
+10 -10
View File
@@ -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)
+5 -5
View File
@@ -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())
}
+2 -2
View File
@@ -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)
+8 -8
View File
@@ -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())
}
+6 -6
View File
@@ -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"
+5 -5
View File
@@ -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())
}
+1 -1
View File
@@ -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)
}