From 933fd41a22238a1cfe34a5ff211b8c921e326a61 Mon Sep 17 00:00:00 2001 From: Camila Macedo Date: Mon, 20 May 2024 23:28:31 +0100 Subject: [PATCH] fix: preserve existing flags when applying metrics patch Ensure that enabling the manager_metrics_patch.yaml in config/default/kustomization.yaml does not overwrite existing arguments in config/manager/manager.yaml. The patch now appends the --metrics-bind-address argument without replacing other arguments. More info: https://github.com/kubernetes-sigs/kubebuilder/issues/3934 --- .github/workflows/test-sample-go.yml | 6 +++--- .../project/config/default/kustomization.yaml | 2 ++ .../config/default/manager_metrics_patch.yaml | 15 +++------------ .../testdata/project/config/manager/manager.yaml | 4 +++- .../project/config/default/kustomization.yaml | 2 ++ .../config/default/manager_metrics_patch.yaml | 15 +++------------ .../testdata/project/config/manager/manager.yaml | 4 +++- docs/book/src/reference/metrics.md | 7 +++++-- .../templates/config/kdefault/kustomization.go | 2 ++ ..._matrics_patch.go => manager_metrics_patch.go} | 15 +++------------ .../internal/templates/config/manager/config.go | 4 +++- test/e2e/v4/generate_test.go | 8 ++++++-- test/e2e/v4/plugin_cluster_test.go | 12 ++++++++++++ .../config/default/kustomization.yaml | 2 ++ .../config/default/manager_metrics_patch.yaml | 15 +++------------ .../config/manager/manager.yaml | 4 +++- .../dist/install.yaml | 2 +- .../config/default/kustomization.yaml | 2 ++ .../config/default/manager_metrics_patch.yaml | 15 +++------------ .../config/manager/manager.yaml | 4 +++- testdata/project-v4-multigroup/dist/install.yaml | 2 +- .../config/default/kustomization.yaml | 2 ++ .../config/default/manager_metrics_patch.yaml | 15 +++------------ .../config/manager/manager.yaml | 4 +++- .../dist/install.yaml | 2 +- .../config/default/kustomization.yaml | 2 ++ .../config/default/manager_metrics_patch.yaml | 15 +++------------ .../config/manager/manager.yaml | 4 +++- .../project-v4-with-grafana/dist/install.yaml | 2 +- .../project-v4/config/default/kustomization.yaml | 2 ++ .../config/default/manager_metrics_patch.yaml | 15 +++------------ testdata/project-v4/config/manager/manager.yaml | 4 +++- testdata/project-v4/dist/install.yaml | 2 +- 33 files changed, 95 insertions(+), 116 deletions(-) rename pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/kdefault/{enable_matrics_patch.go => manager_metrics_patch.go} (85%) diff --git a/.github/workflows/test-sample-go.yml b/.github/workflows/test-sample-go.yml index 3a6d11a7c70..a33f6b0f8eb 100644 --- a/.github/workflows/test-sample-go.yml +++ b/.github/workflows/test-sample-go.yml @@ -24,9 +24,9 @@ jobs: run: | KUSTOMIZATION_FILE_PATH="testdata/project-v4/config/default/kustomization.yaml" sed -i '25s/^#//' $KUSTOMIZATION_FILE_PATH - sed -i '27s/^#//' $KUSTOMIZATION_FILE_PATH - sed -i '42s/^#//' $KUSTOMIZATION_FILE_PATH - sed -i '46,142s/^#//' $KUSTOMIZATION_FILE_PATH + sed -i '39s/^#//' $KUSTOMIZATION_FILE_PATH + sed -i '44s/^#//' $KUSTOMIZATION_FILE_PATH + sed -i '48,144s/^#//' $KUSTOMIZATION_FILE_PATH - name: Test run: | diff --git a/docs/book/src/cronjob-tutorial/testdata/project/config/default/kustomization.yaml b/docs/book/src/cronjob-tutorial/testdata/project/config/default/kustomization.yaml index 9cd07c6181b..e0c1e50e0ce 100644 --- a/docs/book/src/cronjob-tutorial/testdata/project/config/default/kustomization.yaml +++ b/docs/book/src/cronjob-tutorial/testdata/project/config/default/kustomization.yaml @@ -31,6 +31,8 @@ patches: # More info: https://book.kubebuilder.io/reference/metrics # If you want to expose the metric endpoint of your controller-manager uncomment the following line. #- path: manager_metrics_patch.yaml +# target: +# kind: Deployment # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in # crd/kustomization.yaml diff --git a/docs/book/src/cronjob-tutorial/testdata/project/config/default/manager_metrics_patch.yaml b/docs/book/src/cronjob-tutorial/testdata/project/config/default/manager_metrics_patch.yaml index ee197d3f718..f8ed796ddbb 100644 --- a/docs/book/src/cronjob-tutorial/testdata/project/config/default/manager_metrics_patch.yaml +++ b/docs/book/src/cronjob-tutorial/testdata/project/config/default/manager_metrics_patch.yaml @@ -1,13 +1,4 @@ # This patch adds the args to allow exposing the metrics endpoint securely -apiVersion: apps/v1 -kind: Deployment -metadata: - name: controller-manager - namespace: system -spec: - template: - spec: - containers: - - name: manager - args: - - "--metrics-bind-address=0.0.0.0:8080" +- op: replace + path: /spec/template/spec/containers/0/args/0 + value: --metrics-bind-address=0.0.0.0:8080 diff --git a/docs/book/src/cronjob-tutorial/testdata/project/config/manager/manager.yaml b/docs/book/src/cronjob-tutorial/testdata/project/config/manager/manager.yaml index c51cb2471d6..fc5c318c005 100644 --- a/docs/book/src/cronjob-tutorial/testdata/project/config/manager/manager.yaml +++ b/docs/book/src/cronjob-tutorial/testdata/project/config/manager/manager.yaml @@ -61,9 +61,11 @@ spec: - command: - /manager args: + - --metrics-bind-address=0 + # Add other args only bellow. Otherwise, it will make the patch + # in config/default/manager_metrics_patch.yaml stop to work - --leader-elect - --health-probe-bind-address=:8081 - - --metrics-bind-address=0 image: controller:latest name: manager securityContext: diff --git a/docs/book/src/getting-started/testdata/project/config/default/kustomization.yaml b/docs/book/src/getting-started/testdata/project/config/default/kustomization.yaml index 3e7e6da4538..8b3fe2ba35c 100644 --- a/docs/book/src/getting-started/testdata/project/config/default/kustomization.yaml +++ b/docs/book/src/getting-started/testdata/project/config/default/kustomization.yaml @@ -31,6 +31,8 @@ patches: # More info: https://book.kubebuilder.io/reference/metrics # If you want to expose the metric endpoint of your controller-manager uncomment the following line. #- path: manager_metrics_patch.yaml +# target: +# kind: Deployment # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in # crd/kustomization.yaml diff --git a/docs/book/src/getting-started/testdata/project/config/default/manager_metrics_patch.yaml b/docs/book/src/getting-started/testdata/project/config/default/manager_metrics_patch.yaml index ee197d3f718..f8ed796ddbb 100644 --- a/docs/book/src/getting-started/testdata/project/config/default/manager_metrics_patch.yaml +++ b/docs/book/src/getting-started/testdata/project/config/default/manager_metrics_patch.yaml @@ -1,13 +1,4 @@ # This patch adds the args to allow exposing the metrics endpoint securely -apiVersion: apps/v1 -kind: Deployment -metadata: - name: controller-manager - namespace: system -spec: - template: - spec: - containers: - - name: manager - args: - - "--metrics-bind-address=0.0.0.0:8080" +- op: replace + path: /spec/template/spec/containers/0/args/0 + value: --metrics-bind-address=0.0.0.0:8080 diff --git a/docs/book/src/getting-started/testdata/project/config/manager/manager.yaml b/docs/book/src/getting-started/testdata/project/config/manager/manager.yaml index 602974cc5fc..8d07d515387 100644 --- a/docs/book/src/getting-started/testdata/project/config/manager/manager.yaml +++ b/docs/book/src/getting-started/testdata/project/config/manager/manager.yaml @@ -61,9 +61,11 @@ spec: - command: - /manager args: + - --metrics-bind-address=0 + # Add other args only bellow. Otherwise, it will make the patch + # in config/default/manager_metrics_patch.yaml stop to work - --leader-elect - --health-probe-bind-address=:8081 - - --metrics-bind-address=0 image: controller:latest name: manager env: diff --git a/docs/book/src/reference/metrics.md b/docs/book/src/reference/metrics.md index f6d949990c3..32aa09610c7 100644 --- a/docs/book/src/reference/metrics.md +++ b/docs/book/src/reference/metrics.md @@ -46,9 +46,12 @@ First, you will need enable the Metrics by uncommenting the following line in the file `config/default/kustomization.yaml`, see: ```sh -# [Metrics] The following patch will enable the metrics endpoint. -# Ensure that you also protect this endpoint. +# [METRICS] The following patch will enable the metrics endpoint. Ensure that you also protect this endpoint. +# More info: https://book.kubebuilder.io/reference/metrics +# If you want to expose the metric endpoint of your controller-manager uncomment the following line. #- path: manager_metrics_patch.yaml +# target: +# kind: Deployment ``` Note that projects are scaffolded by default passing the flag `--metrics-bind-address=0` diff --git a/pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/kdefault/kustomization.go b/pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/kdefault/kustomization.go index 99cf94f9585..2a7368840ff 100644 --- a/pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/kdefault/kustomization.go +++ b/pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/kdefault/kustomization.go @@ -76,6 +76,8 @@ patches: # More info: https://book.kubebuilder.io/reference/metrics # If you want to expose the metric endpoint of your controller-manager uncomment the following line. #- path: manager_metrics_patch.yaml +# target: +# kind: Deployment # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in # crd/kustomization.yaml diff --git a/pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/kdefault/enable_matrics_patch.go b/pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/kdefault/manager_metrics_patch.go similarity index 85% rename from pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/kdefault/enable_matrics_patch.go rename to pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/kdefault/manager_metrics_patch.go index 768950bbf04..6cc0061d20c 100644 --- a/pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/kdefault/enable_matrics_patch.go +++ b/pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/kdefault/manager_metrics_patch.go @@ -43,16 +43,7 @@ func (f *ManagerMetricsPatch) SetTemplateDefaults() error { } const kustomizeMetricsPatchTemplate = `# This patch adds the args to allow exposing the metrics endpoint securely -apiVersion: apps/v1 -kind: Deployment -metadata: - name: controller-manager - namespace: system -spec: - template: - spec: - containers: - - name: manager - args: - - "--metrics-bind-address=0.0.0.0:8080" +- op: replace + path: /spec/template/spec/containers/0/args/0 + value: --metrics-bind-address=0.0.0.0:8080 ` diff --git a/pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/manager/config.go b/pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/manager/config.go index 000c3901a25..718e97b9d1b 100644 --- a/pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/manager/config.go +++ b/pkg/plugins/common/kustomize/v2/scaffolds/internal/templates/config/manager/config.go @@ -107,9 +107,11 @@ spec: - command: - /manager args: + - --metrics-bind-address=0 + # Add other args only bellow. Otherwise, it will make the patch + # in config/default/manager_metrics_patch.yaml stop to work - --leader-elect - --health-probe-bind-address=:8081 - - --metrics-bind-address=0 image: {{ .Image }} name: manager securityContext: diff --git a/test/e2e/v4/generate_test.go b/test/e2e/v4/generate_test.go index 6e425bad7c4..651977d6d92 100644 --- a/test/e2e/v4/generate_test.go +++ b/test/e2e/v4/generate_test.go @@ -65,7 +65,7 @@ func GenerateV4(kbc *utils.TestContext) { "#- path: webhookcainjection_patch.yaml", "#")).To(Succeed()) ExpectWithOffset(1, pluginutil.UncommentCode( filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"), - "#- path: manager_metrics_patch.yaml", "#")).To(Succeed()) + metricsTarget, "#")).To(Succeed()) ExpectWithOffset(1, pluginutil.UncommentCode(filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"), certManagerTarget, "#")).To(Succeed()) @@ -125,7 +125,7 @@ func GenerateV4WithoutWebhooks(kbc *utils.TestContext) { "#- ../prometheus", "#")).To(Succeed()) ExpectWithOffset(1, pluginutil.UncommentCode( filepath.Join(kbc.Dir, "config", "default", "kustomization.yaml"), - "#- path: manager_metrics_patch.yaml", "#")).To(Succeed()) + metricsTarget, "#")).To(Succeed()) if kbc.IsRestricted { By("uncomment kustomize files to ensure that pods are restricted") @@ -166,6 +166,10 @@ func initingTheProject(kbc *utils.TestContext) { ExpectWithOffset(1, err).NotTo(HaveOccurred()) } +const metricsTarget = `#- path: manager_metrics_patch.yaml +# target: +# kind: Deployment` + //nolint:lll const certManagerTarget = `#replacements: # - source: # Add cert-manager annotation to ValidatingWebhookConfiguration, MutatingWebhookConfiguration and CRDs diff --git a/test/e2e/v4/plugin_cluster_test.go b/test/e2e/v4/plugin_cluster_test.go index 6c3fcddda18..71c2d36fa50 100644 --- a/test/e2e/v4/plugin_cluster_test.go +++ b/test/e2e/v4/plugin_cluster_test.go @@ -163,6 +163,18 @@ func Run(kbc *utils.TestContext, hasWebhook, isToUseInstaller, hasMetrics bool) }() EventuallyWithOffset(1, verifyControllerUp, time.Minute, time.Second).Should(Succeed()) + By("Checking if all flags are applied to the manager pod") + podOutput, err := kbc.Kubectl.Get( + true, + "pod", controllerPodName, + "-o", "jsonpath={.spec.containers[0].args}", + ) + ExpectWithOffset(1, err).NotTo(HaveOccurred()) + ExpectWithOffset(1, podOutput).To(ContainSubstring("leader-elect"), + "Expected manager pod to have --leader-elect flag") + ExpectWithOffset(1, podOutput).To(ContainSubstring("health-probe-bind-address"), + "Expected manager pod to have --health-probe-bind-address flag") + By("validating the metrics endpoint") _ = curlMetrics(kbc, hasMetrics) diff --git a/testdata/project-v4-multigroup-with-deploy-image/config/default/kustomization.yaml b/testdata/project-v4-multigroup-with-deploy-image/config/default/kustomization.yaml index e81d73d4bc3..0191923a08c 100644 --- a/testdata/project-v4-multigroup-with-deploy-image/config/default/kustomization.yaml +++ b/testdata/project-v4-multigroup-with-deploy-image/config/default/kustomization.yaml @@ -31,6 +31,8 @@ patches: # More info: https://book.kubebuilder.io/reference/metrics # If you want to expose the metric endpoint of your controller-manager uncomment the following line. #- path: manager_metrics_patch.yaml +# target: +# kind: Deployment # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in # crd/kustomization.yaml diff --git a/testdata/project-v4-multigroup-with-deploy-image/config/default/manager_metrics_patch.yaml b/testdata/project-v4-multigroup-with-deploy-image/config/default/manager_metrics_patch.yaml index ee197d3f718..f8ed796ddbb 100644 --- a/testdata/project-v4-multigroup-with-deploy-image/config/default/manager_metrics_patch.yaml +++ b/testdata/project-v4-multigroup-with-deploy-image/config/default/manager_metrics_patch.yaml @@ -1,13 +1,4 @@ # This patch adds the args to allow exposing the metrics endpoint securely -apiVersion: apps/v1 -kind: Deployment -metadata: - name: controller-manager - namespace: system -spec: - template: - spec: - containers: - - name: manager - args: - - "--metrics-bind-address=0.0.0.0:8080" +- op: replace + path: /spec/template/spec/containers/0/args/0 + value: --metrics-bind-address=0.0.0.0:8080 diff --git a/testdata/project-v4-multigroup-with-deploy-image/config/manager/manager.yaml b/testdata/project-v4-multigroup-with-deploy-image/config/manager/manager.yaml index 4e217f48c6d..4b5ce551b31 100644 --- a/testdata/project-v4-multigroup-with-deploy-image/config/manager/manager.yaml +++ b/testdata/project-v4-multigroup-with-deploy-image/config/manager/manager.yaml @@ -61,9 +61,11 @@ spec: - command: - /manager args: + - --metrics-bind-address=0 + # Add other args only bellow. Otherwise, it will make the patch + # in config/default/manager_metrics_patch.yaml stop to work - --leader-elect - --health-probe-bind-address=:8081 - - --metrics-bind-address=0 image: controller:latest name: manager securityContext: diff --git a/testdata/project-v4-multigroup-with-deploy-image/dist/install.yaml b/testdata/project-v4-multigroup-with-deploy-image/dist/install.yaml index abdb347ab70..e96673e9fb7 100644 --- a/testdata/project-v4-multigroup-with-deploy-image/dist/install.yaml +++ b/testdata/project-v4-multigroup-with-deploy-image/dist/install.yaml @@ -1529,9 +1529,9 @@ spec: spec: containers: - args: + - --metrics-bind-address=0 - --leader-elect - --health-probe-bind-address=:8081 - - --metrics-bind-address=0 command: - /manager image: controller:latest diff --git a/testdata/project-v4-multigroup/config/default/kustomization.yaml b/testdata/project-v4-multigroup/config/default/kustomization.yaml index d00ee2596e1..ffb90673bac 100644 --- a/testdata/project-v4-multigroup/config/default/kustomization.yaml +++ b/testdata/project-v4-multigroup/config/default/kustomization.yaml @@ -31,6 +31,8 @@ patches: # More info: https://book.kubebuilder.io/reference/metrics # If you want to expose the metric endpoint of your controller-manager uncomment the following line. #- path: manager_metrics_patch.yaml +# target: +# kind: Deployment # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in # crd/kustomization.yaml diff --git a/testdata/project-v4-multigroup/config/default/manager_metrics_patch.yaml b/testdata/project-v4-multigroup/config/default/manager_metrics_patch.yaml index ee197d3f718..f8ed796ddbb 100644 --- a/testdata/project-v4-multigroup/config/default/manager_metrics_patch.yaml +++ b/testdata/project-v4-multigroup/config/default/manager_metrics_patch.yaml @@ -1,13 +1,4 @@ # This patch adds the args to allow exposing the metrics endpoint securely -apiVersion: apps/v1 -kind: Deployment -metadata: - name: controller-manager - namespace: system -spec: - template: - spec: - containers: - - name: manager - args: - - "--metrics-bind-address=0.0.0.0:8080" +- op: replace + path: /spec/template/spec/containers/0/args/0 + value: --metrics-bind-address=0.0.0.0:8080 diff --git a/testdata/project-v4-multigroup/config/manager/manager.yaml b/testdata/project-v4-multigroup/config/manager/manager.yaml index a65ca4a1bc2..a7d7e580d68 100644 --- a/testdata/project-v4-multigroup/config/manager/manager.yaml +++ b/testdata/project-v4-multigroup/config/manager/manager.yaml @@ -61,9 +61,11 @@ spec: - command: - /manager args: + - --metrics-bind-address=0 + # Add other args only bellow. Otherwise, it will make the patch + # in config/default/manager_metrics_patch.yaml stop to work - --leader-elect - --health-probe-bind-address=:8081 - - --metrics-bind-address=0 image: controller:latest name: manager securityContext: diff --git a/testdata/project-v4-multigroup/dist/install.yaml b/testdata/project-v4-multigroup/dist/install.yaml index 4d4beb4ad9f..bf23c64e5fc 100644 --- a/testdata/project-v4-multigroup/dist/install.yaml +++ b/testdata/project-v4-multigroup/dist/install.yaml @@ -1529,9 +1529,9 @@ spec: spec: containers: - args: + - --metrics-bind-address=0 - --leader-elect - --health-probe-bind-address=:8081 - - --metrics-bind-address=0 command: - /manager image: controller:latest diff --git a/testdata/project-v4-with-deploy-image/config/default/kustomization.yaml b/testdata/project-v4-with-deploy-image/config/default/kustomization.yaml index bf965dc95f0..d299940c871 100644 --- a/testdata/project-v4-with-deploy-image/config/default/kustomization.yaml +++ b/testdata/project-v4-with-deploy-image/config/default/kustomization.yaml @@ -31,6 +31,8 @@ patches: # More info: https://book.kubebuilder.io/reference/metrics # If you want to expose the metric endpoint of your controller-manager uncomment the following line. #- path: manager_metrics_patch.yaml +# target: +# kind: Deployment # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in # crd/kustomization.yaml diff --git a/testdata/project-v4-with-deploy-image/config/default/manager_metrics_patch.yaml b/testdata/project-v4-with-deploy-image/config/default/manager_metrics_patch.yaml index ee197d3f718..f8ed796ddbb 100644 --- a/testdata/project-v4-with-deploy-image/config/default/manager_metrics_patch.yaml +++ b/testdata/project-v4-with-deploy-image/config/default/manager_metrics_patch.yaml @@ -1,13 +1,4 @@ # This patch adds the args to allow exposing the metrics endpoint securely -apiVersion: apps/v1 -kind: Deployment -metadata: - name: controller-manager - namespace: system -spec: - template: - spec: - containers: - - name: manager - args: - - "--metrics-bind-address=0.0.0.0:8080" +- op: replace + path: /spec/template/spec/containers/0/args/0 + value: --metrics-bind-address=0.0.0.0:8080 diff --git a/testdata/project-v4-with-deploy-image/config/manager/manager.yaml b/testdata/project-v4-with-deploy-image/config/manager/manager.yaml index 1fd54a41dc2..4e8d46c0c23 100644 --- a/testdata/project-v4-with-deploy-image/config/manager/manager.yaml +++ b/testdata/project-v4-with-deploy-image/config/manager/manager.yaml @@ -61,9 +61,11 @@ spec: - command: - /manager args: + - --metrics-bind-address=0 + # Add other args only bellow. Otherwise, it will make the patch + # in config/default/manager_metrics_patch.yaml stop to work - --leader-elect - --health-probe-bind-address=:8081 - - --metrics-bind-address=0 image: controller:latest name: manager env: diff --git a/testdata/project-v4-with-deploy-image/dist/install.yaml b/testdata/project-v4-with-deploy-image/dist/install.yaml index 54d0bce5c16..280b70c2cc5 100644 --- a/testdata/project-v4-with-deploy-image/dist/install.yaml +++ b/testdata/project-v4-with-deploy-image/dist/install.yaml @@ -605,9 +605,9 @@ spec: spec: containers: - args: + - --metrics-bind-address=0 - --leader-elect - --health-probe-bind-address=:8081 - - --metrics-bind-address=0 command: - /manager env: diff --git a/testdata/project-v4-with-grafana/config/default/kustomization.yaml b/testdata/project-v4-with-grafana/config/default/kustomization.yaml index df5296e37fd..a76c38189c9 100644 --- a/testdata/project-v4-with-grafana/config/default/kustomization.yaml +++ b/testdata/project-v4-with-grafana/config/default/kustomization.yaml @@ -31,6 +31,8 @@ patches: # More info: https://book.kubebuilder.io/reference/metrics # If you want to expose the metric endpoint of your controller-manager uncomment the following line. #- path: manager_metrics_patch.yaml +# target: +# kind: Deployment # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in # crd/kustomization.yaml diff --git a/testdata/project-v4-with-grafana/config/default/manager_metrics_patch.yaml b/testdata/project-v4-with-grafana/config/default/manager_metrics_patch.yaml index ee197d3f718..f8ed796ddbb 100644 --- a/testdata/project-v4-with-grafana/config/default/manager_metrics_patch.yaml +++ b/testdata/project-v4-with-grafana/config/default/manager_metrics_patch.yaml @@ -1,13 +1,4 @@ # This patch adds the args to allow exposing the metrics endpoint securely -apiVersion: apps/v1 -kind: Deployment -metadata: - name: controller-manager - namespace: system -spec: - template: - spec: - containers: - - name: manager - args: - - "--metrics-bind-address=0.0.0.0:8080" +- op: replace + path: /spec/template/spec/containers/0/args/0 + value: --metrics-bind-address=0.0.0.0:8080 diff --git a/testdata/project-v4-with-grafana/config/manager/manager.yaml b/testdata/project-v4-with-grafana/config/manager/manager.yaml index 64ab9a2daa7..6949b649ae3 100644 --- a/testdata/project-v4-with-grafana/config/manager/manager.yaml +++ b/testdata/project-v4-with-grafana/config/manager/manager.yaml @@ -61,9 +61,11 @@ spec: - command: - /manager args: + - --metrics-bind-address=0 + # Add other args only bellow. Otherwise, it will make the patch + # in config/default/manager_metrics_patch.yaml stop to work - --leader-elect - --health-probe-bind-address=:8081 - - --metrics-bind-address=0 image: controller:latest name: manager securityContext: diff --git a/testdata/project-v4-with-grafana/dist/install.yaml b/testdata/project-v4-with-grafana/dist/install.yaml index 97764fed65b..f482c6069b0 100644 --- a/testdata/project-v4-with-grafana/dist/install.yaml +++ b/testdata/project-v4-with-grafana/dist/install.yaml @@ -148,9 +148,9 @@ spec: spec: containers: - args: + - --metrics-bind-address=0 - --leader-elect - --health-probe-bind-address=:8081 - - --metrics-bind-address=0 command: - /manager image: controller:latest diff --git a/testdata/project-v4/config/default/kustomization.yaml b/testdata/project-v4/config/default/kustomization.yaml index 131ea0843e0..848efcedaaa 100644 --- a/testdata/project-v4/config/default/kustomization.yaml +++ b/testdata/project-v4/config/default/kustomization.yaml @@ -31,6 +31,8 @@ patches: # More info: https://book.kubebuilder.io/reference/metrics # If you want to expose the metric endpoint of your controller-manager uncomment the following line. #- path: manager_metrics_patch.yaml +# target: +# kind: Deployment # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in # crd/kustomization.yaml diff --git a/testdata/project-v4/config/default/manager_metrics_patch.yaml b/testdata/project-v4/config/default/manager_metrics_patch.yaml index ee197d3f718..f8ed796ddbb 100644 --- a/testdata/project-v4/config/default/manager_metrics_patch.yaml +++ b/testdata/project-v4/config/default/manager_metrics_patch.yaml @@ -1,13 +1,4 @@ # This patch adds the args to allow exposing the metrics endpoint securely -apiVersion: apps/v1 -kind: Deployment -metadata: - name: controller-manager - namespace: system -spec: - template: - spec: - containers: - - name: manager - args: - - "--metrics-bind-address=0.0.0.0:8080" +- op: replace + path: /spec/template/spec/containers/0/args/0 + value: --metrics-bind-address=0.0.0.0:8080 diff --git a/testdata/project-v4/config/manager/manager.yaml b/testdata/project-v4/config/manager/manager.yaml index 29ab53f42f9..138c145d10f 100644 --- a/testdata/project-v4/config/manager/manager.yaml +++ b/testdata/project-v4/config/manager/manager.yaml @@ -61,9 +61,11 @@ spec: - command: - /manager args: + - --metrics-bind-address=0 + # Add other args only bellow. Otherwise, it will make the patch + # in config/default/manager_metrics_patch.yaml stop to work - --leader-elect - --health-probe-bind-address=:8081 - - --metrics-bind-address=0 image: controller:latest name: manager securityContext: diff --git a/testdata/project-v4/dist/install.yaml b/testdata/project-v4/dist/install.yaml index d7a7c1513c7..2a56ef7471c 100644 --- a/testdata/project-v4/dist/install.yaml +++ b/testdata/project-v4/dist/install.yaml @@ -599,9 +599,9 @@ spec: spec: containers: - args: + - --metrics-bind-address=0 - --leader-elect - --health-probe-bind-address=:8081 - - --metrics-bind-address=0 command: - /manager image: controller:latest