Skip to content

Commit ed2048e

Browse files
authored
Merge pull request #105 from stefanprodan/svc
Copy pod labels from canary to primary
2 parents 773094a + 437b1d3 commit ed2048e

File tree

6 files changed

+35
-14
lines changed

6 files changed

+35
-14
lines changed

artifacts/workloads/canary-deployment.yaml

+1-7
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ spec:
2323
spec:
2424
containers:
2525
- name: podinfod
26-
image: quay.io/stefanprodan/podinfo:1.2.0
26+
image: quay.io/stefanprodan/podinfo:1.4.0
2727
imagePullPolicy: IfNotPresent
2828
ports:
2929
- containerPort: 9898
@@ -67,9 +67,3 @@ spec:
6767
requests:
6868
cpu: 100m
6969
memory: 16Mi
70-
volumeMounts:
71-
- mountPath: /data
72-
name: data
73-
volumes:
74-
- emptyDir: {}
75-
name: data

artifacts/workloads/canary-service.yaml

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
apiVersion: v1
22
kind: Service
33
metadata:
4-
name: podinfo
4+
name: podinfo-canary
55
namespace: test
6-
labels:
7-
app: podinfo
86
spec:
97
type: ClusterIP
108
selector:

artifacts/workloads/primary-deployment.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ spec:
2323
spec:
2424
containers:
2525
- name: podinfod
26-
image: quay.io/stefanprodan/podinfo:1.1.1
26+
image: quay.io/stefanprodan/podinfo:1.4.1
2727
imagePullPolicy: IfNotPresent
2828
ports:
2929
- containerPort: 9898

artifacts/workloads/service.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: podinfo
5+
namespace: test
6+
spec:
7+
type: ClusterIP
8+
selector:
9+
app: podinfo-primary
10+
ports:
11+
- name: http
12+
port: 9898
13+
protocol: TCP
14+
targetPort: http

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+
}

pkg/router/kubernetes.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type KubernetesRouter struct {
2020
logger *zap.SugaredLogger
2121
}
2222

23-
// Sync creates to updates the primary and canary services
23+
// Sync creates or updates the primary and canary services
2424
func (c *KubernetesRouter) Sync(cd *flaggerv1.Canary) error {
2525
targetName := cd.Spec.TargetRef.Name
2626
primaryName := fmt.Sprintf("%s-primary", targetName)
@@ -40,7 +40,7 @@ func (c *KubernetesRouter) Sync(cd *flaggerv1.Canary) error {
4040
},
4141
Spec: corev1.ServiceSpec{
4242
Type: corev1.ServiceTypeClusterIP,
43-
Selector: map[string]string{"app": targetName},
43+
Selector: map[string]string{"app": primaryName},
4444
Ports: []corev1.ServicePort{
4545
{
4646
Name: "http",

0 commit comments

Comments
 (0)