Skip to content

Commit 280c674

Browse files
Merge pull request #682 from jpeeler/metrics-add-servicemonitor
fix(metrics): add service monitor config
2 parents 5019602 + 888b81c commit 280c674

22 files changed

+233
-10
lines changed

cmd/catalog/main.go

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ var (
5353
"debug", false, "use debug log level")
5454

5555
version = flag.Bool("version", false, "displays olm version")
56+
57+
tlsKeyPath = flag.String(
58+
"tls-key", "", "Path to use for private key (requires tls-cert)")
59+
60+
tlsCertPath = flag.String(
61+
"tls-cert", "", "Path to use for certificate key (requires tls-key)")
5662
)
5763

5864
func init() {
@@ -83,17 +89,33 @@ func main() {
8389
}
8490
}
8591

92+
logger := log.New()
93+
if *debug {
94+
logger.SetLevel(log.DebugLevel)
95+
}
96+
logger.Infof("log level %s", logger.Level)
97+
98+
var useTLS bool
99+
if *tlsCertPath != "" && *tlsKeyPath == "" || *tlsCertPath == "" && *tlsKeyPath != "" {
100+
logger.Warn("both --tls-key and --tls-crt must be provided for TLS to be enabled, falling back to non-https")
101+
} else if *tlsCertPath == "" && *tlsKeyPath == "" {
102+
logger.Info("TLS keys not set, using non-https")
103+
} else {
104+
useTLS = true
105+
}
106+
86107
// Serve a health check.
87108
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
88109
w.WriteHeader(http.StatusOK)
89110
})
90111
go http.ListenAndServe(":8080", nil)
91112

92-
logger := log.New()
93-
if *debug {
94-
logger.SetLevel(log.DebugLevel)
113+
http.Handle("/metrics", promhttp.Handler())
114+
if useTLS {
115+
go http.ListenAndServeTLS(":8081", *tlsCertPath, *tlsKeyPath, nil)
116+
} else {
117+
go http.ListenAndServe(":8081", nil)
95118
}
96-
logger.Infof("log level %s", logger.Level)
97119

98120
// create a config client for operator status
99121
config, err := clientcmd.BuildConfigFromFlags("", *kubeConfigPath)
@@ -112,9 +134,6 @@ func main() {
112134
log.Panicf("error configuring operator: %s", err.Error())
113135
}
114136

115-
http.Handle("/metrics", promhttp.Handler())
116-
go http.ListenAndServe(":8081", nil)
117-
118137
ready, done, sync := catalogOperator.Run(stopCh)
119138
<-ready
120139

cmd/olm/main.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ var (
4949
"debug", false, "use debug log level")
5050

5151
version = flag.Bool("version", false, "displays olm version")
52+
53+
tlsKeyPath = flag.String(
54+
"tls-key", "", "Path to use for private key (requires tls-cert)")
55+
56+
tlsCertPath = flag.String(
57+
"tls-cert", "", "Path to use for certificate key (requires tls-key)")
5258
)
5359

5460
func init() {
@@ -113,14 +119,27 @@ func main() {
113119
log.Fatalf("error configuring operator: %s", err.Error())
114120
}
115121

122+
var useTLS bool
123+
if *tlsCertPath != "" && *tlsKeyPath == "" || *tlsCertPath == "" && *tlsKeyPath != "" {
124+
logger.Warn("both --tls-key and --tls-crt must be provided for TLS to be enabled, falling back to non-https")
125+
} else if *tlsCertPath == "" && *tlsKeyPath == "" {
126+
logger.Info("TLS keys not set, using non-https")
127+
} else {
128+
useTLS = true
129+
}
130+
116131
// Serve a health check.
117132
http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
118133
w.WriteHeader(http.StatusOK)
119134
})
120135
go http.ListenAndServe(":8080", nil)
121136

122137
http.Handle("/metrics", promhttp.Handler())
123-
go http.ListenAndServe(":8081", nil)
138+
if useTLS {
139+
go http.ListenAndServeTLS(":8081", *tlsCertPath, *tlsKeyPath, nil)
140+
} else {
141+
go http.ListenAndServe(":8081", nil)
142+
}
124143

125144
ready, done, sync := operator.Run(stopCh)
126145
<-ready

