Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
70 changes: 70 additions & 0 deletions .github/workflows/integration-tests.yaml
Original file line number Diff line number Diff line change
@@ -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
37 changes: 37 additions & 0 deletions .github/workflows/quick-tests.yaml
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions .github/workflows/release-repo.yaml
Original file line number Diff line number Diff line change
@@ -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 }}"
39 changes: 39 additions & 0 deletions .github/workflows/repo-checks.yaml
Original file line number Diff line number Diff line change
@@ -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
19 changes: 18 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
)
40 changes: 9 additions & 31 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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


16 changes: 4 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
```
2 changes: 1 addition & 1 deletion charts/db-instances/README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 0 additions & 1 deletion charts/db-instances/files/test_monitoring
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,3 @@ do
fi
sleep "${ATTEMPTS_PAUSE}"
done

2 changes: 1 addition & 1 deletion charts/db-instances/templates/postgres_exporter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,4 @@ spec:
{{- end }}
{{- end }}
{{- end }}
{{- end }}
{{- end }}
2 changes: 1 addition & 1 deletion charts/db-operator-mysql-test/scripts/test_read.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ do
-e "SELECT data FROM test WHERE data = '${TESTDATA}';")

echo "$FOUNDDATA" | grep "$TESTDATA" && break;
done
done
26 changes: 26 additions & 0 deletions charts/db-operator-psql-test/scripts/test_read.sh
Original file line number Diff line number Diff line change
@@ -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
Loading
Loading