From 6aacbfa23dd0a8c12c2738578d1edd08a403e488 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Wed, 24 Feb 2021 15:31:44 -0800 Subject: [PATCH 1/6] Set label name to app over name --- builtin/k8s/deployment.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/k8s/deployment.go b/builtin/k8s/deployment.go index 968188fc593..25a7be0b21a 100644 --- a/builtin/k8s/deployment.go +++ b/builtin/k8s/deployment.go @@ -24,14 +24,14 @@ func (d *Deployment) newDeployment(name string) *appsv1.Deployment { Spec: appsv1.DeploymentSpec{ Selector: &metav1.LabelSelector{ MatchLabels: map[string]string{ - "name": name, + "app": name, }, }, Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - "name": name, + "app": name, }, Annotations: map[string]string{}, From b10d105709fdac6e1212d42a89f9a5051de19378 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Wed, 24 Feb 2021 15:32:46 -0800 Subject: [PATCH 2/6] Include user defined labels for deployment pod --- builtin/k8s/platform.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/builtin/k8s/platform.go b/builtin/k8s/platform.go index 8d1299c69be..c2a30f188e1 100644 --- a/builtin/k8s/platform.go +++ b/builtin/k8s/platform.go @@ -183,6 +183,11 @@ func (p *Platform) Deploy( // to route to multiple versions during release management. deployment.Spec.Template.Labels[labelId] = result.Id + // Apply user defined labels + for k, v := range p.config.Labels { + deployment.Spec.Template.Labels[k] = v + } + // If the user is using the latest tag, then don't specify an overriding pull policy. // This by default means kubernetes will always pull so that latest is useful. pullPolicy := corev1.PullIfNotPresent @@ -524,6 +529,9 @@ type Config struct { // blank then we default to the home directory. KubeconfigPath string `hcl:"kubeconfig,optional"` + // A map of key vals to label the deployed Pod and Deployment with. + Labels map[string]string `hcl:"labels,optional"` + // Namespace is the Kubernetes namespace to target the deployment to. Namespace string `hcl:"namespace,optional"` From f049fb12534272bc27c01abbcc5e70910cf59221 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Wed, 24 Feb 2021 15:35:45 -0800 Subject: [PATCH 3/6] Add labels docs for k8s platform --- builtin/k8s/platform.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/builtin/k8s/platform.go b/builtin/k8s/platform.go index c2a30f188e1..f59a8770a68 100644 --- a/builtin/k8s/platform.go +++ b/builtin/k8s/platform.go @@ -689,6 +689,11 @@ deploy "kubernetes" { ), ) + doc.SetField( + "labels", + "a map of key value labels to apply to the deployment pod", + ) + doc.SetField( "namespace", "namespace to target deployment into", From 64b75b0fce5e7d1acc41da266ed3b13de7a121cc Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Thu, 25 Feb 2021 09:07:33 -0800 Subject: [PATCH 4/6] Include version label in pod deploy labels --- builtin/k8s/platform.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/builtin/k8s/platform.go b/builtin/k8s/platform.go index f59a8770a68..4d4064ed7ee 100644 --- a/builtin/k8s/platform.go +++ b/builtin/k8s/platform.go @@ -182,6 +182,9 @@ func (p *Platform) Deploy( // Set our ID on the label. We use this ID so that we can have a key // to route to multiple versions during release management. deployment.Spec.Template.Labels[labelId] = result.Id + // Version label duplicates "labelId" to support services like Istio that + // expect pods to be labled with 'version' + deployment.Spec.Template.Labels["version"] = result.Id // Apply user defined labels for k, v := range p.config.Labels { From fb82ed287ae56afb825b376caccccebec2461895 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Thu, 25 Feb 2021 09:59:26 -0800 Subject: [PATCH 5/6] Add back name for local release URL --- builtin/k8s/deployment.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/builtin/k8s/deployment.go b/builtin/k8s/deployment.go index 25a7be0b21a..759b95213b7 100644 --- a/builtin/k8s/deployment.go +++ b/builtin/k8s/deployment.go @@ -24,14 +24,16 @@ func (d *Deployment) newDeployment(name string) *appsv1.Deployment { Spec: appsv1.DeploymentSpec{ Selector: &metav1.LabelSelector{ MatchLabels: map[string]string{ - "app": name, + "app": name, + "name": name, }, }, Template: corev1.PodTemplateSpec{ ObjectMeta: metav1.ObjectMeta{ Labels: map[string]string{ - "app": name, + "app": name, + "name": name, }, Annotations: map[string]string{}, From 2c47693f34f4520ae54c90d4df50e299c3b201c9 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Thu, 25 Feb 2021 10:20:47 -0800 Subject: [PATCH 6/6] Add note about app and name labels for k8s deployment --- builtin/k8s/deployment.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/builtin/k8s/deployment.go b/builtin/k8s/deployment.go index 759b95213b7..f7d9eb10f44 100644 --- a/builtin/k8s/deployment.go +++ b/builtin/k8s/deployment.go @@ -21,6 +21,8 @@ func (d *Deployment) newDeployment(name string) *appsv1.Deployment { Name: name, }, + // Note both name and app are included here. 'app' is expected for certain + // k8s integrations, where as waypoint expepcts 'name' else where for release Spec: appsv1.DeploymentSpec{ Selector: &metav1.LabelSelector{ MatchLabels: map[string]string{