Skip to content

Commit

Permalink
Merge pull request #75 from TRReeve/pull-request-74
Browse files Browse the repository at this point in the history
Surfacing Additional Pod Labels for user
  • Loading branch information
yorinasub17 authored Sep 8, 2020
2 parents df9b0f8 + 5c1441e commit aa0c0ba
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
7 changes: 6 additions & 1 deletion charts/k8s-service/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ metadata:
app.kubernetes.io/name: {{ include "k8s-service.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- range $key, $value := .Values.additionalDeploymentLabels }}
{{ $key }}: {{ $value }}
{{- end}}
{{- with .Values.deploymentAnnotations }}
annotations:
{{ toYaml . | indent 4 }}
Expand All @@ -86,7 +89,9 @@ spec:
app.kubernetes.io/name: {{ include "k8s-service.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
gruntwork.io/deployment-type: main

{{- range $key, $value := .Values.additionalPodLabels }}
{{ $key }}: {{ $value }}
{{- end }}
{{- with .Values.podAnnotations }}
annotations:
{{ toYaml . | indent 8 }}
Expand Down
13 changes: 13 additions & 0 deletions charts/k8s-service/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,24 @@ replicaCount: 1
# NOTE: This variable is injected directly into the deployment spec.
deploymentAnnotations: {}

# additionalDeploymentLabels will add the provided map to the labels for the Deployment resource created by this chart.
# this is in addition to the helm template related labels created by the chart
# The keys and values are free form, but subject to the limitations of Kubernetes labelling.
# NOTE: This variable is injected directly into the deployment spec.
additionalDeploymentLabels: {}

# podAnnotations will add the provided map to the annotations for the Pod resource created by the Deployment.
# The keys and values are free form, but subject to the limitations of Kubernetes resource annotations.
# NOTE: This variable is injected directly into the pod spec.
podAnnotations: {}

# additionalDeploymentLabels will add the provided map to the labels for the Pods created by the deployment resource.
# this is in addition to the helm template related labels created by the chart
# The keys and values are free form, but subject to the limitations of Kubernetes labelling.
# The match labels for the deployment aren't affected by these additional labels
# NOTE: This variable is injected directly into the deployment spec.
additionalPodLabels: {}

# minPodsAvailable specifies the minimum number of pods that should be available at any given point in time. This is
# used to configure a PodDisruptionBudget for the included pod. See
# https://blog.gruntwork.io/avoiding-outages-in-your-kubernetes-cluster-using-poddisruptionbudgets-ef6a4baa5085
Expand Down
25 changes: 25 additions & 0 deletions test/k8s_service_template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,3 +715,28 @@ func TestK8SServiceMainDeploymentContainersLabeledCorrectly(t *testing.T) {
// Ensure a "main" type deployment is properly labeled as such
assert.Equal(t, deployment.Spec.Selector.MatchLabels["gruntwork.io/deployment-type"], "main")
}

func TestK8SServiceDeploymentAddingAdditionalLabels(t *testing.T) {
t.Parallel()
first_custom_deployment_label_value := "first-custom-value"
second_custom_deployment_label_value := "second-custom-value"
deployment := renderK8SServiceDeploymentWithSetValues(t,
map[string]string{"additionalDeploymentLabels.first-label": first_custom_deployment_label_value,
"additionalDeploymentLabels.second-label":second_custom_deployment_label_value})

assert.Equal(t, deployment.Labels["first-label"], first_custom_deployment_label_value)
assert.Equal(t, deployment.Labels["second-label"], second_custom_deployment_label_value)
}

func TestK8SServicePodAddingAdditionalLabels(t *testing.T) {
t.Parallel()
first_custom_pod_label_value := "first-custom-value"
second_custom_pod_label_value := "second-custom-value"
deployment := renderK8SServiceDeploymentWithSetValues(t,
map[string]string{"additionalPodLabels.first-label": first_custom_pod_label_value,
"additionalPodLabels.second-label": second_custom_pod_label_value})

assert.Equal(t, deployment.Spec.Template.Labels["first-label"], first_custom_pod_label_value)
assert.Equal(t, deployment.Spec.Template.Labels["second-label"], second_custom_pod_label_value)
}

0 comments on commit aa0c0ba

Please sign in to comment.