diff --git a/artifacts/workloads/canary-deployment.yaml b/artifacts/workloads/canary-deployment.yaml index 75ee7cbcf..814dd9c2f 100644 --- a/artifacts/workloads/canary-deployment.yaml +++ b/artifacts/workloads/canary-deployment.yaml @@ -23,7 +23,7 @@ spec: spec: containers: - name: podinfod - image: quay.io/stefanprodan/podinfo:1.2.0 + image: quay.io/stefanprodan/podinfo:1.4.0 imagePullPolicy: IfNotPresent ports: - containerPort: 9898 @@ -67,9 +67,3 @@ spec: requests: cpu: 100m memory: 16Mi - volumeMounts: - - mountPath: /data - name: data - volumes: - - emptyDir: {} - name: data diff --git a/artifacts/workloads/canary-service.yaml b/artifacts/workloads/canary-service.yaml index e858e3a58..7a09e206c 100644 --- a/artifacts/workloads/canary-service.yaml +++ b/artifacts/workloads/canary-service.yaml @@ -1,10 +1,8 @@ apiVersion: v1 kind: Service metadata: - name: podinfo + name: podinfo-canary namespace: test - labels: - app: podinfo spec: type: ClusterIP selector: diff --git a/artifacts/workloads/primary-deployment.yaml b/artifacts/workloads/primary-deployment.yaml index f27fa9b78..cc17b82fa 100644 --- a/artifacts/workloads/primary-deployment.yaml +++ b/artifacts/workloads/primary-deployment.yaml @@ -23,7 +23,7 @@ spec: spec: containers: - name: podinfod - image: quay.io/stefanprodan/podinfo:1.1.1 + image: quay.io/stefanprodan/podinfo:1.4.1 imagePullPolicy: IfNotPresent ports: - containerPort: 9898 diff --git a/artifacts/workloads/service.yaml b/artifacts/workloads/service.yaml new file mode 100644 index 000000000..3e98f1e07 --- /dev/null +++ b/artifacts/workloads/service.yaml @@ -0,0 +1,14 @@ +apiVersion: v1 +kind: Service +metadata: + name: podinfo + namespace: test +spec: + type: ClusterIP + selector: + app: podinfo-primary + ports: + - name: http + port: 9898 + protocol: TCP + targetPort: http diff --git a/pkg/controller/deployer.go b/pkg/controller/deployer.go index 6b7555b09..80b211bb9 100644 --- a/pkg/controller/deployer.go +++ b/pkg/controller/deployer.go @@ -77,6 +77,8 @@ func (c *CanaryDeployer) Promote(cd *flaggerv1.Canary) error { } primaryCopy.Spec.Template.Annotations = annotations + primaryCopy.Spec.Template.Labels = makePrimaryLabels(canary.Spec.Template.Labels, primaryName) + _, err = c.kubeClient.AppsV1().Deployments(cd.Namespace).Update(primaryCopy) if err != nil { return fmt.Errorf("updating deployment %s.%s template spec failed: %v", @@ -403,7 +405,7 @@ func (c *CanaryDeployer) createPrimaryDeployment(cd *flaggerv1.Canary) error { }, Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ - Labels: map[string]string{"app": primaryName}, + Labels: makePrimaryLabels(canaryDep.Spec.Template.Labels, primaryName), Annotations: annotations, }, // update spec with the primary secrets and config maps @@ -544,3 +546,16 @@ func (c *CanaryDeployer) makeAnnotations(annotations map[string]string) (map[str return res, nil } + +func makePrimaryLabels(labels map[string]string, primaryName string) map[string]string { + idKey := "app" + res := make(map[string]string) + for k, v := range labels { + if k != idKey { + res[k] = v + } + } + res[idKey] = primaryName + + return res +} diff --git a/pkg/router/kubernetes.go b/pkg/router/kubernetes.go index 5e86e20f7..05681458e 100644 --- a/pkg/router/kubernetes.go +++ b/pkg/router/kubernetes.go @@ -20,7 +20,7 @@ type KubernetesRouter struct { logger *zap.SugaredLogger } -// Sync creates to updates the primary and canary services +// Sync creates or updates the primary and canary services func (c *KubernetesRouter) Sync(cd *flaggerv1.Canary) error { targetName := cd.Spec.TargetRef.Name primaryName := fmt.Sprintf("%s-primary", targetName) @@ -40,7 +40,7 @@ func (c *KubernetesRouter) Sync(cd *flaggerv1.Canary) error { }, Spec: corev1.ServiceSpec{ Type: corev1.ServiceTypeClusterIP, - Selector: map[string]string{"app": targetName}, + Selector: map[string]string{"app": primaryName}, Ports: []corev1.ServicePort{ { Name: "http",