-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Patch to give optional option to enable ServiceMonitor to use cer…
…t-manager-managed serving-cert with TLS verification Adds a patch to configure ServiceMonitor with `insecureSkipVerify: false` to ensure TLS verification using cert-manager certificates. Updates documentation and corrects misaligned comments.
- Loading branch information
1 parent
c331b70
commit f8ba05c
Showing
31 changed files
with
396 additions
and
66 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
9 changes: 9 additions & 0 deletions
9
docs/book/src/cronjob-tutorial/testdata/project/config/prometheus/kustomization.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,2 +1,11 @@ | ||
resources: | ||
- monitor.yaml | ||
|
||
# [PROMETHEUS WITH CERTMANAGER] The following patch configures the ServiceMonitor in ../prometheus | ||
# to securely reference certificates created and managed by cert-manager. | ||
# Additionally, ensure that you uncomment the [WEBHOOK] patch under config/default/kustomization.yaml | ||
# to mount the "serving-cert" secret in the Manager Deployment. | ||
#patches: | ||
# - path: monitor_tls_patch.yaml | ||
# target: | ||
# kind: ServiceMonitor |
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
22 changes: 22 additions & 0 deletions
22
docs/book/src/cronjob-tutorial/testdata/project/config/prometheus/monitor_tls_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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Patch for Prometheus ServiceMonitor to enable secure TLS configuration | ||
# using certificates managed by cert-manager | ||
apiVersion: monitoring.coreos.com/v1 | ||
kind: ServiceMonitor | ||
metadata: | ||
name: controller-manager-metrics-monitor | ||
namespace: system | ||
spec: | ||
endpoints: | ||
- tlsConfig: | ||
insecureSkipVerify: false | ||
ca: | ||
secret: | ||
name: serving-cert | ||
key: ca.crt | ||
cert: | ||
secret: | ||
name: serving-cert | ||
key: tls.crt | ||
keySecret: | ||
name: serving-cert | ||
key: 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
9 changes: 9 additions & 0 deletions
9
docs/book/src/getting-started/testdata/project/config/prometheus/kustomization.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,2 +1,11 @@ | ||
resources: | ||
- monitor.yaml | ||
|
||
# [PROMETHEUS WITH CERTMANAGER] The following patch configures the ServiceMonitor in ../prometheus | ||
# to securely reference certificates created and managed by cert-manager. | ||
# Additionally, ensure that you uncomment the [WEBHOOK] patch under config/default/kustomization.yaml | ||
# to mount the "serving-cert" secret in the Manager Deployment. | ||
#patches: | ||
# - path: monitor_tls_patch.yaml | ||
# target: | ||
# kind: ServiceMonitor |
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
22 changes: 22 additions & 0 deletions
22
docs/book/src/getting-started/testdata/project/config/prometheus/monitor_tls_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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Patch for Prometheus ServiceMonitor to enable secure TLS configuration | ||
# using certificates managed by cert-manager | ||
apiVersion: monitoring.coreos.com/v1 | ||
kind: ServiceMonitor | ||
metadata: | ||
name: controller-manager-metrics-monitor | ||
namespace: system | ||
spec: | ||
endpoints: | ||
- tlsConfig: | ||
insecureSkipVerify: false | ||
ca: | ||
secret: | ||
name: serving-cert | ||
key: ca.crt | ||
cert: | ||
secret: | ||
name: serving-cert | ||
key: tls.crt | ||
keySecret: | ||
name: serving-cert | ||
key: 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
9 changes: 9 additions & 0 deletions
9
docs/book/src/multiversion-tutorial/testdata/project/config/prometheus/kustomization.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,2 +1,11 @@ | ||
resources: | ||
- monitor.yaml | ||
|
||
# [PROMETHEUS WITH CERTMANAGER] The following patch configures the ServiceMonitor in ../prometheus | ||
# to securely reference certificates created and managed by cert-manager. | ||
# Additionally, ensure that you uncomment the [WEBHOOK] patch under config/default/kustomization.yaml | ||
# to mount the "serving-cert" secret in the Manager Deployment. | ||
#patches: | ||
# - path: monitor_tls_patch.yaml | ||
# target: | ||
# kind: ServiceMonitor |
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
22 changes: 22 additions & 0 deletions
22
.../book/src/multiversion-tutorial/testdata/project/config/prometheus/monitor_tls_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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Patch for Prometheus ServiceMonitor to enable secure TLS configuration | ||
# using certificates managed by cert-manager | ||
apiVersion: monitoring.coreos.com/v1 | ||
kind: ServiceMonitor | ||
metadata: | ||
name: controller-manager-metrics-monitor | ||
namespace: system | ||
spec: | ||
endpoints: | ||
- tlsConfig: | ||
insecureSkipVerify: false | ||
ca: | ||
secret: | ||
name: serving-cert | ||
key: ca.crt | ||
cert: | ||
secret: | ||
name: serving-cert | ||
key: tls.crt | ||
keySecret: | ||
name: serving-cert | ||
key: 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
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
67 changes: 67 additions & 0 deletions
67
...s/common/kustomize/v2/scaffolds/internal/templates/config/prometheus/monitor_tls_patch.go
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
Copyright 2024 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package prometheus | ||
|
||
import ( | ||
"path/filepath" | ||
|
||
"sigs.k8s.io/kubebuilder/v4/pkg/machinery" | ||
) | ||
|
||
var _ machinery.Template = &ServiceMonitorPatch{} | ||
|
||
// ServiceMonitorPatch scaffolds a file that defines the patch for the ServiceMonitor | ||
// to use cert-manager managed certificates for secure TLS configuration. | ||
type ServiceMonitorPatch struct { | ||
machinery.TemplateMixin | ||
machinery.ProjectNameMixin | ||
} | ||
|
||
// SetTemplateDefaults implements file.Template | ||
func (f *ServiceMonitorPatch) SetTemplateDefaults() error { | ||
if f.Path == "" { | ||
f.Path = filepath.Join("config", "prometheus", "monitor_tls_patch.yaml") | ||
} | ||
|
||
f.TemplateBody = serviceMonitorPatchTemplate | ||
|
||
return nil | ||
} | ||
|
||
const serviceMonitorPatchTemplate = `# Patch for Prometheus ServiceMonitor to enable secure TLS configuration | ||
# using certificates managed by cert-manager | ||
apiVersion: monitoring.coreos.com/v1 | ||
kind: ServiceMonitor | ||
metadata: | ||
name: controller-manager-metrics-monitor | ||
namespace: system | ||
spec: | ||
endpoints: | ||
- tlsConfig: | ||
insecureSkipVerify: false | ||
ca: | ||
secret: | ||
name: serving-cert | ||
key: ca.crt | ||
cert: | ||
secret: | ||
name: serving-cert | ||
key: tls.crt | ||
keySecret: | ||
name: serving-cert | ||
key: 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.