Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rethink tests #15

Closed
wants to merge 12 commits into from
Closed
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
134 changes: 134 additions & 0 deletions .github/workflows/helm-workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
---
name: Helm
on: push

env:
HELM_VERSION: v3.12.1
PYTHON_VERSION: 3.9

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Helm
uses: azure/setup-helm@v3
with:
version: ${{ env.HELM_VERSION }}

- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
check-latest: true

- name: Set up chart-testing
uses: helm/chart-testing-action@v2.4.0

- 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 }} --validate-maintainers=false


helm-jobs:
runs-on: ubuntu-latest
strategy:
matrix:
k8s_version:
[
"v1.22.15",
"v1.23.17",
"v1.24.15",
"v1.25.11",
"v1.26.6",
"v1.27.3",
"v1.28.0"
]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Helm
uses: azure/setup-helm@v3
with:
version: ${{ env.HELM_VERSION }}

- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
check-latest: true

- name: Set up chart-testing
uses: helm/chart-testing-action@v2.4.0

- 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: Setup helmfile
if: steps.list-changed.outputs.changed == 'true'
uses: mamezou-tech/setup-helmfile@v1.2.0

- name: Prepare a config for the kind cluster
run: |
cat > kind-config.yaml <<EOF
# three node (two workers) cluster config
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
nodes:
- role: control-plane
- role: worker
- role: worker
EOF

- name: Create kind cluster
if: steps.list-changed.outputs.changed == 'true'
uses: helm/kind-action@v1.7.0
with:
node_image: kindest/node:${{ matrix.k8s_version }}
config: ./kind-config.yaml

- name: Init required charts to the cluster
if: steps.list-changed.outputs.changed == 'true'
run: |
helmfile -f charts/db-operator/ci/helmfile.yaml sync

- name: Run chart-testing (install)
if: steps.list-changed.outputs.changed == 'true'
run: ct install --target-branch ${{ github.event.repository.default_branch }}
# -----------------------------------------------------------------
# -- I will enable it later, we need to release this version first
# -----------------------------------------------------------------
# - name: Run chart-testing (upgrade)
# if: steps.list-changed.outputs.changed == 'true'
# run: ct install --target-branch ${{ github.event.repository.default_branch }} --upgrade

- name: Configure Git
run: |
git config user.name "$GITHUB_ACTOR"
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"

- name: Release charts
if: ${{ github.ref == github.event.repository.default_branch }}
uses: helm/chart-releaser-action@v1.5.0
with:
charts_dir: .
env:
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
48 changes: 38 additions & 10 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---
name: Test

on:
Expand All @@ -9,29 +10,29 @@ on:
- main

jobs:
get-chart:
get-chart:
runs-on: ubuntu-latest
outputs:
changed_charts: ${{ steps.get-chart.outputs.changed_charts }}
steps:
steps:
- name: Checkout
uses: actions/checkout@v3
with:
path: charts
fetch-depth: 2 # to be able to obtain files changed in the latest commit

- id: get-chart
name: 'Get modified charts'
name: "Get modified charts"
run: |
cd charts
files_changed="$(git diff --name-only HEAD^ HEAD)"
# Adding || true to avoid "Process exited with code 1" errors
charts_dirs_changed="$(echo "$files_changed" | xargs dirname | grep -o "charts/[^/]*" | sed "s|charts/||g" | uniq | tr '\n' ' ' || true)"
echo "changed:${charts_dirs_changed}"
echo "::set-output name=changed_charts::${charts_dirs_changed}"
lint:
lint:
runs-on: ubuntu-latest
steps:
steps:
- name: Checkout
uses: actions/checkout@v3
with:
Expand All @@ -49,20 +50,47 @@ jobs:
- name: Set up chart-testing
uses: helm/chart-testing-action@v2.3.0

