diff --git a/.github/workflows/release-chart.yml b/.github/workflows/release-chart.yml new file mode 100644 index 0000000..b716077 --- /dev/null +++ b/.github/workflows/release-chart.yml @@ -0,0 +1,34 @@ +name: Release Charts + +on: + push: + branches: + - main + paths: + - 'charts/**' + +jobs: + release: + permissions: + contents: write + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v7 + with: + fetch-depth: 0 + + - name: Configure Git + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + + - name: Install Helm + uses: azure/setup-helm@v4 + + - name: Run chart-releaser + uses: helm/chart-releaser-action@v1.6.0 + with: + charts_dir: . + env: + CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" diff --git a/charts/Chart.yaml b/charts/Chart.yaml new file mode 100644 index 0000000..7778217 --- /dev/null +++ b/charts/Chart.yaml @@ -0,0 +1,13 @@ +apiVersion: v2 +name: alertmanager-icinga-bridge +description: Alertmanager to Icinga2 bridge +home: https://github.com/NETWAYS/alertmanager-icinga-bridge +keywords: +- prometheus +- alertmanager +- webhook +- icinga2 +sources: +- https://github.com/NETWAYS/alertmanager-icinga-bridge +version: 1.0.0 +appVersion: "1.0.3" diff --git a/charts/templates/_helpers.tpl b/charts/templates/_helpers.tpl new file mode 100644 index 0000000..90becd3 --- /dev/null +++ b/charts/templates/_helpers.tpl @@ -0,0 +1,71 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "alertmanager-icinga-bridge.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "alertmanager-icinga-bridge.fullname" -}} +{{- if .Values.fullnameOverride -}} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- $name := default .Chart.Name .Values.nameOverride -}} +{{- if contains $name .Release.Name -}} +{{- .Release.Name | trunc 63 | trimSuffix "-" -}} +{{- else -}} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} +{{- end -}} +{{- end -}} +{{- end -}} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "alertmanager-icinga-bridge.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}} +{{- end -}} + + +{{/* +Create image pull secret. +*/}} +{{- define "alertmanager-icinga-bridge.imagePullSecret" -}} +{{- printf "{\"auths\": {\"%s\": {\"auth\": \"%s\"}}}" ( required "Please specify the Docker registry" .Values.image.registry) (printf "%s:%s" (required "Please specify the Docker user name" .Values.image.username) ( required "Please specify the Docker password" .Values.image.password) | b64enc) | b64enc }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "alertmanager-icinga-bridge.labels" -}} +helm.sh/chart: {{ include "alertmanager-icinga-bridge.chart" . }} +{{ include "alertmanager-icinga-bridge.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "alertmanager-icinga-bridge.selectorLabels" -}} +app.kubernetes.io/name: {{ include "alertmanager-icinga-bridge.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "alertmanager-icinga-bridge.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "alertmanager-icinga-bridge.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} diff --git a/charts/templates/deployment.yaml b/charts/templates/deployment.yaml new file mode 100644 index 0000000..1826282 --- /dev/null +++ b/charts/templates/deployment.yaml @@ -0,0 +1,97 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "alertmanager-icinga-bridge.fullname" . }} + labels: + app.kubernetes.io/name: {{ include "alertmanager-icinga-bridge.name" . }} + helm.sh/chart: {{ include "alertmanager-icinga-bridge.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + app.kubernetes.io/name: {{ include "alertmanager-icinga-bridge.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + template: + metadata: + labels: + app.kubernetes.io/name: {{ include "alertmanager-icinga-bridge.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + annotations: + checksum/tokens-secret: {{ include (print .Template.BasePath "/secret.yaml") . | sha256sum }} + spec: + serviceAccountName: {{ include "alertmanager-icinga-bridge.serviceAccountName" . }} + {{- if .Values.securityContext.enabled }} + securityContext: + fsGroup: {{ .Values.securityContext.fsGroup }} + runAsUser: {{ .Values.securityContext.runAsUser }} + {{- end }} + containers: + - name: {{ .Chart.Name }} + image: {{ .Values.image.registry }}/{{ .Values.image.repository }}:{{ .Values.image.tag }} + env: + - name: ALERTMANAGER_ICINGA_BRIDGE_ID + value: {{ required ".Values.config.id is required" .Values.config.id | quote }} + - name: ALERTMANAGER_ICINGA_BRIDGE_ICINGA_HOSTNAME + value: {{ required ".Values.config.icinga_hostname is required" .Values.config.icinga_hostname | quote }} + - name: ALERTMANAGER_ICINGA_BRIDGE_ICINGA_URL + value: {{ required ".Values.config.icinga_url is required" .Values.config.icinga_url | quote }} + - name: ALERTMANAGER_ICINGA_BRIDGE_ICINGA_USERNAME + value: {{ required ".Values.config.icinga_username is required" .Values.config.icinga_username | quote }} + - name: ALERTMANAGER_ICINGA_BRIDGE_ICINGA_PASSWORD + valueFrom: + secretKeyRef: + name: {{ .Values.config.icinga_password_secret | default (printf "%s" (include "alertmanager-icinga-bridge.fullname" .)) | quote }} + key: "icinga_password" + - name: ALERTMANAGER_ICINGA_BRIDGE_LISTEN_ADDR + value: {{ printf "0.0.0.0:%v" .Values.config.alertmanager_port | quote }} + - name: ALERTMANAGER_ICINGA_BRIDGE_BEARER_TOKEN + valueFrom: + secretKeyRef: + name: {{ .Values.config.alertmanager_bearer_token_secret | default (printf "%s" (include "alertmanager-icinga-bridge.fullname" .)) | quote }} + key: "alertmanager_bearer_token" +{{- if .Values.extraEnvVars }} +{{ toYaml .Values.extraEnvVars | indent 10 }} +{{- end }} + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: http + containerPort: {{ .Values.config.alertmanager_port }} + protocol: TCP + livenessProbe: + httpGet: + path: /healthz + port: http + readinessProbe: + httpGet: + path: /healthz + port: http + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- if .Values.extraVolumeMounts }} + volumeMounts: + {{- toYaml .Values.extraVolumeMounts | nindent 12 }} + {{- end }} + {{- if .Values.extraVolumes }} + volumes: + {{- toYaml .Values.extraVolumes | nindent 8 }} + {{- end }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} + imagePullSecrets: + {{- if .Values.image.existingPullSecret }} + - name: {{ .Values.image.existingPullSecret }} + {{- else if .Values.image.password }} + - name: {{ template "alertmanager-icinga-bridge.fullname" . }}-pullsecret + {{- end }} diff --git a/charts/templates/pull-secret.yaml b/charts/templates/pull-secret.yaml new file mode 100644 index 0000000..d1f0e65 --- /dev/null +++ b/charts/templates/pull-secret.yaml @@ -0,0 +1,14 @@ +{{- if and (not .Values.image.existingPullSecret) .Values.image.password }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "alertmanager-icinga-bridge.fullname" . }}-pullsecret + labels: + app.kubernetes.io/name: {{ include "alertmanager-icinga-bridge.name" . }} + helm.sh/chart: {{ include "alertmanager-icinga-bridge.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +type: kubernetes.io/dockerconfigjson +data: + .dockerconfigjson: {{ template "alertmanager-icinga-bridge.imagePullSecret" . }} +{{- end -}} diff --git a/charts/templates/secret.yaml b/charts/templates/secret.yaml new file mode 100644 index 0000000..3a23e63 --- /dev/null +++ b/charts/templates/secret.yaml @@ -0,0 +1,18 @@ +{{- if or (not .Values.config.icinga_password_secret) (not .Values.config.alertmanager_bearer_token_secret) }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "alertmanager-icinga-bridge.fullname" . }} + labels: + app.kubernetes.io/name: {{ include "alertmanager-icinga-bridge.name" . }} + helm.sh/chart: {{ include "alertmanager-icinga-bridge.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +data: +{{- if not .Values.config.icinga_password_secret }} + icinga_password: {{ required ".Values.config.icinga_password is required" .Values.config.icinga_password | b64enc | quote }} +{{- end }} +{{- if not .Values.config.alertmanager_bearer_token_secret }} + alertmanager_bearer_token: {{ required ".Values.config.alertmanager_bearer_token is required" .Values.config.alertmanager_bearer_token | b64enc | quote }} +{{- end }} +{{- end -}} diff --git a/charts/templates/service.yaml b/charts/templates/service.yaml new file mode 100644 index 0000000..dacdcce --- /dev/null +++ b/charts/templates/service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "alertmanager-icinga-bridge.fullname" . }} + labels: + app.kubernetes.io/name: {{ include "alertmanager-icinga-bridge.name" . }} + helm.sh/chart: {{ include "alertmanager-icinga-bridge.chart" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +spec: + type: ClusterIP + ports: + - name: http + port: 80 + protocol: TCP + targetPort: http + selector: + app.kubernetes.io/name: {{ include "alertmanager-icinga-bridge.name" . }} + app.kubernetes.io/instance: {{ .Release.Name }} diff --git a/charts/templates/serviceaccount.yaml b/charts/templates/serviceaccount.yaml new file mode 100644 index 0000000..670e6a2 --- /dev/null +++ b/charts/templates/serviceaccount.yaml @@ -0,0 +1,10 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "alertmanager-icinga-bridge.serviceAccountName" . }} + labels: + {{- include "alertmanager-icinga-bridge.labels" . | nindent 4 }} + annotations: + {{- toYaml .Values.serviceAccount.annotations | nindent 4 }} +{{- end }} diff --git a/charts/values.yaml b/charts/values.yaml new file mode 100644 index 0000000..ef8ab42 --- /dev/null +++ b/charts/values.yaml @@ -0,0 +1,82 @@ +# Default values for alertmanager-icinga-bridge. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + registry: ghcr.io/netways + repository: alertmanager-icinga-bridge + tag: 1.0.3 + pullPolicy: IfNotPresent + # username: + # password: + # existingPullSecret: my-image-pull-secret + +nameOverride: "" +fullnameOverride: "" + +# Required configuration +config: + id: alertmanagerID + icinga_hostname: Alertmanager + icinga_url: https://icinga.internal:5665 + icinga_username: icinga-example-api-user + icinga_password: icinga-example-api-password + alertmanager_port: 8888 + # alertmanager_bearer_token: aaaaaa + # alertmanager_bearer_token_secret: + +# Optional extra configuration +# extraEnvVars: +# - name: ALERTMANAGER_ICINGA_BRIDGE_LOGLEVEL +# value: "debug" +# - name: ALERTMANAGER_ICINGA_BRIDGE_ICINGA_CA +# value: | +# -----BEGIN CERTIFICATE----- +# .... +# -----END CERTIFICATE----- +# - name: ALERTMANAGER_ICINGA_BRIDGE_ICINGA_INSECURE_TLS +# value: "false" +# - name: ALERTMANAGER_ICINGA_BRIDGE_GC_INTERVAL +# value: "15m" +# - name: ALERTMANAGER_ICINGA_BRIDGE_HEARTBEAT_INTERVAL +# value: "1m" +# - name: ALERTMANAGER_ICINGA_BRIDGE_KEEP_FOR +# value: "168h" +# - name: ALERTMANAGER_ICINGA_BRIDGE_SERVICE_TEMPLATE +# value: "generic-service" +# +# Extra volumes for the alertmanager-icinga-bridge deployment. Optional. +extraVolumes: [] + +# Extra volumeMounts for the alertmanager-icinga-bridge deployment. Optional. +extraVolumeMounts: [] + +serviceAccount: + # Specifies whether a service account should be created + create: true + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + # Annotations to add to the service account + annotations: {} + +securityContext: + enabled: false + runAsUser: 999 + fsGroup: 999 + +resources: + requests: + cpu: 100m + memory: 64Mi + limits: + cpu: 200m + memory: 128Mi + +nodeSelector: {} + +tolerations: [] + +affinity: {} \ No newline at end of file