diff --git a/.github/workflows/release-chart.yml b/.github/workflows/release-chart.yml new file mode 100644 index 00000000..5fa533b8 --- /dev/null +++ b/.github/workflows/release-chart.yml @@ -0,0 +1,31 @@ +name: Release Charts + +on: + push: + branches: + - master + paths: + - charts/** + +jobs: + release: + # depending on default permission settings for your org (contents being read-only or read-write for workloads), you will have to add permissions + # see: https://docs.github.com/en/actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token + permissions: + contents: write + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + 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: Run chart-releaser + uses: helm/chart-releaser-action@v1.5.0 + env: + CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" diff --git a/README.md b/README.md index 3f25dc65..615faaf7 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,10 @@ resources: - https://github.com/resmoio/kubernetes-event-exporter?ref=master ``` +### Helm + +See [Helm Guide](./charts/kubernetes-event-exporter/README.md). + ## Configuration Configuration is done via a YAML file, when run in Kubernetes, ConfigMap. The tool watches all the events and diff --git a/charts/kubernetes-event-exporter/.helmignore b/charts/kubernetes-event-exporter/.helmignore new file mode 100644 index 00000000..0e8a0eb3 --- /dev/null +++ b/charts/kubernetes-event-exporter/.helmignore @@ -0,0 +1,23 @@ +# Patterns to ignore when building packages. +# This supports shell glob matching, relative path matching, and +# negation (prefixed with !). Only one pattern per line. +.DS_Store +# Common VCS dirs +.git/ +.gitignore +.bzr/ +.bzrignore +.hg/ +.hgignore +.svn/ +# Common backup files +*.swp +*.bak +*.tmp +*.orig +*~ +# Various IDEs +.project +.idea/ +*.tmproj +.vscode/ diff --git a/charts/kubernetes-event-exporter/Chart.yaml b/charts/kubernetes-event-exporter/Chart.yaml new file mode 100644 index 00000000..b3fc3583 --- /dev/null +++ b/charts/kubernetes-event-exporter/Chart.yaml @@ -0,0 +1,16 @@ +apiVersion: v2 +name: kubernetes-event-exporter +description: Export Kubernetes events to multiple destinations with routing and filtering +type: application + +# This is the chart version. This version number should be incremented each time you make changes +# to the chart and its templates, including the app version. +# Versions are expected to follow Semantic Versioning (https://semver.org/) +version: 0.1.0 + +# This is the version number of the application being deployed. This version number should be +# incremented each time you make changes to the application. Versions are not expected to +# follow Semantic Versioning. They should reflect the version the application is using. +# It is recommended to use it with quotes. +appVersion: "1.16.0" +home: https://github.com/resmoio/kubernetes-event-exporter diff --git a/charts/kubernetes-event-exporter/README.md b/charts/kubernetes-event-exporter/README.md new file mode 100644 index 00000000..fd2720f5 --- /dev/null +++ b/charts/kubernetes-event-exporter/README.md @@ -0,0 +1,43 @@ +# kubernetes-event-exporter Helm Chart + +## Get Repository Info + +```shell +helm repo add kubernetes-event-exporter https://resmoio.github.io/kubernetes-event-exporter +helm update +``` + +## Prepare the Deployment configuration [Optional] + +Create a helm values file. + +```yaml +# config.yaml +--- +config: | + logLevel: error + logFormat: json + route: + routes: + - match: + - receiver: "dump" + receivers: + - name: "dump" + stdout: {} +``` + +See [App Configuration](../../README.md) for reference. + +## Install Chart + +Ensure `monitoring` namespace exists + +```shell +kubectl create ns monitoring +``` + +Install chart + +```bash +helm install kubernetes-event-exporter -f config.yaml resmoio/kubernetes-event-exporter +``` diff --git a/charts/kubernetes-event-exporter/templates/NOTES.txt b/charts/kubernetes-event-exporter/templates/NOTES.txt new file mode 100644 index 00000000..c1903d1f --- /dev/null +++ b/charts/kubernetes-event-exporter/templates/NOTES.txt @@ -0,0 +1,22 @@ +1. Get the application URL by running these commands: +{{- if .Values.ingress.enabled }} +{{- range $host := .Values.ingress.hosts }} + {{- range .paths }} + http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }} + {{- end }} +{{- end }} +{{- else if contains "NodePort" .Values.service.type }} + export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "kubernetes-event-exporter.fullname" . }}) + export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}") + echo http://$NODE_IP:$NODE_PORT +{{- else if contains "LoadBalancer" .Values.service.type }} + NOTE: It may take a few minutes for the LoadBalancer IP to be available. + You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "kubernetes-event-exporter.fullname" . }}' + export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "kubernetes-event-exporter.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}") + echo http://$SERVICE_IP:{{ .Values.service.port }} +{{- else if contains "ClusterIP" .Values.service.type }} + export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "kubernetes-event-exporter.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}") + export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}") + echo "Visit http://127.0.0.1:8080 to use your application" + kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT +{{- end }} diff --git a/charts/kubernetes-event-exporter/templates/_helpers.tpl b/charts/kubernetes-event-exporter/templates/_helpers.tpl new file mode 100644 index 00000000..4f2a61c4 --- /dev/null +++ b/charts/kubernetes-event-exporter/templates/_helpers.tpl @@ -0,0 +1,73 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "kubernetes-event-exporter.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 "kubernetes-event-exporter.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 "kubernetes-event-exporter.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "kubernetes-event-exporter.labels" -}} +helm.sh/chart: {{ include "kubernetes-event-exporter.chart" . }} +{{ include "kubernetes-event-exporter.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "kubernetes-event-exporter.selectorLabels" -}} +app.kubernetes.io/name: {{ include "kubernetes-event-exporter.name" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "kubernetes-event-exporter.serviceAccountName" -}} +{{- if .Values.serviceAccount.create }} +{{- default (include "kubernetes-event-exporter.fullname" .) .Values.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.serviceAccount.name }} +{{- end }} +{{- end }} + +{{/* +Allow the release namespace to be overridden for multi-namespace deployments in combined charts +*/}} +{{- define "kubernetes-event-exporter.namespace" -}} + {{- if .Values.namespaceOverride -}} + {{- .Values.namespaceOverride -}} + {{- else -}} + {{- .Release.Namespace -}} + {{- end -}} +{{- end -}} diff --git a/charts/kubernetes-event-exporter/templates/configmap.yaml b/charts/kubernetes-event-exporter/templates/configmap.yaml new file mode 100644 index 00000000..1a3402f2 --- /dev/null +++ b/charts/kubernetes-event-exporter/templates/configmap.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ include "kubernetes-event-exporter.fullname" . }}-cfg + namespace: {{ template "kubernetes-event-exporter.namespace" . }} +data: + config.yaml: | +{{ .Values.config | indent 4 }} diff --git a/charts/kubernetes-event-exporter/templates/deployment.yaml b/charts/kubernetes-event-exporter/templates/deployment.yaml new file mode 100644 index 00000000..6535cda5 --- /dev/null +++ b/charts/kubernetes-event-exporter/templates/deployment.yaml @@ -0,0 +1,67 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "kubernetes-event-exporter.fullname" . }} + namespace: {{ include "kubernetes-event-exporter.namespace" . }} +spec: + replicas: {{ .Values.replicaCount }} + selector: + matchLabels: + {{- include "kubernetes-event-exporter.selectorLabels" . | nindent 6 }} + template: + metadata: + {{- with .Values.podAnnotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + labels: + {{- include "kubernetes-event-exporter.selectorLabels" . | nindent 8 }} + spec: + {{- with .Values.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "kubernetes-event-exporter.serviceAccountName" . }} + securityContext: + {{- toYaml .Values.podSecurityContext | nindent 8 }} + containers: + - name: {{ .Chart.Name }} + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + ports: + - name: metrics + containerPort: {{ .Values.service.port }} + protocol: TCP + livenessProbe: + httpGet: + path: /metrics + port: metrics + readinessProbe: + httpGet: + path: /metrics + port: metrics + args: + - -conf=/data/config.yaml + volumeMounts: + - mountPath: /data + name: cfg + resources: + {{- toYaml .Values.resources | nindent 12 }} + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} + volumes: + - name: cfg + configMap: + name: {{ include "kubernetes-event-exporter.fullname" . }}-cfg diff --git a/charts/kubernetes-event-exporter/templates/role.yaml b/charts/kubernetes-event-exporter/templates/role.yaml new file mode 100644 index 00000000..b6c7e563 --- /dev/null +++ b/charts/kubernetes-event-exporter/templates/role.yaml @@ -0,0 +1,11 @@ +{{- if .Values.rbac.create }} +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: {{ include "kubernetes-event-exporter.fullname" . }} +rules: + - apiGroups: ["*"] + resources: ["*"] + verbs: ["get", "watch", "list"] +{{- end -}} diff --git a/charts/kubernetes-event-exporter/templates/rolebinding.yaml b/charts/kubernetes-event-exporter/templates/rolebinding.yaml new file mode 100644 index 00000000..ad8e7f43 --- /dev/null +++ b/charts/kubernetes-event-exporter/templates/rolebinding.yaml @@ -0,0 +1,15 @@ +{{- if .Values.rbac.create }} +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: {{ include "kubernetes-event-exporter.fullname" . }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: {{ include "kubernetes-event-exporter.fullname" . }} +subjects: + - kind: ServiceAccount + namespace: {{ include "kubernetes-event-exporter.namespace" . }} + name: {{ include "kubernetes-event-exporter.fullname" . }} +{{- end }} diff --git a/charts/kubernetes-event-exporter/templates/serviceaccount.yaml b/charts/kubernetes-event-exporter/templates/serviceaccount.yaml new file mode 100644 index 00000000..06a60ff5 --- /dev/null +++ b/charts/kubernetes-event-exporter/templates/serviceaccount.yaml @@ -0,0 +1,7 @@ +{{- if .Values.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "kubernetes-event-exporter.serviceAccountName" . }} + namespace: {{ include "kubernetes-event-exporter.namespace" . }} +{{- end }} diff --git a/charts/kubernetes-event-exporter/values.yaml b/charts/kubernetes-event-exporter/values.yaml new file mode 100644 index 00000000..323c28fb --- /dev/null +++ b/charts/kubernetes-event-exporter/values.yaml @@ -0,0 +1,96 @@ +# Default values for event-exporter. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. + +replicaCount: 1 + +image: + repository: ghcr.io/resmoio/kubernetes-event-exporter + pullPolicy: IfNotPresent + # Overrides the image tag whose default is the chart appVersion. + tag: latest + +imagePullSecrets: [] +nameOverride: "" +fullnameOverride: "" + +serviceAccount: + # Specifies whether a service account should be created + create: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + +podAnnotations: + prometheus.io/scrape: 'true' + prometheus.io/port: '2112' + prometheus.io/path: '/metrics' + +podSecurityContext: {} + # fsGroup: 2000 + +securityContext: {} + # capabilities: + # drop: + # - ALL + # readOnlyRootFilesystem: true + # runAsNonRoot: true + # runAsUser: 1000 + +service: + type: ClusterIP + port: 2112 + +ingress: + enabled: false + className: "" + annotations: {} + # kubernetes.io/ingress.class: nginx + # kubernetes.io/tls-acme: "true" + hosts: + - host: chart-example.local + paths: + - path: / + pathType: ImplementationSpecific + tls: [] + # - secretName: chart-example-tls + # hosts: + # - chart-example.local + +## Override the deployment namespace +namespaceOverride: "monitoring" + +rbac: + # If true, create & use RBAC resources + create: true + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + # requests: + # cpu: 100m + # memory: 128Mi + +nodeSelector: {} + +tolerations: [] + +affinity: {} + +config: | + logLevel: error + logFormat: json + route: + routes: + - match: + - receiver: "dump" + receivers: + - name: "dump" + stdout: {}