Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

builtin/k8s: Include user defined labels on deploy and add name/version labels #1146

Merged
merged 6 commits into from
Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions builtin/k8s/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@ 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{
"app": name,
"name": name,
},
},

Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app": name,
"name": name,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure where this is happening exactly, but it seems like we use name some where for the local release URL to resolve so maybe we leave this as is and include app too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a reasonable decision. I would add a comment to that effect for future-us.

},

Expand Down
16 changes: 16 additions & 0 deletions builtin/k8s/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ 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 {
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.
Expand Down Expand Up @@ -524,6 +532,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"`

Expand Down Expand Up @@ -681,6 +692,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",
Expand Down