diff --git a/README.md b/README.md index 52a519b1..75ab66e9 100644 --- a/README.md +++ b/README.md @@ -180,6 +180,7 @@ Create a deployment and a horizontal pod autoscaler: kubectl apply -f ${REPO}/artifacts/canaries/deployment.yaml kubectl apply -f ${REPO}/artifacts/canaries/hpa.yaml ``` + Create a canary promotion custom resource (replace the Istio gateway and the internet domain with your own): ```bash diff --git a/pkg/controller/deployer_test.go b/pkg/controller/deployer_test.go index 693c2cfc..0b01a544 100644 --- a/pkg/controller/deployer_test.go +++ b/pkg/controller/deployer_test.go @@ -214,3 +214,48 @@ func TestCanaryDeployer_Sync(t *testing.T) { t.Errorf("Got HPA target %s wanted %s", hpaPrimary.Spec.ScaleTargetRef.Name, depPrimary.Name) } } + +func TestCanaryDeployer_Promote(t *testing.T) { + canary := newTestCanary() + dep := newTestDeployment() + dep2 := newTestDeploymentUpdated() + + hpa := newTestHPA() + + flaggerClient := fakeFlagger.NewSimpleClientset(canary) + + kubeClient := fake.NewSimpleClientset(dep, hpa) + + logger, _ := logging.NewLogger("debug") + deployer := &CanaryDeployer{ + flaggerClient: flaggerClient, + kubeClient: kubeClient, + logger: logger, + } + + err := deployer.Sync(canary) + if err != nil { + t.Fatal(err.Error()) + } + + _, err = kubeClient.AppsV1().Deployments("default").Update(dep2) + if err != nil { + t.Fatal(err.Error()) + } + + err = deployer.Promote(canary) + if err != nil { + t.Fatal(err.Error()) + } + + depPrimary, err := kubeClient.AppsV1().Deployments("default").Get("podinfo-primary", metav1.GetOptions{}) + if err != nil { + t.Fatal(err.Error()) + } + + primaryImage := depPrimary.Spec.Template.Spec.Containers[0].Image + sourceImage := dep2.Spec.Template.Spec.Containers[0].Image + if primaryImage != sourceImage { + t.Errorf("Got image %s wanted %s", primaryImage, sourceImage) + } +}