Skip to content

Commit 57d57d8

Browse files
Merge pull request #368 from vikaschoudhary16/metrics-on-https
Expose metric endpoint on https
2 parents 474e14e + 5d2b38b commit 57d57d8

9 files changed

+154
-12
lines changed

cmd/machine-api-operator/start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func startMetricsCollectionAndServer(ctx *ControllerContext) {
145145
metricsPort = v
146146
}
147147
glog.V(4).Info("Starting server to serve prometheus metrics")
148-
go startHTTPMetricServer(fmt.Sprintf(":%d", metricsPort))
148+
go startHTTPMetricServer(fmt.Sprintf("localhost:%d", metricsPort))
149149
}
150150

151151
func startHTTPMetricServer(metricsPort string) {
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
---
2+
apiVersion: apps/v1beta2
3+
kind: Deployment
4+
metadata:
5+
name: machine-api-operator
6+
namespace: openshift-machine-api
7+
labels:
8+
k8s-app: machine-api-operator
9+
spec:
10+
replicas: 1
11+
selector:
12+
matchLabels:
13+
k8s-app: machine-api-operator
14+
template:
15+
metadata:
16+
labels:
17+
k8s-app: machine-api-operator
18+
spec:
19+
priorityClassName: system-node-critical
20+
serviceAccountName: machine-api-operator
21+
containers:
22+
- name: kube-rbac-proxy
23+
image: quay.io/openshift/origin-kube-rbac-proxy:4.2.0
24+
args:
25+
- "--secure-listen-address=0.0.0.0:8443"
26+
- "--upstream=http://localhost:8080/"
27+
- "--config-file=/etc/kube-rbac-proxy/config-file.yaml"
28+
- "--logtostderr=true"
29+
- "--v=10"
30+
ports:
31+
- containerPort: 8443
32+
name: https
33+
volumeMounts:
34+
- name: config
35+
mountPath: /etc/kube-rbac-proxy
36+
- name: machine-api-operator
37+
image: docker.io/openshift/origin-machine-api-operator:v4.0.0
38+
command:
39+
- "/machine-api-operator"
40+
args:
41+
- "start"
42+
- "--images-json=/etc/machine-api-operator-config/images/images.json"
43+
- "--alsologtostderr"
44+
- "--v=3"
45+
env:
46+
- name: RELEASE_VERSION
47+
value: "0.0.1-snapshot"
48+
- name: COMPONENT_NAMESPACE
49+
valueFrom:
50+
fieldRef:
51+
fieldPath: metadata.namespace
52+
- name: METRICS_PORT
53+
value: "8080"
54+
resources:
55+
requests:
56+
cpu: 10m
57+
memory: 50Mi
58+
volumeMounts:
59+
- name: images
60+
mountPath: /etc/machine-api-operator-config/images
61+
nodeSelector:
62+
node-role.kubernetes.io/master: ""
63+
restartPolicy: Always
64+
securityContext:
65+
runAsNonRoot: true
66+
runAsUser: 65534
67+
tolerations:
68+
- key: "node-role.kubernetes.io/master"
69+
operator: "Exists"
70+
effect: "NoSchedule"
71+
- key: "node.kubernetes.io/unreachable"
72+
operator: "Exists"
73+
effect: "NoExecute"
74+
tolerationSeconds: 120
75+
- key: "node.kubernetes.io/not-ready"
76+
operator: "Exists"
77+
effect: "NoExecute"
78+
tolerationSeconds: 120
79+
volumes:
80+
- name: config
81+
configMap:
82+
name: kube-rbac-proxy
83+
- name: images
84+
configMap:
85+
name: machine-api-operator-images

install/0000_30_machine-api-operator_09_rbac.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,14 @@ kind: ClusterRole
199199
metadata:
200200
name: machine-api-operator
201201
rules:
202-
202+
- apiGroups: ["authentication.k8s.io"]
203+
resources:
204+
- tokenreviews
205+
verbs: ["create"]
206+
- apiGroups: ["authorization.k8s.io"]
207+
resources:
208+
- subjectaccessreviews
209+
verbs: ["create"]
203210
- apiGroups:
204211
- config.openshift.io
205212
resources:
@@ -318,6 +325,12 @@ metadata:
318325
name: prometheus-k8s-machine-api-operator
319326
namespace: openshift-machine-api
320327
rules:
328+
- apiGroups:
329+
- ""
330+
resources:
331+
- namespace/metrics
332+
verbs:
333+
- get
321334
- apiGroups:
322335
- ""
323336
resources:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: kube-rbac-proxy
5+
namespace: openshift-machine-api
6+
data:
7+
config-file.yaml: |+
8+
authorization:
9+
resourceAttributes:
10+
apiVersion: v1
11+
resource: namespace
12+
subresource: metrics
13+
namespace: openshift-machine-api
14+

install/0000_30_machine-api-operator_10_service.yaml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@ kind: Service
44
metadata:
55
name: machine-api-operator
66
namespace: openshift-machine-api
7+
annotations:
8+
service.alpha.openshift.io/serving-cert-secret-name: machine-api-operator-tls
79
labels:
810
k8s-app: machine-api-operator
911
spec:
1012
type: ClusterIP
1113
ports:
12-
- name: metrics
13-
port: 8080
14-
targetPort: metrics
15-
protocol: TCP
14+
- name: https
15+
port: 8443
16+
targetPort: https
1617
selector:
1718
k8s-app: machine-api-operator
1819
sessionAffinity: None

install/0000_30_machine-api-operator_11_deployment.yaml

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,24 @@ spec:
1818
priorityClassName: system-node-critical
1919
serviceAccountName: machine-api-operator
2020
containers:
21+
- name: kube-rbac-proxy
22+
image: quay.io/openshift/origin-kube-rbac-proxy:4.2.0
23+
args:
24+
- "--secure-listen-address=0.0.0.0:8443"
25+
- "--upstream=http://localhost:8080/"
26+
- "--tls-cert-file=/etc/tls/private/tls.crt"
27+
- "--tls-private-key-file=/etc/tls/private/tls.key"
28+
- "--config-file=/etc/kube-rbac-proxy/config-file.yaml"
29+
- "--logtostderr=true"
30+
- "--v=10"
31+
ports:
32+
- containerPort: 8443
33+
name: https
34+
volumeMounts:
35+
- name: config
36+
mountPath: /etc/kube-rbac-proxy
37+
- mountPath: /etc/tls/private
38+
name: machine-api-operator-tls
2139
- name: machine-api-operator
2240
image: docker.io/openshift/origin-machine-api-operator:v4.0.0
2341
command:
@@ -36,9 +54,6 @@ spec:
3654
fieldPath: metadata.namespace
3755
- name: METRICS_PORT
3856
value: "8080"
39-
ports:
40-
- name: metrics
41-
containerPort: 8080
4257
resources:
4358
requests:
4459
cpu: 10m
@@ -65,6 +80,12 @@ spec:
6580
effect: "NoExecute"
6681
tolerationSeconds: 120
6782
volumes:
83+
- name: config
84+
configMap:
85+
name: kube-rbac-proxy
6886
- name: images
6987
configMap:
7088
name: machine-api-operator-images
89+
- name: machine-api-operator-tls
90+
secret:
91+
secretName: machine-api-operator-tls

install/0000_90_machine-api-operator_03_servicemonitor.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ spec:
99
endpoints:
1010
- bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token
1111
interval: 30s
12-
port: metrics
13-
scheme: http
12+
port: https
13+
scheme: https
14+
tlsConfig:
15+
caFile: /etc/prometheus/configmaps/serving-certs-ca-bundle/service-ca.crt
16+
serverName: machine-api-operator.openshift-machine-api.svc
1417
namespaceSelector:
1518
matchNames:
1619
- openshift-machine-api

install/image-references

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,7 @@ spec:
5454
from:
5555
kind: DockerImage
5656
name: quay.io/openshift/origin-ironic-static-ip-manager:v4.2.0
57+
- name: kube-rbac-proxy
58+
from:
59+
kind: DockerImage
60+
name: quay.io/openshift/origin-kube-rbac-proxy:4.2.0

kustomization.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ resources:
2626
- install/0000_30_machine-api-operator_07_machinehealthcheck.crd.yaml
2727
- install/0000_30_machine-api-operator_08_machinedisruptionbudget.crd.yaml
2828
- install/0000_30_machine-api-operator_09_rbac.yaml
29+
- install/0000_30_machine-api-operator_10_kube-rbac-proxy-config.yaml
2930
- install/0000_30_machine-api-operator_10_service.yaml
30-
- install/0000_30_machine-api-operator_11_deployment.yaml
31+
- config/machine-api-operator-deployment.yaml
3132
- install/0000_30_machine-api-operator_12_clusteroperator.yaml
3233

3334

0 commit comments

Comments
 (0)