Skip to content

Commit

Permalink
chore(RHTAPWATCH-568): Add authentication to Service and ServiceMonitor
Browse files Browse the repository at this point in the history
Signed-off-by: Kousalya Lakshmanan <[email protected]>
  • Loading branch information
klakshma21 committed Jan 29, 2024
1 parent 94972fb commit cc72cbe
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
apiVersion: v1
kind: Namespace
metadata:
name: appstudio-grafana-datasource-exporter
spec: {}
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: availability-exporter-sa
namespace: appstudio-grafana-datasource-exporter
---
apiVersion: v1
kind: Secret
metadata:
name: availability-exporter-sa
namespace: appstudio-grafana-datasource-exporter
annotations:
kubernetes.io/service-account.name: availability-exporter-sa
type: kubernetes.io/service-account-token
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: availability-exporter-cluster-role
rules:
- nonResourceURLs:
- /metrics
verbs:
- get
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: availability-exporter-cluster-role-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: availability-exporter-cluster-role
subjects:
- kind: ServiceAccount
name: availability-exporter-sa
namespace: appstudio-grafana-datasource-exporter
---
apiVersion: v1
kind: Service
metadata:
name: availability-exporter-service
namespace: appstudio-grafana-datasource-exporter
labels:
app: grafana-datasource-exporter
spec:
ports:
- name: https
port: 8443
targetPort: https
selector:
app: grafana-datasource-exporter
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: availability-exporter-service-deployment
namespace: appstudio-grafana-datasource-exporter
spec:
replicas: 1
selector:
matchLabels:
app: grafana-datasource-exporter
template:
metadata:
labels:
app: grafana-datasource-exporter
spec:
name: availability-exporter-sa
containers:
- name: grafana-datasource-exporter
image: exporter:latest
image: quay.io/redhat-appstudio/o11y-prometheus-exporters:v0.1
ports:
- containerPort: 8443
name: https
resources:
limits:
cpu: 100m
memory: 100Mi
requests:
cpu: 100m
memory: 10Mi
securityContext:
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
runAsNonRoot: true
---
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: availability-metrics-reader
namespace: appstudio-grafana-datasource-exporter
spec:
endpoints:
- path: /metrics
port: web
scheme: https
bearerTokenSecret:
name: "availability-exporter-sa"
key: token
tlsConfig:
insecureSkipVerify: true
selector:
matchLabels:
app: grafana-datasource-exporter
5 changes: 3 additions & 2 deletions exporters/dsexporter/dsexporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ func main() {
exporter := NewCustomCollector()
reg.MustRegister(exporter)

fmt.Println("Server is listening on http://localhost:8443/metrics")

http.Handle("/metrics", promhttp.HandlerFor(
reg,
promhttp.HandlerOpts{
EnableOpenMetrics: true,
Registry: reg,
},
))
fmt.Println("Server is listening on http://localhost:8090/metrics")
http.ListenAndServe(":8090", nil)
http.ListenAndServe(":8443", nil)
}

0 comments on commit cc72cbe

Please sign in to comment.