Repository: linkerd/linkerd2
Pull request #5056 (2020-10-08 23:50:48)

Add podLabels and podAnnotations to Values struct
PR https://github.com/linkerd/linkerd2/pull/5027 added `podLabels` and `podAnnotations` to `values.yaml` to allow setting labels and annotations on pods in the Helm template.  However, these fields were not added to the `Values` struct in `Values.go`.  This means that these fields were not serialized out to the `linkerd-config` or to the `linkerd-config-overrides`.  Furthermore, in PR #5005 which moves to using the `Values` struct more authoritatively, the `podLabels` and `podAnnotations` fields would not take effect at all.

Add these fields to the `Values` struct and update all test fixtures accordingly.

Signed-off-by: Alex Leong <alex@buoyant.io>

<!--  Thanks for sending a pull request!

If you already have a well-structured git commit message, chances are GitHub
set the title and description of this PR to the git commit message subject and
body, respectively. If so, you may delete these instructions and submit your PR.

If this is your first time, please read our contributor guide:
https://github.com/linkerd/linkerd2/blob/main/CONTRIBUTING.md

The title and description of your Pull Request should match the git commit
subject and body, respectively. Git commit messages are structured as follows:

```
Subject

Problem

Solution

Validation

Fixes #[GitHub issue ID]

DCO Sign off
```

Example git commit message:

```
Introduce Pull Request Template

GitHub's community guidelines recommend a pull request template, the repo was
lacking one.

Introduce a `PULL_REQUEST_TEMPLATE.md` file.

Once merged, the
[Community profile checklist](https://github.com/linkerd/linkerd2/community)
should indicate the repo now provides a pull request template.

Fixes #3321

Signed-off-by: Jane Smith <jane.smith@example.com>
```

Note the git commit message subject becomes the pull request title.

For more details around git commits, see the section on Committing in our
contributor guide:
https://github.com/linkerd/linkerd2/blob/main/CONTRIBUTING.md#committing
-->



Patch:
diff --git a/pkg/charts/linkerd2/values.go b/pkg/charts/linkerd2/values.go
index 279f16c14..461046049 100644
--- a/pkg/charts/linkerd2/values.go
+++ b/pkg/charts/linkerd2/values.go
@@ -94,6 +94,9 @@ type (
 		ImagePullSecrets         []map[string]string `json:"imagePullSecrets"`
 		LinkerdVersion           string              `json:"linkerdVersion"`
 
+		PodAnnotations map[string]string `json:"podAnnotations"`
+		PodLabels      map[string]string `json:"podLabels"`
+
 		Proxy     *Proxy     `json:"proxy"`
 		ProxyInit *ProxyInit `json:"proxyInit"`
 	}


Test patch:
diff --git a/bin/_test-helpers.sh b/bin/_test-helpers.sh
index 73eeeea21..f4fca770f 100644
--- a/bin/_test-helpers.sh
+++ b/bin/_test-helpers.sh
@@ -9,80 +9,101 @@ set +e
 export default_test_names=(deep external-issuer helm-deep helm-upgrade multicluster uninstall upgrade-edge upgrade-stable cni-calico-deep)
 export all_test_names=(cluster-domain "${default_test_names[*]}")
 
