Skip to content

Commit

Permalink
Update helm charts with deployment support (#90)
Browse files Browse the repository at this point in the history
* Update helm charts with deployment support

* Add serviceMonitor to the chart
  • Loading branch information
Yuni-sa authored Oct 4, 2023
1 parent 605cf95 commit a0e15fa
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 1 deletion.
66 changes: 66 additions & 0 deletions charts/kor/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{{- if .Values.prometheusExporter.enabled -}}
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ .Values.prometheusExporter.name }}
labels:
app: {{ .Values.prometheusExporter.name }}
spec:
{{- with .Values.prometheusExporter.deployment.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent }}
{{- end }}
replicas: {{ .Values.prometheusExporter.deployment.replicaCount | default 1 }}
selector:
matchLabels:
app: {{ .Values.prometheusExporter.name }}
template:
metadata:
labels:
app: {{ .Values.prometheusExporter.name }}
spec:
serviceAccountName: {{ include "kor.serviceAccountName" . }}
containers:
- name: "{{ .Values.prometheusExporter.name }}-container"
{{- with .Values.prometheusExporter.deployment.securityContext }}
securityContext:
{{ toYaml . | nindent 12 }}
{{- end }}
image: "{{ .Values.prometheusExporter.deployment.image.repository }}:{{ .Values.prometheusExporter.deployment.image.tag }}"
command: ["/bin/sh", "-c"]
args: ["{{ .Values.prometheusExporter.deployment.command }}"]
ports:
- containerPort: 8080
name: http
protocol: TCP
{{- with .Values.prometheusExporter.deployment.resources }}
resources:
{{- toYaml . | nindent 12 }}
{{- end }}
{{- if .Values.prometheusExporter.exporterInterval }}
env:
- name: EXPORTER_INTERVAL
value: {{ .Values.prometheusExporter.exporterInterval }}
{{- end}}
{{- with .Values.prometheusExporter.deployment.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.prometheusExporter.deployment.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.prometheusExporter.deployment.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
terminationMessagePath: "/dev/termination-log"
imagePullPolicy: {{ .Values.prometheusExporter.deployment.imagePullPolicy }}
restartPolicy: {{ .Values.prometheusExporter.deployment.restartPolicy }}
terminationGracePeriodSeconds: 30
dnsPolicy: ClusterFirst
{{- with .Values.prometheusExporter.deployment.podSecurityContext }}
securityContext:
{{- toYaml . | nindent 8}}
{{- end }}
{{- end }}
20 changes: 20 additions & 0 deletions charts/kor/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{{- if .Values.prometheusExporter.enabled -}}
apiVersion: v1
kind: Service
metadata:
name: {{ .Values.prometheusExporter.name }}
annotations:
prometheus.io/scrape: "true"
prometheus.io/path: /metrics
prometheus.io/port: "8080"
labels:
app: {{ .Values.prometheusExporter.name }}
spec:
type: {{ .Values.prometheusExporter.service.type }}
selector:
app: {{ .Values.prometheusExporter.name }}
ports:
- name: metrics
port: {{ .Values.prometheusExporter.service.port }}
targetPort: http
{{- end }}
44 changes: 44 additions & 0 deletions charts/kor/templates/servicemonitor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{{- if and ( .Capabilities.APIVersions.Has "monitoring.coreos.com/v1" ) ( .Values.prometheusExporter.serviceMonitor.enabled ) }}
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
labels:
app: {{ .Values.prometheusExporter.name }}
name: {{ .Values.prometheusExporter.name }}
{{- if .Values.prometheusExporter.serviceMonitor.namespace }}
namespace: {{ .Values.prometheusExporter.serviceMonitor.namespace }}
{{- end }}
spec:
endpoints:
- targetPort: 8080
{{- if .Values.prometheusExporter.serviceMonitor.interval }}
interval: {{ .Values.prometheusExporter.serviceMonitor.interval }}
{{- end }}
{{- if .Values.prometheusExporter.serviceMonitor.telemetryPath }}
path: {{ .Values.prometheusExporter.serviceMonitor.telemetryPath }}
{{- end }}
{{- if .Values.prometheusExporter.serviceMonitor.timeout }}
scrapeTimeout: {{ .Values.prometheusExporter.serviceMonitor.timeout }}
{{- end }}
{{- if .Values.prometheusExporter.serviceMonitor.metricRelabelings }}
metricRelabelings:
{{ toYaml .Values.prometheusExporter.serviceMonitor.metricRelabelings | indent 4 }}
{{- end }}
{{- if .Values.prometheusExporter.serviceMonitor.relabelings }}
relabelings:
{{ toYaml .Values.prometheusExporter.serviceMonitor.relabelings | indent 4 }}
{{- end }}
jobLabel: {{ .Values.prometheusExporter.name }}
namespaceSelector:
matchNames:
- {{ .Release.Namespace }}
selector:
matchLabels:
app: {{ .Values.prometheusExporter.name }}
{{- if .Values.prometheusExporter.serviceMonitor.targetLabels }}
targetLabels:
{{- range .Values.prometheusExporter.serviceMonitor.targetLabels }}
- {{ . }}
{{- end }}
{{- end }}
{{- end }}
57 changes: 56 additions & 1 deletion charts/kor/values.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cronJob:
enabled: true
enabled: false
name: kor
schedule: "0 1 * * 1"
image:
Expand All @@ -14,6 +14,61 @@ cronJob:
successfulJobsHistoryLimit: 3
failedJobsHistoryLimit: 2

prometheusExporter:
enabled: true
name: kor-exporter
# time in minutes, default is 10 minutes
exporterInterval: ""
deployment:
image:
repository: yonahdissen/kor
tag: latest
command: kor exporter
restartPolicy: Always
imagePullPolicy: Always
imagePullSecrets: []
podSecurityContext: {}
replicaCount: 1
resources: {}
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi

securityContext: {}
# capabilities:
# drop:
# - ALL
# readOnlyRootFilesystem: true
# runAsNonRoot: true
# runAsUser: 1000

nodeSelector: {}
tolerations: []
affinity: {}

service:
type: ClusterIP
port: 8080

serviceMonitor:
enabled: true
# Set the namespace the ServiceMonitor should be deployed, if empty namespace will be .Release.Namespace
namespace: ""
# Service monitor labels
labels: {}
# Set how frequently Prometheus should scrape
interval: 30s
telemetryPath: /metrics
# Set timeout for scrape
timeout: 10s
relabelings: []
# Set of labels to transfer on the Kubernetes Service onto the target.
targetLabels: []
metricRelabelings: []

serviceAccount:
# Specifies whether a service account should be created
create: true
Expand Down

0 comments on commit a0e15fa

Please sign in to comment.