Skip to content

Commit 71ddcba

Browse files
authored
Merge pull request #45 from Gregory-Pereira/ocp-use-authorization-credentials-for-metrics
use authorization.credentials instead of bearerToekn
2 parents 06862a9 + 4889964 commit 71ddcba

5 files changed

Lines changed: 51 additions & 15 deletions

File tree

config/default/kustomization.yaml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,6 @@ patches:
4141
target:
4242
kind: Deployment
4343

44-
45-
replacements:
46-
- source:
47-
kind: Deployment
48-
name: controller-manager
49-
fieldPath: metadata.namespace
50-
targets:
51-
- select:
52-
kind: ServiceMonitor
53-
group: monitoring.coreos.com
54-
version: v1
55-
name: controller-manager-metrics-monitor
56-
fieldPaths:
57-
- spec.namespaceSelector.matchNames.0
58-
5944
# Uncomment the patches line if you enable Metrics and CertManager
6045
# [METRICS-WITH-CERTS] To enable metrics protected with certManager, uncomment the following line.
6146
# This patch will protect the metrics with certManager self-signed certs.

config/openshift/kustomization.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ kind: Kustomization
44
resources:
55
- ../default
66
- cluster-monitoring-view-binding.yaml
7+
- metrics-reader-token.yaml
8+
- prometheus-metrics-auth-binding.yaml
79

810
patches:
911
- path: configmap-patch.yaml
@@ -22,5 +24,9 @@ patches:
2224
target:
2325
kind: Deployment
2426
name: controller-manager
27+
- path: monitor-auth-patch.yaml
28+
target:
29+
kind: ServiceMonitor
30+
name: controller-manager-metrics-monitor
2531

2632
namespace: workload-variant-autoscaler-system
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Long-lived SA token for Prometheus to authenticate to the WVA metrics endpoint.
2+
# Required on OpenShift because user-workload-monitoring Prometheus rejects
3+
# bearerTokenFile for security. The ServiceMonitor is patched (via
4+
# monitor-auth-patch.yaml) to reference this Secret instead.
5+
apiVersion: v1
6+
kind: Secret
7+
metadata:
8+
name: workload-variant-autoscaler-metrics-reader-token
9+
annotations:
10+
kubernetes.io/service-account.name: workload-variant-autoscaler-controller-manager
11+
type: kubernetes.io/service-account-token
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Replace bearerTokenFile with authorization.credentials for OpenShift
2+
# user-workload-monitoring compatibility. The user-workload Prometheus Operator
3+
# rejects bearerTokenFile ("it accesses file system via bearer token file which
4+
# Prometheus specification prohibits").
5+
apiVersion: monitoring.coreos.com/v1
6+
kind: ServiceMonitor
7+
metadata:
8+
name: controller-manager-metrics-monitor
9+
spec:
10+
endpoints:
11+
- port: https
12+
path: /metrics
13+
interval: 10s
14+
scheme: https
15+
tlsConfig:
16+
insecureSkipVerify: true
17+
authorization:
18+
credentials:
19+
name: workload-variant-autoscaler-metrics-reader-token
20+
key: token
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Grant the OpenShift user-workload-monitoring Prometheus SA permission to
2+
# authenticate to the WVA metrics endpoint (tokenreviews + subjectaccessreviews).
3+
apiVersion: rbac.authorization.k8s.io/v1
4+
kind: ClusterRoleBinding
5+
metadata:
6+
name: workload-variant-autoscaler-ocp-prometheus-metrics-auth
7+
roleRef:
8+
apiGroup: rbac.authorization.k8s.io
9+
kind: ClusterRole
10+
name: workload-variant-autoscaler-metrics-auth-role
11+
subjects:
12+
- kind: ServiceAccount
13+
name: prometheus-k8s
14+
namespace: openshift-user-workload-monitoring

0 commit comments

Comments
 (0)