-handle_input() {
-  export images="docker"
-  export test_name=''
-  export skip_cluster_create=''
-
-  while :
-  do
-    case $1 in
-      -h|--help)
-        echo "Run Linkerd integration tests.
+usage() {
+  progname="${0##*/}"
+  echo "Run Linkerd integration tests.
 
 Optionally specify a test with the --name flag: [${all_test_names[*]}]
 
 Note: The cluster-domain test requires a cluster configuration with a custom cluster domain (see test/configs/cluster-domain.yaml)
 
 Usage:
-    ${0##*/} [--images docker|archive|skip] [--name test-name] [--skip-cluster-create] /path/to/linkerd
+    ${progname} [--images docker|archive|skip] [--name test-name] [--skip-cluster-create] /path/to/linkerd
 
 Examples:
     # Run all tests in isolated clusters
-    ${0##*/} /path/to/linkerd
+    ${progname} /path/to/linkerd
 
     # Run single test in isolated clusters
-    ${0##*/} --name test-name /path/to/linkerd
+    ${progname} --name test-name /path/to/linkerd
 
     # Skip KinD/k3d cluster creation and run all tests in default cluster context
-    ${0##*/} --skip-cluster-create /path/to/linkerd
+    ${progname} --skip-cluster-create /path/to/linkerd
 
     # Load images from tar files located under the 'image-archives' directory
     # Note: This is primarily for CI
-    ${0##*/} --images archive /path/to/linkerd
+    ${progname} --images archive /path/to/linkerd
 
 Available Commands:
     --name: the argument to this option is the specific test to run
     --skip-cluster-create: skip KinD/k3d cluster creation step and run tests in an existing cluster.
     --images: by default load images into the cluster from the local docker cache (docker), or from tar files located under the 'image-archives' directory (archive), or completely skip image loading (skip)."
+}
+
+
+handle_input() {
+  export images="docker"
+  export test_name=''
+  export skip_cluster_create=''
+  export linkerd_path=""
+
+  while  [ "$#" -ne 0 ]; do
+    case $1 in
+      -h|--help)
+        usage "$0"
         exit 0
         ;;
       --images)
         images=$2
         if [ -z "$images" ]; then
-          echo 'Error: the argument for --images was not specified'
-          exit 1
+          echo 'Error: the argument for --images was not specified' >&2
+          usage "$0" >&2
+          exit 64
         fi
         if [[ $images != "docker" && $images != "archive" && $images != "skip" ]]; then
-          echo 'Error: the argument for --images was invalid'
-          exit 1
+          echo 'Error: the argument for --images was invalid' >&2
+          usage "$0" >&2
+          exit 64
         fi
         shift
+        shift
         ;;
       --name)
         test_name=$2
         if [ -z "$test_name" ]; then
-          echo 'Error: the argument for --name was not specified'
-          exit 1
+          echo 'Error: the argument for --name was not specified' >&2
+          usage "$0" >&2
+          exit 64
         fi
         shift
+        shift
         ;;
       --skip-cluster-create)
         skip_cluster_create=1
+        shift
         ;;
       *)
-        break
+        if echo "$1" | grep -q '^-.*' ; then
+          echo "Unexpected flag: $1" >&2
+          usage "$0" >&2
+          exit 64
+        fi
+        if [ -n "$linkerd_path" ]; then
+          echo "Multliple linkerd paths specified:" >&2
+          echo "  $linkerd_path" >&2
+          echo "  $1" >&2
+          usage "$0" >&2
+          exit 64
+        fi
+        linkerd_path="$1"
+        shift
+        ;;
     esac
-    shift
   done
 
-  export linkerd_path="$1"
   if [ -z "$linkerd_path" ]; then
-    echo "Error: path to linkerd binary is required
-Help:
-     ${0##*/} -h|--help
-Basic usage:
-     ${0##*/} /path/to/linkerd"
+    echo "Error: path to linkerd binary is required" >&2
+    usage "$0" >&2
     exit 64
   fi
 }
diff --git a/cli/cmd/install_test.go b/cli/cmd/install_test.go
index a9e23656c..b56fe47e1 100644
--- a/cli/cmd/install_test.go
+++ b/cli/cmd/install_test.go
@@ -91,6 +91,8 @@ func TestRender(t *testing.T) {
 			CNIEnabled:               false,
 			IdentityTrustDomain:      defaultValues.Global.IdentityTrustDomain,
 			IdentityTrustAnchorsPEM:  defaultValues.Global.IdentityTrustAnchorsPEM,
+			PodAnnotations:           map[string]string{},
+			PodLabels:                map[string]string{},
 			Proxy: &charts.Proxy{
 				DestinationGetNetworks: "DestinationGetNetworks",
 				Image: &charts.Image{
diff --git a/cli/cmd/testdata/install_addon_control-plane.golden b/cli/cmd/testdata/install_addon_control-plane.golden
index 7326ae0ff..82a858b2d 100644
--- a/cli/cmd/testdata/install_addon_control-plane.golden
+++ b/cli/cmd/testdata/install_addon_control-plane.golden
@@ -65,6 +65,8 @@ data:
       linkerdNamespaceLabel: linkerd.io/is-control-plane
       linkerdVersion: dev-undefined
       namespace: linkerd
+      podAnnotations: {}
+      podLabels: {}
       prometheusUrl: ""
       proxy:
         capabilities: null
diff --git a/cli/cmd/testdata/install_control-plane.golden b/cli/cmd/testdata/install_control-plane.golden
index 25044de72..6ccde93d7 100644
--- a/cli/cmd/testdata/install_control-plane.golden
+++ b/cli/cmd/testdata/install_control-plane.golden
@@ -65,6 +65,8 @@ data:
       linkerdNamespaceLabel: linkerd.io/is-control-plane
       linkerdVersion: dev-undefined
       namespace: linkerd
+      podAnnotations: {}
+      podLabels: {}
       prometheusUrl: ""
       proxy:
         capabilities: null
diff --git a/cli/cmd/testdata/install_controlplane_tracing_output.golden b/cli/cmd/testdata/install_controlplane_tracing_output.golden
index 29c1d8f1f..1b4673437 100644
--- a/cli/cmd/testdata/install_controlplane_tracing_output.golden
+++ b/cli/cmd/testdata/install_controlplane_tracing_output.golden
@@ -853,6 +853,8 @@ data:
       linkerdNamespaceLabel: linkerd.io/is-control-plane
       linkerdVersion: dev-undefined
       namespace: linkerd
+      podAnnotations: {}
+      podLabels: {}
       prometheusUrl: ""
       proxy:
         capabilities: null
diff --git a/cli/cmd/testdata/install_custom_registry.golden b/cli/cmd/testdata/install_custom_registry.golden
index 55fab46e0..3945fc3be 100644
--- a/cli/cmd/testdata/install_custom_registry.golden
+++ b/cli/cmd/testdata/install_custom_registry.golden
@@ -853,6 +853,8 @@ data:
       linkerdNamespaceLabel: linkerd.io/is-control-plane
       linkerdVersion: dev-undefined
       namespace: linkerd
+      podAnnotations: {}
+      podLabels: {}
       prometheusUrl: ""
       proxy:
         capabilities: null
diff --git a/cli/cmd/testdata/install_default.golden b/cli/cmd/testdata/install_default.golden
index 21798c5a4..ac029e791 100644
--- a/cli/cmd/testdata/install_default.golden
+++ b/cli/cmd/testdata/install_default.golden
@@ -853,6 +853,8 @@ data:
       linkerdNamespaceLabel: linkerd.io/is-control-plane
       linkerdVersion: dev-undefined
       namespace: linkerd
+      podAnnotations: {}
+      podLabels: {}
       prometheusUrl: ""
       proxy:
         capabilities: null
diff --git a/cli/cmd/testdata/install_default_override_dst_get_nets.golden b/cli/cmd/testdata/install_default_override_dst_get_nets.golden
index 60b4e3b71..f2b8b4ec0 100644
--- a/cli/cmd/testdata/install_default_override_dst_get_nets.golden
+++ b/cli/cmd/testdata/install_default_override_dst_get_nets.golden
@@ -853,6 +853,8 @@ data:
       linkerdNamespaceLabel: linkerd.io/is-control-plane
       linkerdVersion: dev-undefined
       namespace: linkerd
+      podAnnotations: {}
+      podLabels: {}
       prometheusUrl: ""
       proxy:
         capabilities: null
diff --git a/cli/cmd/testdata/install_grafana_existing.golden b/cli/cmd/testdata/install_grafana_existing.golden
index 095fb6543..fe56567fa 100644
--- a/cli/cmd/testdata/install_grafana_existing.golden
+++ b/cli/cmd/testdata/install_grafana_existing.golden
@@ -850,6 +850,8 @@ data:
       linkerdNamespaceLabel: linkerd.io/is-control-plane
       linkerdVersion: dev-undefined
       namespace: linkerd
+      podAnnotations: {}
+      podLabels: {}
       prometheusUrl: ""
       proxy:
         capabilities: null
diff --git a/cli/cmd/testdata/install_ha_output.golden b/cli/cmd/testdata/install_ha_output.golden
index 2cd3595a9..ed02b9db2 100644
--- a/cli/cmd/testdata/install_ha_output.golden
+++ b/cli/cmd/testdata/install_ha_output.golden
@@ -859,6 +859,8 @@ data:
       linkerdNamespaceLabel: linkerd.io/is-control-plane
       linkerdVersion: dev-undefined
       namespace: linkerd
+      podAnnotations: {}
+      podLabels: {}
       prometheusUrl: ""
       proxy:
         capabilities: null
diff --git a/cli/cmd/testdata/install_ha_with_overrides_output.golden b/cli/cmd/testdata/install_ha_with_overrides_output.golden
index 223dd1751..3b772182e 100644
--- a/cli/cmd/testdata/install_ha_with_overrides_output.golden
+++ b/cli/cmd/testdata/install_ha_with_overrides_output.golden
@@ -859,6 +859,8 @@ data:
       linkerdNamespaceLabel: linkerd.io/is-control-plane
       linkerdVersion: dev-undefined
       namespace: linkerd
+      podAnnotations: {}
+      podLabels: {}
       prometheusUrl: ""
       proxy:
         capabilities: null
diff --git a/cli/cmd/testdata/install_heartbeat_disabled_output.golden b/cli/cmd/testdata/install_heartbeat_disabled_output.golden
index 67e57d2a8..66636ca33 100644
--- a/cli/cmd/testdata/install_heartbeat_disabled_output.golden
+++ b/cli/cmd/testdata/install_heartbeat_disabled_output.golden
@@ -809,6 +809,8 @@ data:
       linkerdNamespaceLabel: linkerd.io/is-control-plane
       linkerdVersion: dev-undefined
       namespace: linkerd
+      podAnnotations: {}
+      podLabels: {}
       prometheusUrl: ""
       proxy:
         capabilities: null
diff --git a/cli/cmd/testdata/install_helm_output.golden b/cli/cmd/testdata/install_helm_output.golden
index 818f8ebb7..d5ba61aa7 100644
--- a/cli/cmd/testdata/install_helm_output.golden
+++ b/cli/cmd/testdata/install_helm_output.golden
@@ -929,6 +929,8 @@ data:
       linkerdNamespaceLabel: linkerd.io/is-control-plane
       linkerdVersion: linkerd-version
       namespace: linkerd
+      podAnnotations: {}
+      podLabels: {}
       prometheusUrl: ""
       proxy:
         capabilities: null
@@ -1014,6 +1016,8 @@ data:
         linkerdNamespaceLabel: linkerd.io/is-control-plane
         linkerdVersion: linkerd-version
         namespace: linkerd
+        podAnnotations: {}
+        podLabels: {}
         prometheusUrl: ""
         proxy:
           capabilities: null
@@ -1100,6 +1104,8 @@ data:
           linkerdNamespaceLabel: linkerd.io/is-control-plane
           linkerdVersion: linkerd-version
           namespace: linkerd
+          podAnnotations: {}
+          podLabels: {}
           prometheusUrl: ""
           proxy:
             capabilities: null
@@ -1211,6 +1217,8 @@ data:
         linkerdNamespaceLabel: linkerd.io/is-control-plane
         linkerdVersion: linkerd-version
         namespace: linkerd
+        podAnnotations: {}
+        podLabels: {}
         prometheusUrl: ""
         proxy:
           capabilities: null
@@ -1300,6 +1308,8 @@ data:
           linkerdNamespaceLabel: linkerd.io/is-control-plane
           linkerdVersion: linkerd-version
           namespace: linkerd
+          podAnnotations: {}
+          podLabels: {}
           prometheusUrl: ""
           proxy:
             capabilities: null
diff --git a/cli/cmd/testdata/install_helm_output_addons.golden b/cli/cmd/testdata/install_helm_output_addons.golden
index 5b1eba592..03dc6839e 100644
--- a/cli/cmd/testdata/install_helm_output_addons.golden
+++ b/cli/cmd/testdata/install_helm_output_addons.golden
@@ -929,6 +929,8 @@ data:
       linkerdNamespaceLabel: linkerd.io/is-control-plane
       linkerdVersion: linkerd-version
       namespace: linkerd
+      podAnnotations: {}
+      podLabels: {}
       prometheusUrl: ""
       proxy:
         capabilities: null
@@ -1014,6 +1016,8 @@ data:
         linkerdNamespaceLabel: linkerd.io/is-control-plane
         linkerdVersion: linkerd-version
         namespace: linkerd
+        podAnnotations: {}
+        podLabels: {}
         prometheusUrl: ""
         proxy:
           capabilities: null
@@ -1100,6 +1104,8 @@ data:
           linkerdNamespaceLabel: linkerd.io/is-control-plane
           linkerdVersion: linkerd-version
           namespace: linkerd
+          podAnnotations: {}
+          podLabels: {}
           prometheusUrl: ""
           proxy:
             capabilities: null
@@ -1211,6 +1217,8 @@ data:
         linkerdNamespaceLabel: linkerd.io/is-control-plane
         linkerdVersion: linkerd-version
         namespace: linkerd
+        podAnnotations: {}
+        podLabels: {}
         prometheusUrl: ""
         proxy:
           capabilities: null
@@ -1300,6 +1308,8 @@ data:
           linkerdNamespaceLabel: linkerd.io/is-control-plane
           linkerdVersion: linkerd-version
           namespace: linkerd
+          podAnnotations: {}
+          podLabels: {}
           prometheusUrl: ""
           proxy:
             capabilities: null
@@ -1406,6 +1416,8 @@ data:
         linkerdNamespaceLabel: linkerd.io/is-control-plane
         linkerdVersion: linkerd-version
         namespace: linkerd
+        podAnnotations: {}
+        podLabels: {}
         prometheusUrl: ""
         proxy:
           capabilities: null
@@ -1492,6 +1504,8 @@ data:
           linkerdNamespaceLabel: linkerd.io/is-control-plane
           linkerdVersion: linkerd-version
           namespace: linkerd
+          podAnnotations: {}
+          podLabels: {}
           prometheusUrl: ""
           proxy:
             capabilities: null
diff --git a/cli/cmd/testdata/install_helm_output_ha.golden b/cli/cmd/testdata/install_helm_output_ha.golden
index bed42703b..b8b9cacc4 100644
--- a/cli/cmd/testdata/install_helm_output_ha.golden
+++ b/cli/cmd/testdata/install_helm_output_ha.golden
@@ -935,6 +935,8 @@ data:
       linkerdNamespaceLabel: linkerd.io/is-control-plane
       linkerdVersion: linkerd-version
       namespace: linkerd
+      podAnnotations: {}
+      podLabels: {}
       prometheusUrl: ""
       proxy:
         capabilities: null
@@ -1019,6 +1021,8 @@ data:
         linkerdNamespaceLabel: linkerd.io/is-control-plane
         linkerdVersion: linkerd-version
         namespace: linkerd
+        podAnnotations: {}
+        podLabels: {}
         prometheusUrl: ""
         proxy:
           capabilities: null
@@ -1104,6 +1108,8 @@ data:
           linkerdNamespaceLabel: linkerd.io/is-control-plane
           linkerdVersion: linkerd-version
           namespace: linkerd
+          podAnnotations: {}
+          podLabels: {}
           prometheusUrl: ""
           proxy:
             capabilities: null
@@ -1233,6 +1239,8 @@ data:
         linkerdNamespaceLabel: linkerd.io/is-control-plane
         linkerdVersion: linkerd-version
         namespace: linkerd
+        podAnnotations: {}
+        podLabels: {}
         prometheusUrl: ""
         proxy:
           capabilities: null
@@ -1321,6 +1329,8 @@ data:
           linkerdNamespaceLabel: linkerd.io/is-control-plane
           linkerdVersion: linkerd-version
           namespace: linkerd
+          podAnnotations: {}
+          podLabels: {}
           prometheusUrl: ""
           proxy:
             capabilities: null
diff --git a/cli/cmd/testdata/install_no_init_container.golden b/cli/cmd/testdata/install_no_init_container.golden
index f20365bcb..95702088e 100644
--- a/cli/cmd/testdata/install_no_init_container.golden
+++ b/cli/cmd/testdata/install_no_init_container.golden
@@ -850,6 +850,8 @@ data:
       linkerdNamespaceLabel: linkerd.io/is-control-plane
       linkerdVersion: dev-undefined
       namespace: linkerd
+      podAnnotations: {}
+      podLabels: {}
       prometheusUrl: ""
       proxy:
         capabilities: null
diff --git a/cli/cmd/testdata/install_output.golden b/cli/cmd/testdata/install_output.golden
index fb12dda36..44579b0f6 100644
--- a/cli/cmd/testdata/install_output.golden
+++ b/cli/cmd/testdata/install_output.golden
@@ -853,6 +853,8 @@ data:
       linkerdNamespaceLabel: LinkerdNamespaceLabel
       linkerdVersion: ""
       namespace: Namespace
+      podAnnotations: {}
+      podLabels: {}
       prometheusUrl: ""
       proxy:
         capabilities: null
diff --git a/cli/cmd/testdata/install_prometheus_overwrite.golden b/cli/cmd/testdata/install_prometheus_overwrite.golden
index 462ec39bd..664ce4691 100644
--- a/cli/cmd/testdata/install_prometheus_overwrite.golden
+++ b/cli/cmd/testdata/install_prometheus_overwrite.golden
@@ -853,6 +853,8 @@ data:
       linkerdNamespaceLabel: linkerd.io/is-control-plane
       linkerdVersion: dev-undefined
       namespace: linkerd
+      podAnnotations: {}
+      podLabels: {}
       prometheusUrl: ""
       proxy:
         capabilities: null
diff --git a/cli/cmd/testdata/install_proxy_ignores.golden b/cli/cmd/testdata/install_proxy_ignores.golden
index b3667c8d4..a9cf093f6 100644
--- a/cli/cmd/testdata/install_proxy_ignores.golden
+++ b/cli/cmd/testdata/install_proxy_ignores.golden
@@ -853,6 +853,8 @@ data:
       linkerdNamespaceLabel: linkerd.io/is-control-plane
       linkerdVersion: dev-undefined
       namespace: linkerd
+      podAnnotations: {}
+      podLabels: {}
       prometheusUrl: ""
       proxy:
         capabilities: null
diff --git a/cli/cmd/testdata/install_restricted_dashboard.golden b/cli/cmd/testdata/install_restricted_dashboard.golden
index 0eb065f34..84a11f520 100644
--- a/cli/cmd/testdata/install_restricted_dashboard.golden
+++ b/cli/cmd/testdata/install_restricted_dashboard.golden
@@ -785,6 +785,8 @@ data:
       linkerdNamespaceLabel: linkerd.io/is-control-plane
       linkerdVersion: dev-undefined
       namespace: linkerd
+      podAnnotations: {}
+      podLabels: {}
       prometheusUrl: ""
       proxy:
         capabilities: null
diff --git a/cli/cmd/testdata/install_tracing.golden b/cli/cmd/testdata/install_tracing.golden
index f47db6316..ed260dabc 100644
--- a/cli/cmd/testdata/install_tracing.golden
+++ b/cli/cmd/testdata/install_tracing.golden
@@ -853,6 +853,8 @@ data:
       linkerdNamespaceLabel: linkerd.io/is-control-plane
       linkerdVersion: dev-undefined
       namespace: linkerd
+      podAnnotations: {}
+      podLabels: {}
       prometheusUrl: ""
       proxy:
         capabilities: null
diff --git a/cli/cmd/testdata/install_tracing_overwrite.golden b/cli/cmd/testdata/install_tracing_overwrite.golden
index 71bf48f67..75e2585af 100644
--- a/cli/cmd/testdata/install_tracing_overwrite.golden
+++ b/cli/cmd/testdata/install_tracing_overwrite.golden
@@ -853,6 +853,8 @@ data:
       linkerdNamespaceLabel: linkerd.io/is-control-plane
       linkerdVersion: dev-undefined
       namespace: linkerd
+      podAnnotations: {}
+      podLabels: {}
       prometheusUrl: ""
       proxy:
         capabilities: null
diff --git a/pkg/charts/linkerd2/values_test.go b/pkg/charts/linkerd2/values_test.go
index 389dc34f7..805903417 100644
--- a/pkg/charts/linkerd2/values_test.go
+++ b/pkg/charts/linkerd2/values_test.go
@@ -52,6 +52,8 @@ func TestNewValues(t *testing.T) {
 			ControlPlaneTracing:      false,
 			HighAvailability:         false,
 			IdentityTrustDomain:      "cluster.local",
+			PodAnnotations:           map[string]string{},
+			PodLabels:                map[string]string{},
 			Proxy: &Proxy{
 				EnableExternalProfiles: false,
 				Image: &Image{