Skip to content

Commit

Permalink
Merge pull request #105 from stefanprodan/svc
Browse files Browse the repository at this point in the history
 Copy pod labels from canary to primary
  • Loading branch information
stefanprodan authored Mar 13, 2019
2 parents 773094a + 437b1d3 commit ed2048e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 14 deletions.
8 changes: 1 addition & 7 deletions artifacts/workloads/canary-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -67,9 +67,3 @@ spec:
requests:
cpu: 100m
memory: 16Mi
volumeMounts:
- mountPath: /data
name: data
volumes:
- emptyDir: {}
name: data
4 changes: 1 addition & 3 deletions artifacts/workloads/canary-service.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
apiVersion: v1
kind: Service
metadata:
name: podinfo
name: podinfo-canary
namespace: test
labels:
app: podinfo
spec:
type: ClusterIP
selector:
Expand Down
2 changes: 1 addition & 1 deletion artifacts/workloads/primary-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions artifacts/workloads/service.yaml
Original file line number Diff line number Diff line change
@@ -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
17 changes: 16 additions & 1 deletion pkg/controller/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions pkg/router/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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",
Expand Down

0 comments on commit ed2048e

Please sign in to comment.