forked from kubernetes-sigs/kubebuilder
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat/fix: enhance cert-manager integration for metrics endpoints (fol…
…low-up to PR kubernetes-sigs#4243) This commit is a follow-up to PR kubernetes-sigs#4243, which introduced support for using cert-manager certificates for securing the metrics endpoint and ServiceMonitor. Key enhancements: - Added support for configuring certificate integration via a Kustomize patch. - Introduced configurable flags for greater flexibility in customization. - (fix)Updated the patch logic to append volumes and arguments without overwriting existing configurations, ensuring seamless integration. These improvements enhance usability and adaptability while maintaining compatibility with the initial implementation. As the feature has not yet been released, this update ensures a polished and user-friendly integration for upcoming releases.
- Loading branch information
1 parent
781e93f
commit 6114658
Showing
44 changed files
with
775 additions
and
424 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 43 additions & 21 deletions
64
...c/cronjob-tutorial/testdata/project/config/default/certmanager_metrics_manager_patch.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,43 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: controller-manager | ||
namespace: system | ||
labels: | ||
app.kubernetes.io/name: project | ||
app.kubernetes.io/managed-by: kustomize | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- name: manager | ||
volumeMounts: | ||
- mountPath: /tmp/k8s-metrics-server/metrics-certs | ||
name: metrics-certs | ||
readOnly: true | ||
volumes: | ||
- name: metrics-certs | ||
secret: | ||
secretName: metrics-server-cert | ||
# This patch adds the args and volumes to allow the manager to use the metrics-server certs | ||
# Ensure the volumeMounts field exists by creating it if missing | ||
- op: add | ||
path: /spec/template/spec/containers/0/volumeMounts | ||
value: [] | ||
# Add the volume mount for the serving certificates | ||
- op: add | ||
path: /spec/template/spec/containers/0/volumeMounts/- | ||
value: | ||
mountPath: /tmp/k8s-metrics-server/serving-certs | ||
name: metrics-certs | ||
readOnly: true | ||
# Add the cert-dir argument | ||
- op: add | ||
path: /spec/template/spec/containers/0/args/- | ||
value: --cert-dir=/tmp/k8s-metrics-server/serving-certs | ||
# Add the cert-name argument | ||
- op: add | ||
path: /spec/template/spec/containers/0/args/- | ||
value: --cert-name=/tmp/k8s-metrics-server/serving-certs/tls.crt | ||
# Add the cert-key argument | ||
- op: add | ||
path: /spec/template/spec/containers/0/args/- | ||
value: --cert-key=/tmp/k8s-metrics-server/serving-certs/tls.key | ||
# Ensure the volumes field exists by creating it if missing | ||
- op: add | ||
path: /spec/template/spec/volumes | ||
value: [] | ||
# Add the volume for the serving certificates | ||
- op: add | ||
path: /spec/template/spec/volumes/- | ||
value: | ||
name: metrics-certs | ||
secret: | ||
secretName: metrics-server-cert | ||
optional: false | ||
items: | ||
- key: ca.crt | ||
path: ca.crt | ||
- key: tls.crt | ||
path: tls.crt | ||
- key: tls.key | ||
path: tls.key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 37 additions & 26 deletions
63
docs/book/src/cronjob-tutorial/testdata/project/config/default/manager_webhook_patch.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,37 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: controller-manager | ||
namespace: system | ||
labels: | ||
app.kubernetes.io/name: project | ||
app.kubernetes.io/managed-by: kustomize | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- name: manager | ||
ports: | ||
- containerPort: 9443 | ||
name: webhook-server | ||
protocol: TCP | ||
volumeMounts: | ||
- mountPath: /tmp/k8s-webhook-server/serving-certs | ||
name: cert | ||
readOnly: true | ||
volumes: | ||
- name: cert | ||
secret: | ||
defaultMode: 420 | ||
secretName: webhook-server-cert | ||
# This patch adds the args and volumes to allow the manager to use the webhook-server certs | ||
# Ensure the ports field exists in the container | ||
- op: add | ||
path: /spec/template/spec/containers/0/ports | ||
value: [] | ||
# Add the webhook-server port if it does not already exist | ||
- op: add | ||
path: /spec/template/spec/containers/0/ports/- | ||
value: | ||
containerPort: 9443 | ||
name: webhook-server | ||
protocol: TCP | ||
|
||
# Ensure the volumeMounts field exists in the container | ||
- op: add | ||
path: /spec/template/spec/containers/0/volumeMounts | ||
value: [] | ||
# Add the serving-cert volume mount if it does not already exist | ||
- op: add | ||
path: /spec/template/spec/containers/0/volumeMounts/- | ||
value: | ||
mountPath: /tmp/k8s-webhook-server/serving-certs | ||
name: cert | ||
readOnly: true | ||
|
||
# Ensure the volumes field exists in the pod spec | ||
- op: add | ||
path: /spec/template/spec/volumes | ||
value: [] | ||
# Add the cert volume if it does not already exist | ||
- op: add | ||
path: /spec/template/spec/volumes/- | ||
value: | ||
name: cert | ||
secret: | ||
defaultMode: 420 | ||
secretName: webhook-server-cert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 43 additions & 21 deletions
64
...rc/getting-started/testdata/project/config/default/certmanager_metrics_manager_patch.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,43 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: controller-manager | ||
namespace: system | ||
labels: | ||
app.kubernetes.io/name: project | ||
app.kubernetes.io/managed-by: kustomize | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- name: manager | ||
volumeMounts: | ||
- mountPath: /tmp/k8s-metrics-server/metrics-certs | ||
name: metrics-certs | ||
readOnly: true | ||
volumes: | ||
- name: metrics-certs | ||
secret: | ||
secretName: metrics-server-cert | ||
# This patch adds the args and volumes to allow the manager to use the metrics-server certs | ||
# Ensure the volumeMounts field exists by creating it if missing | ||
- op: add | ||
path: /spec/template/spec/containers/0/volumeMounts | ||
value: [] | ||
# Add the volume mount for the serving certificates | ||
- op: add | ||
path: /spec/template/spec/containers/0/volumeMounts/- | ||
value: | ||
mountPath: /tmp/k8s-metrics-server/serving-certs | ||
name: metrics-certs | ||
readOnly: true | ||
# Add the cert-dir argument | ||
- op: add | ||
path: /spec/template/spec/containers/0/args/- | ||
value: --cert-dir=/tmp/k8s-metrics-server/serving-certs | ||
# Add the cert-name argument | ||
- op: add | ||
path: /spec/template/spec/containers/0/args/- | ||
value: --cert-name=/tmp/k8s-metrics-server/serving-certs/tls.crt | ||
# Add the cert-key argument | ||
- op: add | ||
path: /spec/template/spec/containers/0/args/- | ||
value: --cert-key=/tmp/k8s-metrics-server/serving-certs/tls.key | ||
# Ensure the volumes field exists by creating it if missing | ||
- op: add | ||
path: /spec/template/spec/volumes | ||
value: [] | ||
# Add the volume for the serving certificates | ||
- op: add | ||
path: /spec/template/spec/volumes/- | ||
value: | ||
name: metrics-certs | ||
secret: | ||
secretName: metrics-server-cert | ||
optional: false | ||
items: | ||
- key: ca.crt | ||
path: ca.crt | ||
- key: tls.crt | ||
path: tls.crt | ||
- key: tls.key | ||
path: tls.key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.