diff --git a/.github/workflows/helm-workflow.yaml b/.github/helm-workflow.yaml similarity index 73% rename from .github/workflows/helm-workflow.yaml rename to .github/helm-workflow.yaml index eeb7a7f..5430857 100644 --- a/.github/workflows/helm-workflow.yaml +++ b/.github/helm-workflow.yaml @@ -14,59 +14,8 @@ env: PYTHON_VERSION: 3.14 jobs: - # -- Quick tests like helm unintest and linters - fast-tests: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v6 - with: - fetch-depth: 0 - - - name: Set up Go - uses: actions/setup-go@v6 - - - name: Set up Helm - uses: azure/setup-helm@v4.3.1 - with: - version: ${{ env.HELM_VERSION }} - - - uses: actions/setup-python@v6 - with: - python-version: ${{ env.PYTHON_VERSION }} - check-latest: true - - - name: Check CRD generation - run: | - ./scripts/sync_crds.sh - if [[ -n $(git status --porcelain) ]]; then - echo "Please update CRDs using the ./scripts/sync_crds.sh and push the changes" - exit 1 - fi - - - name: Check for changes - id: check_changes - run: | - if [[ -n $(git status --porcelain) ]]; then - echo "changes=true" >> "$GITHUB_OUTPUT"; - fi - - - name: Set up chart-testing - uses: helm/chart-testing-action@v2.8.0 - - - name: Run chart-testing (lint) - run: ct lint --target-branch main --validate-maintainers=false - - - name: Helm unit tests - run: | - helm plugin install https://github.com/helm-unittest/helm-unittest.git --verify=false - files=$(find ./charts/db-operator/tests -name '*.yaml') - for file in $files; do - helm unittest -f $file ./charts/db-operator - done - # -- Tests that require a real k8s cluster running, should be tested against supported k8s versions long-test: - needs: fast-tests + needs: quick-tests runs-on: ubuntu-latest strategy: matrix: diff --git a/.github/workflows/integration-tests.yaml b/.github/workflows/integration-tests.yaml new file mode 100644 index 0000000..5849275 --- /dev/null +++ b/.github/workflows/integration-tests.yaml @@ -0,0 +1,70 @@ +--- +# -- Long tests against the kubernetes API +name: Integration tests + +on: + pull_request: + branches: + - main + +jobs: + chart-test: + runs-on: ubuntu-latest + strategy: + matrix: + k8s_version: + - v1.35.0 + - v1.34.3 + - v1.33.7 + - v1.32.11 + chart: + - db-operator + - db-instances + steps: + - uses: actions/checkout@v6 + with: + fetch-depth: 0 + - uses: actions/setup-python@v3 + - uses: actions/setup-go@v6 + - uses: azure/setup-helm@v4.3.0 + - uses: helm/chart-testing-action@v2.8.0 + - name: Create kind cluster + uses: helm/kind-action@v1.13.0 + with: + node_image: kindest/node:${{ matrix.k8s_version }} + config: ./ci/kind-config.yaml + - name: Deploy the helmfile + uses: helmfile/helmfile-action@v2.1.0 + with: + helmfile-auto-init: true + helmfile-args: sync -e ${{ matrix.chart }} --wait + helmfile-workdirectory: ./ci + - name: Test the db-operator chart install + run: | + ct install --target-branch main --charts ./charts/${{ matrix.chart }} + - name: Test the db-operator chart upgrade + run: | + ct install --target-branch main --charts ./charts/${{ matrix.chart }} --upgrade + + logic-test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - uses: actions/setup-python@v3 + - uses: actions/setup-go@v6 + - uses: azure/setup-helm@v4.3.0 + - name: Create kind cluster + uses: helm/kind-action@v1.13.0 + with: + config: ./ci/kind-config.yaml + - name: Deploy the helmfile + uses: helmfile/helmfile-action@v2.1.0 + with: + helmfile-auto-init: true + helmfile-args: sync -e tests --wait + helmfile-workdirectory: ./ci + - name: Run tests + uses: helmfile/helmfile-action@v2.1.0 + with: + helmfile-args: test -e tests -l purpose=test + helmfile-workdirectory: ./ci diff --git a/.github/workflows/quick-tests.yaml b/.github/workflows/quick-tests.yaml new file mode 100644 index 0000000..b2a1299 --- /dev/null +++ b/.github/workflows/quick-tests.yaml @@ -0,0 +1,37 @@ +--- +# -- Quick tests like linters and unit-tests +name: Quick tests + +on: + pull_request: + branches: + - main + +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + with: + fetch-depth: 0 + - uses: actions/setup-python@v3 + - uses: actions/setup-go@v6 + - uses: azure/setup-helm@v4.3.0 + - uses: helm/chart-testing-action@v2.8.0 + - name: Lint the charts + run: make lint + + + unit-tests: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - uses: actions/setup-python@v3 + - uses: actions/setup-go@v6 + - uses: azure/setup-helm@v4.3.0 + - name: Install the helm-unittest plugin + run: |- + helm plugin install https://github.com/helm-unittest/helm-unittest.git \ + --verify=false + - name: Run the unit tests + run: make unit diff --git a/.github/workflows/release-repo.yaml b/.github/workflows/release-repo.yaml new file mode 100644 index 0000000..ffebb91 --- /dev/null +++ b/.github/workflows/release-repo.yaml @@ -0,0 +1,21 @@ +--- +# -- Release to the regular helm repo hosted with Github Pages + +on: + push: + branches: + - main + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - name: Configure Git + run: | + git config user.name "$GITHUB_ACTOR" + git config user.email "$GITHUB_ACTOR@users.noreply.github.com" + - uses: azure/setup-helm@v4.3.0 + - uses: helm/chart-releaser-action@v1.7.0 + env: + CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/repo-checks.yaml b/.github/workflows/repo-checks.yaml new file mode 100644 index 0000000..d247711 --- /dev/null +++ b/.github/workflows/repo-checks.yaml @@ -0,0 +1,39 @@ +--- +# -- Quick checks mostly related to the code-related worklow +name: Repo checks + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + repo-checks: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v6 + - uses: actions/setup-python@v3 + - uses: actions/setup-go@v6 + - name: Run the pre-commit hook + uses: pre-commit/action@v3.0.1 + with: + extra_args: --all-files + + - name: Check CRD generation + run: |- + make sync-crds + if [[ -n $(git status --porcelain) ]]; then + echo "Please update CRDs using 'make sync-crds' and push the changes" + exit 1 + fi + + - name: Check docs generation + run: |- + make gen-docs + if [[ -n $(git status --porcelain) ]]; then + echo "Please re-generate the docs using 'make gen-docs' and push the changes" + exit 1 + fi diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6e5b76c..0530de7 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,22 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 # Use the ref you want to point at + rev: v2.3.0 hooks: + - id: end-of-file-fixer + # -- Pre commit hook is conflicting with the helm-docs + exclude: | + (?x)( + ^charts/db-instances/README.md + ) - id: trailing-whitespace + - id: detect-private-key + - repo: https://github.com/codespell-project/codespell + rev: v2.4.1 + hooks: + - id: codespell + exclude: | + (?x)( + ^charts/db-operator/crd/| + ^charts/db-operator/README.md| + ^charts/db-instances/README.md + ) diff --git a/Makefile b/Makefile index a182a18..2694403 100644 --- a/Makefile +++ b/Makefile @@ -1,45 +1,23 @@ -.PHONY: all deploy build helm -.ONESHELL: test - -ifeq ($(K8S_VERSION),) -K8S_VERSION := v1.28.4 -endif - LOCALBIN_DIR ?= $(shell pwd)/bin $(LOCALBIN_DIR): mkdir -p $(LOCALBIN_DIR) -k3d: - @curl -s https://raw.githubusercontent.com/k3d-io/k3d/main/install.sh | bash - @k3d cluster create myk3s -i rancher/k3s:$(K8S_VERSION)-k3s1 - @kubectl get pod - -helmfile-operator: ## Syncs the helmfile with dependencies for testing operator - helmfile sync -f ./helmfile.yaml - -helmfile-instances: ## Syncs the helmfile with dependencies for testing dbinstances - helmfile sync -f ./helmfile.yaml -e instances - +#-- ct must be installed in the system, it's not that easy +#-- to install it line helm-docs lint: ## lint helm charts ct lint --target-branch main --validate-maintainers=false -test-operator: helmfile-operator ## test helm charts - ct install --target-branch main --charts ./charts/db-operator +DB_OPERATOR_UNIT := $(shell find charts/db-operator/tests -name '*.yaml') +unit: + @for file in $(DB_OPERATOR_UNIT); do \ + helm unittest -f $$file ./charts/db-operator; \ + done -test-upgrade-operator: helmfile-operator ## test helm charts - ct install --upgrade --target-branch main --charts ./charts/db-operator +sync-crds: ## Sync crds from the operator repo + ./scripts/sync_crds.sh -test-instances: helmfile-instances ## test helm charts - ct install --target-branch main --charts ./charts/db-instances - -test-upgrade-instances: helmfile-instances ## test helm charts - ct install --upgrade --target-branch main --charts ./charts/db-instances - -.PHONY: gen_docs gen-docs: ## Generate helm documentation test -s $(LOCALBIN)/helm-docs || GOBIN=$(LOCALBIN_DIR) go install github.com/norwoodj/helm-docs/cmd/helm-docs@latest ./bin/helm-docs --template-files=./charts/db-operator/README.md.gotmpl \ --sort-values-order file --chart-to-generate=charts/db-operator ./bin/helm-docs --template-files=./charts/db-isntances/README.md.gotmpl --sort-values-order file --chart-to-generate=charts/db-instances - - diff --git a/README.md b/README.md index 970a0b5..6951f4b 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,9 @@ -## Prerequisites -* Kubernetes v1.21+ -* Helm v3.0.2+ +## Charts for deploying DB Operator + +## Github Actions + ## Releasing new chart version The new chart version release is executed automatically with Github actions. For triggering it, change the version of Chart.yaml in the chart directory and merge to `main` branch. - -## Configuring helm client -``` -$ helm repo add db-operator https://db-operator.github.io/charts -``` -Test the helm chart repository -``` -$ helm search repo db-operator -``` \ No newline at end of file diff --git a/charts/db-instances/README.md b/charts/db-instances/README.md index 563855e..450dc83 100644 --- a/charts/db-instances/README.md +++ b/charts/db-instances/README.md @@ -1,6 +1,6 @@ # db-instances -![Version: 2.5.0](https://img.shields.io/badge/Version-2.5.0-informational?style=flat-square) ![AppVersion: 1.0](https://img.shields.io/badge/AppVersion-1.0-informational?style=flat-square) +![Version: 2.6.0](https://img.shields.io/badge/Version-2.6.0-informational?style=flat-square) ![AppVersion: 1.0](https://img.shields.io/badge/AppVersion-1.0-informational?style=flat-square) Database Instances for db operator diff --git a/charts/db-instances/files/test_monitoring b/charts/db-instances/files/test_monitoring index 39fd8a7..75c5274 100755 --- a/charts/db-instances/files/test_monitoring +++ b/charts/db-instances/files/test_monitoring @@ -39,4 +39,3 @@ do fi sleep "${ATTEMPTS_PAUSE}" done - diff --git a/charts/db-instances/templates/postgres_exporter.yaml b/charts/db-instances/templates/postgres_exporter.yaml index 61b2afd..0545c17 100644 --- a/charts/db-instances/templates/postgres_exporter.yaml +++ b/charts/db-instances/templates/postgres_exporter.yaml @@ -179,4 +179,4 @@ spec: {{- end }} {{- end }} {{- end }} -{{- end }} \ No newline at end of file +{{- end }} diff --git a/charts/db-operator-mysql-test/scripts/test_read.sh b/charts/db-operator-mysql-test/scripts/test_read.sh old mode 100644 new mode 100755 index 2a2efc8..3e708ea --- a/charts/db-operator-mysql-test/scripts/test_read.sh +++ b/charts/db-operator-mysql-test/scripts/test_read.sh @@ -23,4 +23,4 @@ do -e "SELECT data FROM test WHERE data = '${TESTDATA}';") echo "$FOUNDDATA" | grep "$TESTDATA" && break; -done \ No newline at end of file +done diff --git a/charts/db-operator-psql-test/scripts/test_read.sh b/charts/db-operator-psql-test/scripts/test_read.sh new file mode 100644 index 0000000..f606b6f --- /dev/null +++ b/charts/db-operator-psql-test/scripts/test_read.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +retry=3 +interval=5 + +for i in `seq 1 $retry` +do + sleep $interval + if [ ! -f "${POSTGRES_PASSWORD_FILE}" ]; then + echo "Password file does not exists" + exit 1; + else + POSTGRES_PASSWORD=$(cat ${POSTGRES_PASSWORD_FILE}) + fi + + TESTDATA="$(cat /tmp/checkdata)" + + echo "reading data from postgres..." + FOUNDDATA=$(PGPASSWORD=${POSTGRES_PASSWORD} psql \ + -h ${POSTGRES_HOST} \ + -U ${POSTGRES_USERNAME} \ + ${POSTGRES_DB} \ + -c "SELECT data FROM test WHERE data = '${TESTDATA}';") + + echo "$FOUNDDATA" | grep "$TESTDATA" && break; +done diff --git a/charts/db-operator-psql-test/scripts/test_write.sh b/charts/db-operator-psql-test/scripts/test_write.sh new file mode 100644 index 0000000..4eeb403 --- /dev/null +++ b/charts/db-operator-psql-test/scripts/test_write.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +TESTDATA="$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)" +echo ${TESTDATA} > /tmp/checkdata + +retry=5 +interval=10 + +for i in `seq 1 $retry` +do + sleep $interval + if [ ! -f "${POSTGRES_PASSWORD_FILE}" ]; then + echo "Password file does not exists" + exit 1; + else + POSTGRES_PASSWORD=$(cat ${POSTGRES_PASSWORD_FILE}) + fi + + echo "writing data into postgres database..." + PGPASSWORD=${POSTGRES_PASSWORD} psql -h ${POSTGRES_HOST} -U ${POSTGRES_USERNAME} ${POSTGRES_DB} \ + -c "CREATE TABLE IF NOT EXISTS test (no serial PRIMARY KEY, data VARCHAR (50) NOT NULL); INSERT INTO test (data) VALUES('${TESTDATA}');" \ + && break +done diff --git a/charts/db-operator/Chart.yaml b/charts/db-operator/Chart.yaml index 4f353f0..98ef13b 100644 --- a/charts/db-operator/Chart.yaml +++ b/charts/db-operator/Chart.yaml @@ -1,8 +1,7 @@ apiVersion: v2 type: application name: db-operator -version: 2.5.0 - +version: 3.0.0 # --------------------------------------------------------------------------------- # -- All supported k8s versions are in the test: # -- https://github.com/db-operator/charts/blob/main/.github/workflows/test.yaml diff --git a/charts/db-operator/README.md b/charts/db-operator/README.md index eaaa07e..8628f43 100644 --- a/charts/db-operator/README.md +++ b/charts/db-operator/README.md @@ -1,6 +1,6 @@ # db-operator -![Version: 2.3.0](https://img.shields.io/badge/Version-2.3.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 2.18.0](https://img.shields.io/badge/AppVersion-2.18.0-informational?style=flat-square) +![Version: 3.0.0](https://img.shields.io/badge/Version-3.0.0-informational?style=flat-square) ![Type: application](https://img.shields.io/badge/Type-application-informational?style=flat-square) ![AppVersion: 2.18.0](https://img.shields.io/badge/AppVersion-2.18.0-informational?style=flat-square) The DB Operator creates databases and make them available in the cluster via Custom Resource. @@ -33,7 +33,7 @@ If you want to manage `CRDs` yourself, you need to set `.Values.crds.install` to We don't support this way of `CRD` management officially though, so we can't promise to answer your questions if you choose to go this way. If you want to know more about it, keep reading, we'll talk about it later. -## Upgarding the Chart +## Upgrading the Chart If there are breaking changes, they should be described in this README's latest item and in helm-chart notes. So if you run `helm upgrade db-operator db-operator/db-operator --dry-run`, you will see if there are breaking changes there. @@ -85,7 +85,7 @@ At the moment, `db-operator` chart requires `cert-manager` to be present in the ## What is `.Values.tests`? -We use helm tests feature for testing the chart in CI. Though we know that this feature should be used by users to test their intsallations, we do not think that it can be very helpful in this particular case. Test resources are creating a powerful `ClusterRoles`, so **please make sure you don't have them enabled**, unless you really know what you're doing and why. +We use helm tests feature for testing the chart in CI. Though we know that this feature should be used by users to test their installations, we do not think that it can be very helpful in this particular case. Test resources are creating a powerful `ClusterRoles`, so **please make sure you don't have them enabled**, unless you really know what you're doing and why. ## Chart Values | Key | Type | Default | Description | @@ -192,7 +192,7 @@ $ helm upgrade db-operator db-operator/db-operator --version 1.11.0
To v1.10.0 -CRDs are moved to the `templates` folder, so now they are part of the release. It means that after the upgrade, you will get errors about resource ownerships. Thow errors will contain messages about missing `labels` and `annotations`, and the easiest way to fix it, will be just to add the `metadata` that helm can't find. So you can follow those messages one by one and when all the `CRDs` are patched, you'll be able to install the release. +CRDs are moved to the `templates` folder, so now they are part of the release. It means that after the upgrade, you will get errors about resource ownerships. Those errors will contain messages about missing `labels` and `annotations`, and the easiest way to fix it, will be just to add the `metadata` that helm can't find. So you can follow those messages one by one and when all the `CRDs` are patched, you'll be able to install the release. For example: diff --git a/charts/db-operator/README.md.gotmpl b/charts/db-operator/README.md.gotmpl index f0598d9..29eab35 100644 --- a/charts/db-operator/README.md.gotmpl +++ b/charts/db-operator/README.md.gotmpl @@ -24,7 +24,7 @@ If you want to manage `CRDs` yourself, you need to set `.Values.crds.install` to We don't support this way of `CRD` management officially though, so we can't promise to answer your questions if you choose to go this way. If you want to know more about it, keep reading, we'll talk about it later. -## Upgarding the Chart +## Upgrading the Chart If there are breaking changes, they should be described in this README's latest item and in helm-chart notes. So if you run `helm upgrade db-operator db-operator/db-operator --dry-run`, you will see if there are breaking changes there. @@ -76,7 +76,7 @@ At the moment, `db-operator` chart requires `cert-manager` to be present in the ## What is `.Values.tests`? -We use helm tests feature for testing the chart in CI. Though we know that this feature should be used by users to test their intsallations, we do not think that it can be very helpful in this particular case. Test resources are creating a powerful `ClusterRoles`, so **please make sure you don't have them enabled**, unless you really know what you're doing and why. +We use helm tests feature for testing the chart in CI. Though we know that this feature should be used by users to test their installations, we do not think that it can be very helpful in this particular case. Test resources are creating a powerful `ClusterRoles`, so **please make sure you don't have them enabled**, unless you really know what you're doing and why. ## Chart Values {{ template "chart.valuesTable" . }} @@ -112,7 +112,7 @@ $ helm upgrade db-operator db-operator/db-operator --version 1.11.0
To v1.10.0 -CRDs are moved to the `templates` folder, so now they are part of the release. It means that after the upgrade, you will get errors about resource ownerships. Thow errors will contain messages about missing `labels` and `annotations`, and the easiest way to fix it, will be just to add the `metadata` that helm can't find. So you can follow those messages one by one and when all the `CRDs` are patched, you'll be able to install the release. +CRDs are moved to the `templates` folder, so now they are part of the release. It means that after the upgrade, you will get errors about resource ownerships. Those errors will contain messages about missing `labels` and `annotations`, and the easiest way to fix it, will be just to add the `metadata` that helm can't find. So you can follow those messages one by one and when all the `CRDs` are patched, you'll be able to install the release. For example: diff --git a/charts/db-operator/templates/NOTES.txt b/charts/db-operator/templates/NOTES.txt index 7f2be74..5601a14 100644 --- a/charts/db-operator/templates/NOTES.txt +++ b/charts/db-operator/templates/NOTES.txt @@ -6,7 +6,7 @@ (.-.).-.) _______________________ooo__( ^ )___________________________ / '-.___.-' \ -| Please read these notes, they might be usefull and we will try to | +| Please read these notes, they might be useful and we will try to | | make them as short as possible | \________________________________________ooo_______________________/ |_ | _| jgs @@ -25,7 +25,7 @@ The Release name {{ .Release.Name }}. Breaking changes and migration paths: From 2.5.0, the .image.logLevel field is no longer used, and instead -users should use .controller.logLevel and .webhook.logLevel +users should use .controller.logLevel and .webhook.logLevel From 2.0.0, the "v" prefix will not be automatically added to the image tag. If you are overriding the image diff --git a/charts/db-operator/templates/certificate/issuer.yaml b/charts/db-operator/templates/certificate/issuer.yaml index 7de5de2..1d48597 100644 --- a/charts/db-operator/templates/certificate/issuer.yaml +++ b/charts/db-operator/templates/certificate/issuer.yaml @@ -7,4 +7,4 @@ metadata: namespace: {{ .Release.Namespace }} spec: selfSigned: {} -{{- end }} \ No newline at end of file +{{- end }} diff --git a/helmfile.yaml.gotmpl b/ci/helmfile.yaml.gotmpl similarity index 82% rename from helmfile.yaml.gotmpl rename to ci/helmfile.yaml.gotmpl index aa2776e..c934845 100644 --- a/helmfile.yaml.gotmpl +++ b/ci/helmfile.yaml.gotmpl @@ -1,7 +1,7 @@ environments: - default: - instances: - + db-operator: + db-instances: + tests: --- repositories: - name: jetstack @@ -56,7 +56,8 @@ releases: - name: db-operator namespace: db-operator createNamespace: true - chart: ./charts/db-operator + installed: {{ not (eq .Environment.Name "db-operator") }} + chart: ../charts/db-operator labels: purpose: db-operator needs: @@ -66,6 +67,7 @@ releases: - name: mariadb-instance namespace: databases chart: cloudpirates/mariadb + installed: {{ not (eq .Environment.Name "db-operator") }} labels: test: mysql version: 0.13.4 @@ -75,7 +77,8 @@ releases: - name: mysql-test namespace: mysql-test - chart: ./charts/db-operator-mysql-test/ + chart: ../charts/db-operator-mysql-test/ + installed: {{ eq .Environment.Name "tests" }} labels: test: mysql purpose: test @@ -84,6 +87,7 @@ releases: namespace: databases chart: cloudpirates/postgres version: 0.15.5 + installed: {{ not (eq .Environment.Name "db-operator") }} labels: test: psql values: @@ -93,7 +97,8 @@ releases: - name: psql-test namespace: psql-test - chart: ./charts/db-operator-psql-test/ + installed: {{ eq .Environment.Name "tests" }} + chart: ../charts/db-operator-psql-test/ labels: test: psql purpose: test diff --git a/ci/kind-config.yaml b/ci/kind-config.yaml new file mode 100644 index 0000000..ab4a941 --- /dev/null +++ b/ci/kind-config.yaml @@ -0,0 +1,7 @@ +--- +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +nodes: + - role: control-plane + - role: worker + - role: worker