From 3b6d1cbc4dbf602ad2066903a2b203af483bac2a Mon Sep 17 00:00:00 2001 From: Pedro Rodrigues Date: Mon, 4 Nov 2024 20:12:47 -0300 Subject: [PATCH 1/5] Add `disturbed-cli` --- .github/workflows/release.yaml | 29 +++++++++ .gitignore | 7 +++ README.md | 9 ++- charts/disturbed-cli/Chart.yaml | 14 +++++ charts/disturbed-cli/README.md | 62 +++++++++++++++++++ charts/disturbed-cli/templates/_helpers.tpl | 33 ++++++++++ .../templates/configuration.yaml | 7 +++ charts/disturbed-cli/templates/cronjob.yaml | 33 ++++++++++ charts/disturbed-cli/templates/namespace.yaml | 8 +++ charts/disturbed-cli/values.yaml | 44 +++++++++++++ 10 files changed, 244 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/release.yaml create mode 100644 .gitignore create mode 100644 charts/disturbed-cli/Chart.yaml create mode 100644 charts/disturbed-cli/README.md create mode 100644 charts/disturbed-cli/templates/_helpers.tpl create mode 100644 charts/disturbed-cli/templates/configuration.yaml create mode 100644 charts/disturbed-cli/templates/cronjob.yaml create mode 100644 charts/disturbed-cli/templates/namespace.yaml create mode 100644 charts/disturbed-cli/values.yaml diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..c4820bd --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,29 @@ +name: Release charts + +on: + push: + branches: + - main + +jobs: + release: + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - name: Checkout + uses: actions/checkout@v4.2.2 + 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.2.0 + env: + GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' + - name: Publish charts + uses: helm/chart-releaser-action@v1.6.0 + env: + CR_TOKEN: '${{ secrets.GITHUB_TOKEN }}' diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c377361 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +# Folder + +.idea + +# File + +*.iml diff --git a/README.md b/README.md index 7978c47..3b23be3 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,7 @@ -# helm-charts -Personal Helm charts +# Helm Charts + +Personal Helm charts for Kubernetes. + +## Reference + +- [helm template](https://helm.sh/docs/helm/helm_template) diff --git a/charts/disturbed-cli/Chart.yaml b/charts/disturbed-cli/Chart.yaml new file mode 100644 index 0000000..62f9317 --- /dev/null +++ b/charts/disturbed-cli/Chart.yaml @@ -0,0 +1,14 @@ +apiVersion: v2 +name: disturbed-cli +description: Disturbed CLI +version: 0.1.0 +appVersion: 1.0.9 +home: https://github.com/hpedrorodrigues/disturbed_cli +sources: + - https://github.com/hpedrorodrigues/disturbed_cli + - https://github.com/hpedrorodrigues/helm-charts/tree/main/charts/disturbed-cli +keywords: + - on-call + - schedule +maintainers: + - name: hpedrorodrigues diff --git a/charts/disturbed-cli/README.md b/charts/disturbed-cli/README.md new file mode 100644 index 0000000..bef72eb --- /dev/null +++ b/charts/disturbed-cli/README.md @@ -0,0 +1,62 @@ +# Disturbed CLI + +Simple CLI that update users in Slack user groups based on OpsGenie on-call schedules. + +Learn more: [disturbed_cli][github-repository]. + +This chart creates a disturbed-cli cronjob on a [Kubernetes][kubernetes] cluster using the [Helm][helm] package manager. + +## Get Repository Info + +```console +helm repo add hpedrorodrigues-charts https://hpedrorodrigues.github.io/helm-charts +helm repo update +``` + +_See [`helm repo`][helm-cli-repo] for command documentation._ + +## Install Chart + +```console +helm install [RELEASE_NAME] hpedrorodrigues-charts/disturbed-cli +``` + +_See [configuration](#configuration) below._ + +_See [helm install][helm-cli-install] for command documentation._ + +## Uninstall Chart + +```console +helm uninstall [RELEASE_NAME] +``` + +This removes all the Kubernetes components associated with the chart and deletes the release. + +_See [helm uninstall][helm-cli-uninstall] for command documentation._ + +## Upgrading Chart + +```console +helm upgrade [RELEASE_NAME] [CHART] --install +``` + +_See [helm upgrade][helm-cli-upgrade] for command documentation._ + +## Configuration + +See [Customizing the chart before installing][helm-intro-chart-customization]. To check all configurable options with +detailed comments, visit the chart's [values.yaml](./values.yaml), or run these configuration commands: + +```console +helm show values hpedrorodrigues-charts/disturbed-cli +``` + +[kubernetes]: https://kubernetes.io +[helm]: https://helm.sh +[helm-cli-repo]: https://helm.sh/docs/helm/helm_repo +[helm-cli-install]: https://helm.sh/docs/helm/helm_install +[helm-cli-uninstall]: https://helm.sh/docs/helm/helm_uninstall +[helm-cli-upgrade]: https://helm.sh/docs/helm/helm_upgrade +[helm-intro-chart-customization]: https://helm.sh/docs/intro/using_helm/#customizing-the-chart-before-installing +[github-repository]: https://github.com/hpedrorodrigues/disturbed_cli diff --git a/charts/disturbed-cli/templates/_helpers.tpl b/charts/disturbed-cli/templates/_helpers.tpl new file mode 100644 index 0000000..0de1e06 --- /dev/null +++ b/charts/disturbed-cli/templates/_helpers.tpl @@ -0,0 +1,33 @@ +{{/* Expand the name of the chart. */}} +{{- define "disturbed.name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* Expand the version of the chart. */}} +{{- define "disturbed.version" -}} +{{ .Chart.AppVersion | quote }} +{{- end }} + +{{/* Expand the name and version of the chart. */}} +{{- define "disturbed.chart" -}} +{{ .Chart.Name }}-{{ .Chart.Version }} +{{- end }} + +{{/* Common labels. */}} +{{- define "disturbed.labels" -}} +app.kubernetes.io/name: {{ include "disturbed.name" . }} +app.kubernetes.io/version: {{ include "disturbed.version" . }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +app.kubernetes.io/instance: {{ .Release.Name }} +helm.sh/chart: {{ include "disturbed.chart" . }} +{{- if .Values.commonLabels }} +{{ toYaml .Values.commonLabels }} +{{- end }} +{{- end }} + +{{/* Image. */}} +{{- define "disturbed.image" -}} +{{- $image := .Values.image.repository -}} +{{- $version := default .Chart.AppVersion .Values.image.tag -}} +{{- printf "%s:%s" $image $version -}} +{{- end }} diff --git a/charts/disturbed-cli/templates/configuration.yaml b/charts/disturbed-cli/templates/configuration.yaml new file mode 100644 index 0000000..d7d0003 --- /dev/null +++ b/charts/disturbed-cli/templates/configuration.yaml @@ -0,0 +1,7 @@ +apiVersion: v1 +kind: ConfigMap +metadata: + name: {{ template "disturbed.name" . }}-config +data: + config.yaml: + {{ toYaml .Values.configuration.content | nindent 4}} diff --git a/charts/disturbed-cli/templates/cronjob.yaml b/charts/disturbed-cli/templates/cronjob.yaml new file mode 100644 index 0000000..8170ba7 --- /dev/null +++ b/charts/disturbed-cli/templates/cronjob.yaml @@ -0,0 +1,33 @@ +apiVersion: batch/v1 +kind: CronJob +metadata: + name: {{ template "disturbed.name" . }} + labels: + {{- include "disturbed.labels" . | nindent 4 }} +spec: + concurrencyPolicy: Forbid + schedule: {{ .Values.cron.schedule | quote }} + jobTemplate: + spec: + template: + metadata: + labels: + {{- include "disturbed.labels" . | nindent 12 }} + spec: + restartPolicy: OnFailure + containers: + - name: {{ template "disturbed.name" . }} + image: disturbed + imagePullPolicy: IfNotPresent + env: + {{- toYaml .Values.env | nindent 16 }} + resources: + {{- toYaml .Values.resources | nindent 16 }} + volumeMounts: + - name: config-file + subPath: config.yaml + mountPath: {{ .Values.configuration.filePath }} + volumes: + - name: config-file + configMap: + name: {{ template "disturbed.name" . }}-config diff --git a/charts/disturbed-cli/templates/namespace.yaml b/charts/disturbed-cli/templates/namespace.yaml new file mode 100644 index 0000000..7112545 --- /dev/null +++ b/charts/disturbed-cli/templates/namespace.yaml @@ -0,0 +1,8 @@ +{{- if .Values.namespace.create }} +apiVersion: v1 +kind: Namespace +metadata: + name: {{ template "disturbed.name" . }} + labels: + {{- include "disturbed.labels" . | nindent 4 }} +{{- end}} diff --git a/charts/disturbed-cli/values.yaml b/charts/disturbed-cli/values.yaml new file mode 100644 index 0000000..a118a76 --- /dev/null +++ b/charts/disturbed-cli/values.yaml @@ -0,0 +1,44 @@ +# Default values for `disturbed-cli`. + +commonLabels: {} + +namespace: + create: true + +cron: + schedule: '*/10 * * * *' # every 10m + +image: + repository: ghcr.io/hpedrorodrigues/disturbed_cli + # Optional. Defaults to Chart's appVersion (declared in Chart.yaml). + tag: '' + +# Optional. No resources are set by default. +resources: + {} + # limits: + # cpu: 100m + # memory: 64Mi + # requests: + # cpu: 100m + # memory: 64Mi + +# See: https://github.com/hpedrorodrigues/disturbed_cli#configuration-file. +configuration: + filePath: /app/config.yaml + content: '' + +env: + [] + # - name: DISTURBED_SLACK_API_TOKEN + # valueFrom: + # secretKeyRef: + # name: disturbed-cli + # key: disturbed-cli + # - name: DISTURBED_OPSGENIE_API_KEY + # valueFrom: + # secretKeyRef: + # name: disturbed-cli + # key: disturbed-cli + # - name: DISTURBED_LOG_LEVEL + # value: "INFO" From ccd37b08904166c1676222e8b3b3639ccfb1fd43 Mon Sep 17 00:00:00 2001 From: Pedro Rodrigues Date: Mon, 4 Nov 2024 20:23:51 -0300 Subject: [PATCH 2/5] Add workflow to check pull requests --- .github/workflows/pr-checks.yaml | 42 ++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 .github/workflows/pr-checks.yaml diff --git a/.github/workflows/pr-checks.yaml b/.github/workflows/pr-checks.yaml new file mode 100644 index 0000000..38a3f67 --- /dev/null +++ b/.github/workflows/pr-checks.yaml @@ -0,0 +1,42 @@ +name: Checks (pull request) + +on: + pull_request: + branches: + - '*' + +jobs: + checks: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4.2.2 + with: + fetch-depth: 0 + - name: Install Helm + uses: azure/setup-helm@v4.2.0 + env: + GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' + - name: Install Python + uses: actions/setup-python@v5 + with: + python-version: '3.x' + check-latest: true + - name: Set up chart-testing + uses: helm/chart-testing-action@v2.6.1 + - name: Run chart-testing (list-changed) + id: list-changed + run: | + changed=$(ct list-changed --target-branch ${{ github.event.repository.default_branch }}) + if [[ -n "${changed}" ]]; then + echo "changed=true" >> "$GITHUB_OUTPUT" + fi + - name: Run chart-testing (lint) + if: steps.list-changed.outputs.changed == 'true' + run: ct lint --target-branch ${{ github.event.repository.default_branch }} + - name: Create kind cluster + if: steps.list-changed.outputs.changed == 'true' + uses: helm/kind-action@v1.10.0 + - name: Run chart-testing (install) + if: steps.list-changed.outputs.changed == 'true' + run: ct install --target-branch ${{ github.event.repository.default_branch }} From 5a8abe787733e31f988757647ea5106fe7220803 Mon Sep 17 00:00:00 2001 From: Pedro Rodrigues Date: Mon, 4 Nov 2024 20:26:47 -0300 Subject: [PATCH 3/5] Fix lint issues --- .github/workflows/pr-checks.yaml | 2 +- charts/disturbed-cli/values.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pr-checks.yaml b/.github/workflows/pr-checks.yaml index 38a3f67..82ebd5c 100644 --- a/.github/workflows/pr-checks.yaml +++ b/.github/workflows/pr-checks.yaml @@ -1,4 +1,4 @@ -name: Checks (pull request) +name: PR Checks on: pull_request: diff --git a/charts/disturbed-cli/values.yaml b/charts/disturbed-cli/values.yaml index a118a76..cd33aac 100644 --- a/charts/disturbed-cli/values.yaml +++ b/charts/disturbed-cli/values.yaml @@ -6,7 +6,7 @@ namespace: create: true cron: - schedule: '*/10 * * * *' # every 10m + schedule: '*/10 * * * *' image: repository: ghcr.io/hpedrorodrigues/disturbed_cli From 1b6b34a4247515ca11ce426c730a79d51521cabd Mon Sep 17 00:00:00 2001 From: Pedro Rodrigues Date: Mon, 4 Nov 2024 20:28:11 -0300 Subject: [PATCH 4/5] Add ref to chart to readme --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 3b23be3..36489a5 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,10 @@ Personal Helm charts for Kubernetes. +## Charts + +- [disturbed-cli](./charts/disturbed-cli) + ## Reference - [helm template](https://helm.sh/docs/helm/helm_template) From 608b34166f9397546f891be1951cde1564b7ea2d Mon Sep 17 00:00:00 2001 From: Pedro Rodrigues Date: Mon, 4 Nov 2024 20:33:13 -0300 Subject: [PATCH 5/5] Push OCI packages --- .github/workflows/release.yaml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index c4820bd..cd75fb6 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -10,6 +10,8 @@ jobs: runs-on: ubuntu-latest permissions: contents: write + packages: write + id-token: write steps: - name: Checkout uses: actions/checkout@v4.2.2 @@ -27,3 +29,18 @@ jobs: uses: helm/chart-releaser-action@v1.6.0 env: CR_TOKEN: '${{ secrets.GITHUB_TOKEN }}' + - name: Login to GitHub Container Registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Push charts to GHCR + run: | + shopt -s nullglob + for pkg in .cr-release-packages/*; do + if [ -z "${pkg:-}" ]; then + break + fi + helm push "${pkg}" "oci://ghcr.io/${GITHUB_REPOSITORY_OWNER}/charts" + done