Skip to content

Commit 16d5cef

Browse files
authored
Merge pull request #3937 from camilamacedo86/fix-patch-metrics
🐛 fix: preserve existing flags when applying metrics patch
2 parents 1798f4a + d05aae5 commit 16d5cef

File tree

41 files changed

+82
-124
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+82
-124
lines changed

.github/workflows/test-sample-go.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ jobs:
2424
run: |
2525
KUSTOMIZATION_FILE_PATH="testdata/project-v4/config/default/kustomization.yaml"
2626
sed -i '25s/^#//' $KUSTOMIZATION_FILE_PATH
27-
sed -i '27s/^#//' $KUSTOMIZATION_FILE_PATH
28-
sed -i '42s/^#//' $KUSTOMIZATION_FILE_PATH
29-
sed -i '46,142s/^#//' $KUSTOMIZATION_FILE_PATH
27+
sed -i '39s/^#//' $KUSTOMIZATION_FILE_PATH
28+
sed -i '44s/^#//' $KUSTOMIZATION_FILE_PATH
29+
sed -i '48,144s/^#//' $KUSTOMIZATION_FILE_PATH
3030
3131
- name: Test
3232
run: |

docs/book/src/cronjob-tutorial/testdata/project/cmd/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ func main() {
7676
var probeAddr string
7777
var secureMetrics bool
7878
var enableHTTP2 bool
79-
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
79+
flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metric endpoint binds to. "+
80+
"Use the port :8080. If not set, it will be '0 in order to disable the metrics server")
8081
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
8182
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
8283
"Enable leader election for controller manager. "+

docs/book/src/cronjob-tutorial/testdata/project/config/default/kustomization.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ patches:
3131
# More info: https://book.kubebuilder.io/reference/metrics
3232
# If you want to expose the metric endpoint of your controller-manager uncomment the following line.
3333
#- path: manager_metrics_patch.yaml
34+
# target:
35+
# kind: Deployment
3436

3537
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
3638
# crd/kustomization.yaml
Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
# This patch adds the args to allow exposing the metrics endpoint securely
2-
apiVersion: apps/v1
3-
kind: Deployment
4-
metadata:
5-
name: controller-manager
6-
namespace: system
7-
spec:
8-
template:
9-
spec:
10-
containers:
11-
- name: manager
12-
args:
13-
- "--metrics-bind-address=0.0.0.0:8080"
2+
- op: add
3+
path: /spec/template/spec/containers/0/args/0
4+
value: --metrics-bind-address=:8080

docs/book/src/cronjob-tutorial/testdata/project/config/manager/manager.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ spec:
6363
args:
6464
- --leader-elect
6565
- --health-probe-bind-address=:8081
66-
- --metrics-bind-address=0
6766
image: controller:latest
6867
name: manager
6968
securityContext:

docs/book/src/getting-started/testdata/project/cmd/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ func main() {
5757
var probeAddr string
5858
var secureMetrics bool
5959
var enableHTTP2 bool
60-
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
60+
flag.StringVar(&metricsAddr, "metrics-bind-address", "0", "The address the metric endpoint binds to. "+
61+
"Use the port :8080. If not set, it will be '0 in order to disable the metrics server")
6162
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
6263
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
6364
"Enable leader election for controller manager. "+

docs/book/src/getting-started/testdata/project/config/default/kustomization.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ patches:
3131
# More info: https://book.kubebuilder.io/reference/metrics
3232
# If you want to expose the metric endpoint of your controller-manager uncomment the following line.
3333
#- path: manager_metrics_patch.yaml
34+
# target:
35+
# kind: Deployment
3436

3537
# [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
3638
# crd/kustomization.yaml
Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
# This patch adds the args to allow exposing the metrics endpoint securely
2-
apiVersion: apps/v1
3-
kind: Deployment
4-
metadata:
5-
name: controller-manager
6-
namespace: system
7-
spec:
8-
template:
9-
spec:
10-
containers:
11-
- name: manager
12-
args:
13-
- "--metrics-bind-address=0.0.0.0:8080"
2+
- op: add
3+
path: /spec/template/spec/containers/0/args/0
4+
value: --metrics-bind-address=:8080

docs/book/src/getting-started/testdata/project/config/manager/manager.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ spec:
6363
args:
6464
- --leader-elect
6565
- --health-probe-bind-address=:8081
66-
- --metrics-bind-address=0
6766
image: controller:latest
6867
name: manager
6968
env:

docs/book/src/reference/metrics.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ First, you will need enable the Metrics by uncommenting the following line
4646
in the file `config/default/kustomization.yaml`, see:
4747

4848
```sh
49-
# [Metrics] The following patch will enable the metrics endpoint.
50-
# Ensure that you also protect this endpoint.
49+
# [METRICS] The following patch will enable the metrics endpoint. Ensure that you also protect this endpoint.
50+
# More info: https://book.kubebuilder.io/reference/metrics
51+
# If you want to expose the metric endpoint of your controller-manager uncomment the following line.
5152
#- path: manager_metrics_patch.yaml
53+
# target:
54+
# kind: Deployment
5255
```
5356

5457
Note that projects are scaffolded by default passing the flag `--metrics-bind-address=0`

0 commit comments

Comments
 (0)