- name: Run chart-testing (list-changed)
id: list-changed
run: |
changed=$(ct list-changed --chart-dirs helm --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 --validate-maintainers=false --target-branch main

test-values:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Run the test
run: |
cd charts/db-operator
./scripts/test_values -p ./ci/unit-test
db-operator-test:
runs-on: ubuntu-latest
needs: get-chart
if: ${{ contains(needs.get-chart.outputs.changed_charts, 'db-operator') || contains(needs.get-chart.outputs.changed_charts, 'db-instances') }}
strategy:
matrix:
k8s_version: ['v1.21.6', 'v1.22.3', 'v1.23.1', 'v1.24.3']
k8s_version:
[
"v1.22.8",
"v1.23.5",
"v1.24.16",
"v1.25.12",
"v1.26.7",
"v1.27.4",
]
steps:
- name: Checkout
uses: actions/checkout@v3

# The existing apparmor profile for mysql needs to be removed.
# https://github.com/actions/virtual-environments/issues/181
# https://github.com/moby/moby/issues/7512#issuecomment-51845976
Expand All @@ -73,17 +101,17 @@ jobs:
sudo apt-get update -y
sudo apt-get install apparmor-profiles
sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld

- name: Create k3d cluster
env:
K8S_VERSION: ${{ matrix.k8s_version }}
run: make k3d

- name: Install Cert Manager
run: make cert-manager

- name: Install Helm chart
run: make db-operator

- name: Integration test
run: ./tests/db-operator/integration.sh
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ For triggering it, change the version of Chart.yaml in the chart directory and m

## Configuring helm client
```
$ helm repo add kloeckneri https://kloeckner-i.github.io/charts
$ helm repo add db-operator https://db-operator.github.io/charts
```
Test the helm chart repository
```
$ helm search repo kloeckneri
$ helm search repo db-operator
```
2 changes: 1 addition & 1 deletion charts/db-instances/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ apiVersion: v1
appVersion: "1.0"
description: Database Instances for db operator
name: db-instances
version: 1.4.0
version: 1.4.2
2 changes: 1 addition & 1 deletion charts/db-instances/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Create DB Instance resources for is DB Operator
## Installing Chart
To install the chart with the release name my-release:
```
$ helm install --name my-release kloeckneri/db-instances
$ helm install --name my-release db-operator/db-instances
```
The command deploys DB Operator on Kubernetes with default configuration.

Expand Down
5 changes: 4 additions & 1 deletion charts/db-instances/templates/dbinstance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{{- if .Values.dbinstances }}
{{- range $name, $value := .Values.dbinstances }}
---
apiVersion: "kci.rocks/v1beta1"
apiVersion: "kinda.rocks/v1beta1"
kind: "DbInstance"
metadata:
name: {{ $name }}
Expand All @@ -13,6 +13,9 @@ metadata:
{{- end }}
labels:
{{- include "db-instances.labels" $ | nindent 4 }}
{{- with $value.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
engine: {{ $value.engine }}
{{- if $value.existingAdminSecret }}
Expand Down
4 changes: 4 additions & 0 deletions charts/db-operator/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Changelog

## 1.9.2
- feat: Make the webhook optional | https://github.com/db-operator/charts/pull/7
30 changes: 25 additions & 5 deletions charts/db-operator/Chart.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
---
apiVersion: v2
type: application
## All supported k8s versions are in the test: https://github.com/kloeckner-i/db-operator/blob/master/.github/workflows/build-and-test.yaml
kubeVersion: ">= 1.21-prerelease"
appVersion: "1.10.0"
description: A Database Operator
name: db-operator
version: 1.7.0
version: 1.11.1
# ---------------------------------------------------------------------------------
# -- All supported k8s versions are in the test:
# -- https://github.com/db-operator/charts/blob/main/.github/workflows/test.yaml
# ---------------------------------------------------------------------------------
kubeVersion: ">= 1.22-prerelease"
appVersion: "1.14.1"
description: The DB Operator creates databases and make them available in the cluster via Custom Resource.
home: https://github.com/db-operator/db-operator

maintainers:
- name: Nikolai Rodionov
email: allanger@zohomail.com

sources:
- https://github.com/db-operator/db-operator
- https://github.com/db-operator/cloudish-sql
- https://github.com/db-operator/pgdump-gcs
- https://github.com/db-operator/mydump-gcs
keywords:
- database
- Operator
- mysql
- postgres
2 changes: 2 additions & 0 deletions charts/db-operator/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
gen_docs:

Loading
Loading