Skip to content

Commit 437b1d3

Browse files
committed
Copy labels from canary to primary
1 parent ba1788c commit 437b1d3

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

pkg/controller/deployer.go

+16-1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ func (c *CanaryDeployer) Promote(cd *flaggerv1.Canary) error {
7777
}
7878
primaryCopy.Spec.Template.Annotations = annotations
7979

80+
primaryCopy.Spec.Template.Labels = makePrimaryLabels(canary.Spec.Template.Labels, primaryName)
81+
8082
_, err = c.kubeClient.AppsV1().Deployments(cd.Namespace).Update(primaryCopy)
8183
if err != nil {
8284
return fmt.Errorf("updating deployment %s.%s template spec failed: %v",
@@ -403,7 +405,7 @@ func (c *CanaryDeployer) createPrimaryDeployment(cd *flaggerv1.Canary) error {
403405
},
404406
Template: corev1.PodTemplateSpec{
405407
ObjectMeta: metav1.ObjectMeta{
406-
Labels: map[string]string{"app": primaryName},
408+
Labels: makePrimaryLabels(canaryDep.Spec.Template.Labels, primaryName),
407409
Annotations: annotations,
408410
},
409411
// update spec with the primary secrets and config maps
@@ -544,3 +546,16 @@ func (c *CanaryDeployer) makeAnnotations(annotations map[string]string) (map[str
544546

545547
return res, nil
546548
}
549+
550+
func makePrimaryLabels(labels map[string]string, primaryName string) map[string]string {
551+
idKey := "app"
552+
res := make(map[string]string)
553+
for k, v := range labels {
554+
if k != idKey {
555+
res[k] = v
556+
}
557+
}
558+
res[idKey] = primaryName
559+
560+
return res
561+
}

0 commit comments

Comments
 (0)