deploy/chart/templates/0000_50_olm_00-namespace.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@ apiVersion: v1
22
kind: Namespace
33
metadata:
44
name: {{ .Values.namespace }}
5+
{{ if and .Values.installType (eq .Values.installType "ocp") }}
56
labels:
67
openshift.io/run-level: "1"
8+
openshift.io/cluster-monitoring: "true"
9+
{{ end }}
710
---
811
apiVersion: v1
912
kind: Namespace
1013
metadata:
1114
name: {{ .Values.operator_namespace }}
15+
{{ if and .Values.installType (eq .Values.installType "ocp") }}
1216
labels:
1317
openshift.io/run-level: "1"
18+
{{ end }}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{{ if and .Values.installType (eq .Values.installType "ocp") }}
2+
apiVersion: v1
3+
kind: Service
4+
metadata:
5+
name: olm-operator-metrics
6+
namespace: {{ .Values.namespace }}
7+
annotations:
8+
service.alpha.openshift.io/serving-cert-secret-name: olm-operator-serving-cert
9+
labels:
10+
app: olm-operator
11+
spec:
12+
type: ClusterIP
13+
ports:
14+
- name: https-metrics
15+
port: 8081
16+
protocol: TCP
17+
targetPort: metrics
18+
selector:
19+
app: olm-operator
20+
---
21+
apiVersion: v1
22+
kind: Service
23+
metadata:
24+
name: catalog-operator-metrics
25+
namespace: {{ .Values.namespace }}
26+
annotations:
27+
service.alpha.openshift.io/serving-cert-secret-name: catalog-operator-serving-cert
28+
labels:
29+
app: catalog-operator
30+
spec:
31+
type: ClusterIP
32+
ports:
33+
- name: https-metrics
34+
port: 8081
35+
protocol: TCP
36+
targetPort: metrics
37+
selector:
38+
app: catalog-operator
39+
{{ end }}

deploy/chart/templates/0000_50_olm_06-olm-operator.deployment.yaml renamed to deploy/chart/templates/0000_50_olm_07-olm-operator.deployment.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,21 @@ spec:
3737
- -writeStatusName
3838
- {{ .Values.writeStatusName }}
3939
{{- end }}
40+
{{- if .Values.olm.tlsCertPath }}
41+
- -tls-cert
42+
- {{ .Values.olm.tlsCertPath }}
43+
{{- end }}
44+
{{- if .Values.olm.tlsKeyPath }}
45+
- -tls-key
46+
- {{ .Values.olm.tlsKeyPath }}
47+
{{- end }}
4048
image: {{ .Values.olm.image.ref }}
4149
imagePullPolicy: {{ .Values.olm.image.pullPolicy }}
4250
ports:
4351
- containerPort: {{ .Values.olm.service.internalPort }}
52+
- containerPort: 8081
53+
name: metrics
54+
protocol: TCP
4455
livenessProbe:
4556
httpGet:
4657
path: /healthz
@@ -64,6 +75,18 @@ spec:
6475
resources:
6576
{{ toYaml .Values.olm.resources | indent 12 }}
6677
{{- end}}
78+
{{ if and .Values.installType (eq .Values.installType "ocp") }}
79+
volumeMounts:
80+
- mountPath: /var/run/secrets/serving-cert
81+
name: serving-cert
82+
{{ end }}
83+
{{ if and .Values.installType (eq .Values.installType "ocp") }}
84+
volumes:
85+
- name: serving-cert
86+
secret:
87+
secretName: olm-operator-serving-cert
88+
optional: true
89+
{{ end }}
6790
{{- if .Values.olm.nodeSelector }}
6891
nodeSelector:
6992
{{ toYaml .Values.olm.nodeSelector | indent 8 }}

deploy/chart/templates/0000_50_olm_07-catalog-operator.deployment.yaml renamed to deploy/chart/templates/0000_50_olm_08-catalog-operator.deployment.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,21 @@ spec:
3939
- -writeStatusName
4040
- {{ .Values.writeStatusNameCatalog }}
4141
{{- end }}
42+
{{- if .Values.olm.tlsCertPath }}
43+
- -tls-cert
44+
- {{ .Values.olm.tlsCertPath }}
45+
{{- end }}
46+
{{- if .Values.olm.tlsKeyPath }}
47+
- -tls-key
48+
- {{ .Values.olm.tlsKeyPath }}
49+
{{- end }}
4250
image: {{ .Values.catalog.image.ref }}
4351
imagePullPolicy: {{ .Values.catalog.image.pullPolicy }}
4452
ports:
4553
- containerPort: {{ .Values.catalog.service.internalPort }}
54+
- containerPort: 8081
55+
name: metrics
56+
protocol: TCP
4657
livenessProbe:
4758
httpGet:
4859
path: /healthz
@@ -55,6 +66,18 @@ spec:
5566
resources:
5667
{{ toYaml .Values.catalog.resources | indent 12 }}
5768
{{- end}}
69+
{{ if and .Values.installType (eq .Values.installType "ocp") }}
70+
volumeMounts:
71+
- mountPath: /var/run/secrets/serving-cert
72+
name: serving-cert
73+
{{ end }}
74+
{{ if and .Values.installType (eq .Values.installType "ocp") }}
75+
volumes:
76+
- name: serving-cert
77+
secret:
78+
secretName: catalog-operator-serving-cert
79+
optional: true
80+
{{ end }}
5881
{{- if .Values.catalog.nodeSelector }}
5982
nodeSelector:
6083
{{ toYaml .Values.catalog.nodeSelector | indent 8 }}

0 commit comments

Comments
 (0)