From 9254ffa8387d4db87b420039220ddcfd681006ee Mon Sep 17 00:00:00 2001 From: AH | Dromaniuk Date: Fri, 10 Sep 2021 14:24:27 +0300 Subject: [PATCH 1/5] Add helm-chart (#14) --- charts/exporter/Chart.yaml | 6 +++ charts/exporter/templates/_helpers.tpl | 39 ++++++++++++++++ charts/exporter/templates/deployment.yaml | 45 +++++++++++++++++++ .../prometheus-operator-probes/demo.yaml | 17 +++++++ charts/exporter/templates/service.yaml | 16 +++++++ charts/exporter/values.yaml | 41 +++++++++++++++++ 6 files changed, 164 insertions(+) create mode 100644 charts/exporter/Chart.yaml create mode 100644 charts/exporter/templates/_helpers.tpl create mode 100644 charts/exporter/templates/deployment.yaml create mode 100644 charts/exporter/templates/prometheus-operator-probes/demo.yaml create mode 100644 charts/exporter/templates/service.yaml create mode 100644 charts/exporter/values.yaml diff --git a/charts/exporter/Chart.yaml b/charts/exporter/Chart.yaml new file mode 100644 index 00000000..a9b9defe --- /dev/null +++ b/charts/exporter/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: ssl_exporter +description: A Helm chart for SSL Exporter +type: application +version: 0.1.0 +appVersion: 2.3.1 \ No newline at end of file diff --git a/charts/exporter/templates/_helpers.tpl b/charts/exporter/templates/_helpers.tpl new file mode 100644 index 00000000..4c0cbfbf --- /dev/null +++ b/charts/exporter/templates/_helpers.tpl @@ -0,0 +1,39 @@ +{{/***************************************************************************** + + General templates + +*****************************************************************************/}} + +{{- define "name" -}}{{- /****************************************************** +Expand the name of the chart +***************************************************************************/ -}} +{{- $.Chart.Name | trunc 63 | trimSuffix "-" }} +{{- end }} + + +{{- define "releasename" -}}{{- /********************************************** +Expand the name of the instance +***************************************************************************/ -}} +{{- $.Release.Name | trunc 63 | trimSuffix "-" }} +{{- end }} + + +{{- define "labels" -}}{{- /**************************************************** +Define controller labels +***************************************************************************/ -}} +app.kubernetes.io/name: {{ include "name" $ }} +helm.sh/chart: {{ $.Chart.Name }}-{{ $.Chart.Version | replace "+" "_" }} +app.kubernetes.io/managed-by: {{ $.Release.Service }} +app.kubernetes.io/instance: {{ $.Release.Name }} +app.kubernetes.io/version: {{ $.Chart.AppVersion }} +{{- end }} + + +{{- define "matchLabels" -}}{{- /********************************************** + Define labels are used by controllers to find their pods +***************************************************************************/ -}} +app.kubernetes.io/name: {{ include "name" $ }} +app.kubernetes.io/managed-by: {{ $.Release.Service }} +app.kubernetes.io/instance: {{ $.Release.Name }} +{{- end }} + diff --git a/charts/exporter/templates/deployment.yaml b/charts/exporter/templates/deployment.yaml new file mode 100644 index 00000000..4fe62d2e --- /dev/null +++ b/charts/exporter/templates/deployment.yaml @@ -0,0 +1,45 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + namespace: {{ $.Release.Namespace | quote }} + name: {{ include "releasename" $ | quote }} + labels: {{- include "labels" $ | nindent 4 }} + annotations: {{- toYaml $.Values.annotations | nindent 4 }} +spec: + selector: + matchLabels: {{- include "matchLabels" $ | nindent 6 }} + replicas: {{ int $.Values.replicaCount }} + strategy: + type: RollingUpdate + revisionHistoryLimit: 3 + + template: + metadata: + labels: {{- include "labels" $ | nindent 8 }} + spec: + restartPolicy: Always + terminationGracePeriodSeconds: {{ $.Values.terminationGracePeriodSeconds }} + nodeSelector: {{- toYaml $.Values.nodeSelector | nindent 8 }} + tolerations: {{- toYaml $.Values.tolerations | nindent 8 }} + affinity: {{- toYaml $.Values.affinity | nindent 8 }} + securityContext: {{- toYaml $.Values.securityContext | nindent 8 }} + imagePullSecrets: {{- toYaml $.Values.imagePullSecrets | nindent 8 }} + containers: + + - name: exporter + image: ribbybibby/ssl-exporter:v{{ $.Chart.AppVersion }} + imagePullPolicy: {{ $.Values.podImagePullPolicy | quote }} + resources: {{ toYaml $.Values.resources | nindent 12 }} + ports: + - name: exporter + containerPort: 9219 + readinessProbe: + {{- toYaml $.Values.probes.readiness | nindent 12 }} + httpGet: + port: exporter + path: / + livenessProbe: + {{- toYaml $.Values.probes.liveness | nindent 12 }} + httpGet: + port: exporter + path: / diff --git a/charts/exporter/templates/prometheus-operator-probes/demo.yaml b/charts/exporter/templates/prometheus-operator-probes/demo.yaml new file mode 100644 index 00000000..638f0af4 --- /dev/null +++ b/charts/exporter/templates/prometheus-operator-probes/demo.yaml @@ -0,0 +1,17 @@ +{{- if $.Values.prometheusOperator.enableExampleProbes }} +apiVersion: monitoring.coreos.com/v1 +kind: Probe +metadata: + name: probe-demo + labels: + release: prometheus-operator + {{- include "labels" $ | nindent 4 }} +spec: + prober: + url: {{ printf "%s.%s.svc" (include "releasename" .) $.Release.Namespace | quote }} + module: http + targets: + staticConfig: + static: + - "https://demo.do.prometheus.io" +{{- end }} diff --git a/charts/exporter/templates/service.yaml b/charts/exporter/templates/service.yaml new file mode 100644 index 00000000..2fb6530d --- /dev/null +++ b/charts/exporter/templates/service.yaml @@ -0,0 +1,16 @@ +apiVersion: v1 +kind: Service +metadata: + namespace: {{ $.Release.Namespace | quote }} + name: {{ include "releasename" $ | quote }} + labels: {{- include "labels" $ | nindent 4 }} + annotations: {{- toYaml $.Values.service.annotations | nindent 4 }} +spec: + ports: + - name: exporter + port: {{ $.Values.service.port }} + protocol: TCP + targetPort: exporter + selector: {{- include "matchLabels" $ | nindent 4 }} + sessionAffinity: {{ $.Values.service.sessionAffinity | quote }} + type: {{ $.Values.service.type | quote }} diff --git a/charts/exporter/values.yaml b/charts/exporter/values.yaml new file mode 100644 index 00000000..8f354ce7 --- /dev/null +++ b/charts/exporter/values.yaml @@ -0,0 +1,41 @@ +annotations: {} +replicaCount: 1 +imagePullPolicy: Always +imagePullSecrets: [] +nodeSelector: {} +tolerations: [] +affinity: {} +securityContext: {} + # fsGroup: 1001 + # runAsGroup: 1001 + # runAsNonRoot: true + # runAsUser: 1001 +resources: {} + # limits: + # cpu: 500m + # memory: 256Mi + # requests: + # cpu: 200m + # memory: 128Mi +terminationGracePeriodSeconds: 5 +probes: + readiness: + initialDelaySeconds: 3 + periodSeconds: 5 + timeoutSeconds: 5 + failureThreshold: 3 + successThreshold: 1 + liveness: + initialDelaySeconds: 3 + periodSeconds: 5 + timeoutSeconds: 5 + failureThreshold: 3 + successThreshold: 1 +service: + enabled: true + annotations: {} + port: 80 + sessionAffinity: None + +prometheusOperator: + enableExampleProbes: false \ No newline at end of file From faef101f25abe418baacb2c17a3a803e735a526d Mon Sep 17 00:00:00 2001 From: AH | Dromaniuk Date: Mon, 13 Sep 2021 10:15:53 +0300 Subject: [PATCH 2/5] Fix imagePullPolicy default value --- charts/exporter/values.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/exporter/values.yaml b/charts/exporter/values.yaml index 8f354ce7..107830a6 100644 --- a/charts/exporter/values.yaml +++ b/charts/exporter/values.yaml @@ -1,6 +1,6 @@ annotations: {} replicaCount: 1 -imagePullPolicy: Always +imagePullPolicy: IfNotPresent imagePullSecrets: [] nodeSelector: {} tolerations: [] From 1dc956030625c8509df32179ddaca42fa90c4f2c Mon Sep 17 00:00:00 2001 From: AH | Dromaniuk Date: Mon, 13 Sep 2021 10:17:04 +0300 Subject: [PATCH 3/5] Remove empty lines in Deployment --- charts/exporter/templates/deployment.yaml | 2 -- 1 file changed, 2 deletions(-) diff --git a/charts/exporter/templates/deployment.yaml b/charts/exporter/templates/deployment.yaml index 4fe62d2e..268c4692 100644 --- a/charts/exporter/templates/deployment.yaml +++ b/charts/exporter/templates/deployment.yaml @@ -12,7 +12,6 @@ spec: strategy: type: RollingUpdate revisionHistoryLimit: 3 - template: metadata: labels: {{- include "labels" $ | nindent 8 }} @@ -25,7 +24,6 @@ spec: securityContext: {{- toYaml $.Values.securityContext | nindent 8 }} imagePullSecrets: {{- toYaml $.Values.imagePullSecrets | nindent 8 }} containers: - - name: exporter image: ribbybibby/ssl-exporter:v{{ $.Chart.AppVersion }} imagePullPolicy: {{ $.Values.podImagePullPolicy | quote }} From 546a1c411574a65ef59325c632031a001a04f8b5 Mon Sep 17 00:00:00 2001 From: AH | Dromaniuk Date: Mon, 13 Sep 2021 11:19:42 +0300 Subject: [PATCH 4/5] Add configMap generation --- charts/exporter/templates/configmap.yaml | 12 ++++++ charts/exporter/templates/deployment.yaml | 14 +++++++ charts/exporter/values.yaml | 46 ++++++++++++++++++++++- 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 charts/exporter/templates/configmap.yaml diff --git a/charts/exporter/templates/configmap.yaml b/charts/exporter/templates/configmap.yaml new file mode 100644 index 00000000..43e6a302 --- /dev/null +++ b/charts/exporter/templates/configmap.yaml @@ -0,0 +1,12 @@ +{{- if $.Values.configMap.enabled -}} +apiVersion: v1 +kind: ConfigMap +metadata: + namespace: {{ .Release.Namespace | quote }} + name: {{ include "releasename" $ | quote }} + labels: + {{- include "labels" . | nindent 4 }} +data: + config.yaml: | +{{ $.Values.configMap.data | indent 4 }} +{{- end }} diff --git a/charts/exporter/templates/deployment.yaml b/charts/exporter/templates/deployment.yaml index 268c4692..2254209a 100644 --- a/charts/exporter/templates/deployment.yaml +++ b/charts/exporter/templates/deployment.yaml @@ -23,11 +23,20 @@ spec: affinity: {{- toYaml $.Values.affinity | nindent 8 }} securityContext: {{- toYaml $.Values.securityContext | nindent 8 }} imagePullSecrets: {{- toYaml $.Values.imagePullSecrets | nindent 8 }} +{{- if $.Values.configMap.enabled }} + volumes: + - name: config + configMap: + name: {{ include "releasename" $ | quote }} +{{- end }} containers: - name: exporter image: ribbybibby/ssl-exporter:v{{ $.Chart.AppVersion }} imagePullPolicy: {{ $.Values.podImagePullPolicy | quote }} resources: {{ toYaml $.Values.resources | nindent 12 }} +{{- if $.Values.configMap.enabled }} + args: ["--config.file=/config/config.yaml"] +{{- end }} ports: - name: exporter containerPort: 9219 @@ -41,3 +50,8 @@ spec: httpGet: port: exporter path: / +{{- if $.Values.configMap.enabled }} + volumeMounts: + - name: config + mountPath: /config +{{- end }} diff --git a/charts/exporter/values.yaml b/charts/exporter/values.yaml index 107830a6..af633d6e 100644 --- a/charts/exporter/values.yaml +++ b/charts/exporter/values.yaml @@ -38,4 +38,48 @@ service: sessionAffinity: None prometheusOperator: - enableExampleProbes: false \ No newline at end of file + enableExampleProbes: false + +configMap: + enabled: false + data: | + modules: + https: + prober: https + https_insecure: + prober: https + tls_config: + insecure_skip_verify: true + https_proxy: + prober: https + https: + proxy_url: "socks5://localhost:8123" + https_timeout: + prober: https + timeout: 3s + tcp: + prober: tcp + tcp_servername: + prober: tcp + tls_config: + server_name: example.com + tcp_client_auth: + prober: tcp + tls_config: + ca_file: /etc/tls/ca.crt + cert_file: /etc/tls/tls.crt + key_file: /etc/tls/tls.key + tcp_smtp_starttls: + prober: tcp + tcp: + starttls: smtp + file: + prober: file + kubernetes: + prober: kubernetes + kubernetes_kubeconfig: + prober: kubernetes + kubernetes: + kubeconfig: /root/.kube/config + kubeconfig: + prober: kubeconfig From 4370fd130c0a1250f4ca6dcf68d17bd1f29a7598 Mon Sep 17 00:00:00 2001 From: AH | Dromaniuk Date: Mon, 13 Sep 2021 11:29:18 +0300 Subject: [PATCH 5/5] Update README.md Add helm-chart notes --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index bf68912a..3c595713 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ metric indicates if the probe has been successful. upload binaries in response to a release being created in Github - Dockerhub will build and tag a new container image in response to tags of the format `/^v[0-9.]+$/` +- Helm chart needs to update app version manually in `Chart.yaml` ## Usage