Skip to content

Commit b73d89a

Browse files
authored
controller refactoring DK-2516 (#17)
refactoring, integration tests, e2e, gh pipelines, improvements and fixes
1 parent aae819c commit b73d89a

File tree

97 files changed

+4621
-1769
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+4621
-1769
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: bug
6+
assignees: ''
7+
8+
---
9+
10+
#### Describe the bug
11+
A clear and concise description of what the bug is.
12+
13+
#### To Reproduce
14+
Steps to reproduce the behavior:
15+
16+
#### Expected behavior
17+
A clear and concise description of what you expected to happen.
18+
19+
#### Environment
20+
- controller version: [e.g. v1.0.0]
21+
- postgres version: [e.g. v11.0.0]
22+
- mongodb version: [e.g. v5.0.0]
23+
- kubernetes version: [e.g. v1.19.0]
24+
25+
#### Additional context
26+
Add any other context about the problem here.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Change request
3+
about: Propose a change for an already implemented solution
4+
title: ''
5+
labels: change
6+
assignees: ''
7+
8+
---
9+
10+
#### Describe the change
11+
A clear and concise description of what the change is about.
12+
13+
#### Current situation
14+
Describe the current situation.
15+
16+
#### Should
17+
Describe the changes you would like to propose.
18+
19+
#### Additional context
20+
Add any other context about the problem here.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea for this project
4+
title: ''
5+
labels: feature
6+
assignees: ''
7+
8+
---
9+
10+
#### Is your feature request related to a problem? Please describe
11+
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12+
13+
#### Describe the solution you'd like
14+
A clear and concise description of what you want to happen.
15+
16+
#### Describe alternatives you've considered
17+
A clear and concise description of any alternative solutions or features you've considered.
18+
19+
#### Additional context
20+
Add any other context or screenshots about the feature request here.

.github/workflows/chart.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Lint and Test Charts
2+
3+
on: pull_request
4+
5+
jobs:
6+
lint-test:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v2
11+
with:
12+
fetch-depth: 0
13+
14+
- name: Set up Helm
15+
uses: azure/setup-helm@v1
16+
with:
17+
version: v3.4.0
18+
19+
- uses: actions/setup-python@v2
20+
with:
21+
python-version: 3.7
22+
23+
- name: Set up chart-testing
24+
uses: helm/chart-testing-action@v2.1.0
25+
26+
- name: Run chart-testing (list-changed)
27+
id: list-changed
28+
run: |
29+
changed=$(ct list-changed --chart-dirs chart)
30+
if [[ -n "$changed" ]]; then
31+
echo "::set-output name=changed::true"
32+
fi
33+
34+
- name: Run chart-testing (lint)
35+
run: ct lint --chart-dirs chart
36+
37+
- name: Create kind cluster
38+
uses: helm/kind-action@v1.2.0
39+
if: steps.list-changed.outputs.changed == 'true'
40+
41+
- name: Run chart-testing (install)
42+
run: ct install --chart-dirs chart

.github/workflows/e2e.yaml

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
name: e2e
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- master
8+
9+
jobs:
10+
kind:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
- name: Setup QEMU
16+
uses: docker/setup-qemu-action@v1
17+
with:
18+
platforms: all
19+
- name: Setup Docker Buildx
20+
id: buildx
21+
uses: docker/setup-buildx-action@v1
22+
- name: Restore Go cache
23+
uses: actions/cache@v1
24+
with:
25+
path: ~/go/pkg/mod
26+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
27+
restore-keys: |
28+
${{ runner.os }}-go-
29+
- name: Cache Docker layers
30+
uses: actions/cache@v2
31+
id: cache
32+
with:
33+
path: /tmp/.buildx-cache
34+
key: ${{ runner.os }}-buildx-ghcache-${{ github.sha }}
35+
restore-keys: |
36+
${{ runner.os }}-buildx-ghcache-
37+
- name: Setup Go
38+
uses: actions/setup-go@v2
39+
with:
40+
go-version: 1.16.x
41+
- name: Setup Kubernetes
42+
uses: engineerd/setup-kind@v0.5.0
43+
with:
44+
version: v0.11.1
45+
image: kindest/node:v1.21.1@sha256:69860bda5563ac81e3c0057d654b5253219618a22ec3a346306239bba8cfa1a6
46+
- name: Setup Kustomize
47+
uses: fluxcd/pkg/actions/kustomize@main
48+
- name: Setup envtest
49+
uses: fluxcd/pkg/actions/envtest@main
50+
with:
51+
version: "1.21.2"
52+
- name: Setup Helm
53+
uses: fluxcd/pkg/actions/helm@main
54+
- name: Run controller tests
55+
run: make test
56+
- name: Check if working tree is dirty
57+
run: |
58+
if [[ $(git diff --stat) != '' ]]; then
59+
git --no-pager diff
60+
echo 'run make test and commit changes'
61+
exit 1
62+
fi
63+
- name: Build container image
64+
run: |
65+
make docker-build IMG=test/k8sdb-controller:latest BUILD_PLATFORMS=linux/amd64 \
66+
BUILD_ARGS="--cache-from=type=local,src=/tmp/.buildx-cache \
67+
--cache-to=type=local,dest=/tmp/.buildx-cache-new,mode=max"
68+
- name: Move cache
69+
run: |
70+
rm -rf /tmp/.buildx-cache
71+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
72+
- name: Load test image
73+
run: kind load docker-image test/k8sdb-controller:latest
74+
- name: Deploy controller
75+
run: make deploy IMG=test/k8sdb-controller:latest
76+
- name: Setup MongoDB
77+
env:
78+
MONGODB_VER: ${{ '10.29.2' }}
79+
run: |
80+
kubectl create ns mongodb
81+
helm repo add bitnami https://charts.bitnami.com/bitnami
82+
helm upgrade --wait -i mongodb bitnami/mongodb \
83+
--version $MONGODB_VER \
84+
--namespace mongodb \
85+
--set auth.rootPassword=password \
86+
--set persistence.enabled=false
87+
kubectl -n k8sdb-system apply -f ./config/testdata/mongodb/root-secret.yaml
88+
- name: Run MongoDB tests
89+
run: |
90+
kubectl -n k8sdb-system apply -f ./config/testdata/mongodbdatabase
91+
kubectl -n k8sdb-system apply -f ./config/testdata/mongodbuser
92+
kubectl -n k8sdb-system wait mongodbdatabase/admin --for=condition=DatabaseReady --timeout=1m
93+
kubectl -n k8sdb-system wait mongodbuser/foo --for=condition=UserReady --timeout=1m
94+
kubectl -n mongodb exec -ti deployment/mongodb mongodb -- mongo mongodb://localhost:27017/foo --authenticationDatabase=admin -u foo -p password --eval 'db.bar.insert({"foo":"bar"})'
95+
kubectl -n k8sdb-system delete -f ./config/testdata/mongodbuser
96+
! kubectl -n mongodb exec -ti deployment/mongodb mongodb -- mongo mongodb://localhost:27017/foo --authenticationDatabase=admin -u foo -p password --eval 'db.bar.insert({"foo":"bar"})'
97+
- name: Setup PostgreSQL
98+
env:
99+
POSTGRESQL_VER: ${{ '10.13.8' }}
100+
run: |
101+
kubectl create ns postgresql
102+
helm repo add bitnami https://charts.bitnami.com/bitnami
103+
helm upgrade --wait -i postgresql bitnami/postgresql \
104+
--version $POSTGRESQL_VER \
105+
--namespace postgresql \
106+
--set postgresqlPassword=password \
107+
--set persistence.enabled=false
108+
kubectl -n k8sdb-system apply -f ./config/testdata/postgresql/root-secret.yaml
109+
- name: Run PostgreSQL tests
110+
run: |
111+
kubectl -n k8sdb-system apply -f ./config/testdata/postgresqldatabase
112+
kubectl -n k8sdb-system apply -f ./config/testdata/postgresqluser
113+
kubectl -n k8sdb-system wait postgresqldatabase/foo --for=condition=DatabaseReady --timeout=1m
114+
kubectl -n k8sdb-system wait postgresqluser/foo --for=condition=UserReady --timeout=1m
115+
kubectl -n postgresql exec -ti sts/postgresql-postgresql postgresql -- bash -c "PGPASSWORD=password psql -h localhost -U foo foo -c '\l'"
116+
kubectl -n k8sdb-system delete -f ./config/testdata/postgresqluser
117+
! kubectl -n postgresql exec -ti sts/postgresql-postgresql postgresql -- bash -c "PGPASSWORD=password psql -h localhost -U foo foo -c '\l'"
118+
- name: Logs
119+
run: |
120+
kubectl -n k8sdb-system logs deploy/k8sdb-controller
121+
- name: Debug failure
122+
if: failure()
123+
run: |
124+
kubectl -n kube-system describe pods
125+
kubectl -n k8sdb-system describe pods
126+
kubectl -n k8sdb-system get mongodbdatabase -oyaml
127+
kubectl -n k8sdb-system get mongodbuser -oyaml
128+
kubectl -n k8sdb-system get postgresqldatabase -oyaml
129+
kubectl -n k8sdb-system get postgresqluser -oyaml
130+
kubectl -n k8sdb-system get all
131+
kubectl -n k8sdb-system logs deploy/k8sdb-controller
132+
kubectl -n mongodb get all
133+
kubectl -n postgresql get all

.github/workflows/rebase.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: rebase
2+
3+
on:
4+
pull_request:
5+
types: [opened]
6+
issue_comment:
7+
types: [created]
8+
9+
jobs:
10+
rebase:
11+
if: github.event.issue.pull_request != '' && contains(github.event.comment.body, '/rebase') && (github.event.comment.author_association == 'CONTRIBUTOR' || github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'OWNER')
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout the latest code
15+
uses: actions/checkout@v2
16+
with:
17+
fetch-depth: 0
18+
- name: Automatic Rebase
19+
uses: cirrus-actions/rebase@1.3.1
20+
env:
21+
GITHUB_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }}

.github/workflows/release-chart.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Release Chart
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
jobs:
9+
release:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v2
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Configure Git
18+
run: |
19+
git config user.name "$GITHUB_ACTOR"
20+
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
21+
- name: Run chart-releaser
22+
uses: helm/chart-releaser-action@v1.3.0
23+
with:
24+
charts_dir: ./chart
25+
env:
26+
CR_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

.github/workflows/release.yaml

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
name: release
2+
on:
3+
push:
4+
tags:
5+
- 'v*'
6+
workflow_dispatch:
7+
inputs:
8+
tag:
9+
description: 'image tag prefix'
10+
default: 'rc'
11+
required: true
12+
13+
permissions:
14+
contents: write # needed to write releases
15+
id-token: write # needed for keyless signing
16+
packages: write # needed for ghcr access
17+
18+
env:
19+
CONTROLLER: ${{ github.event.repository.name }}
20+
21+
jobs:
22+
build-push:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v2
26+
- name: Setup Kustomize
27+
uses: fluxcd/pkg/actions/kustomize@main
28+
- name: Prepare
29+
id: prep
30+
run: |
31+
VERSION="${{ github.event.inputs.tag }}-${GITHUB_SHA::8}"
32+
if [[ $GITHUB_REF == refs/tags/* ]]; then
33+
VERSION=${GITHUB_REF/refs\/tags\//}
34+
fi
35+
echo ::set-output name=BUILD_DATE::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
36+
echo ::set-output name=VERSION::${VERSION}
37+
- name: Setup QEMU
38+
uses: docker/setup-qemu-action@v1
39+
with:
40+
platforms: all
41+
- name: Setup Docker Buildx
42+
id: buildx
43+
uses: docker/setup-buildx-action@v1
44+
with:
45+
buildkitd-flags: "--debug"
46+
- name: Login to GitHub Container Registry
47+
uses: docker/login-action@v1
48+
with:
49+
registry: ghcr.io
50+
username: ${{ github.actor }}
51+
password: ${{ secrets.GITHUB_TOKEN }}
52+
- name: Generate images meta
53+
id: meta
54+
uses: docker/metadata-action@v3
55+
with:
56+
images: |
57+
ghcr.io/doodlescheduling/${{ env.CONTROLLER }}
58+
tags: |
59+
type=raw,value=${{ steps.prep.outputs.VERSION }}
60+
- name: Publish multi-arch container image
61+
uses: docker/build-push-action@v2
62+
with:
63+
push: true
64+
builder: ${{ steps.buildx.outputs.name }}
65+
context: .
66+
file: ./Dockerfile
67+
platforms: linux/amd64,linux/arm/v7,linux/arm64
68+
tags: ${{ steps.meta.outputs.tags }}
69+
labels: ${{ steps.meta.outputs.labels }}
70+
- name: Check images
71+
run: |
72+
docker buildx imagetools inspect ghcr.io/doodlescheduling/${{ env.CONTROLLER }}:${{ steps.prep.outputs.VERSION }}
73+
docker pull ghcr.io/doodlescheduling/${{ env.CONTROLLER }}:${{ steps.prep.outputs.VERSION }}
74+
- name: Generate release manifests
75+
if: startsWith(github.ref, 'refs/tags/v')
76+
run: |
77+
mkdir -p config/release
78+
kustomize build ./config/crd > ./config/release/${{ env.CONTROLLER }}.crds.yaml
79+
kustomize build ./config/manager > ./config/release/${{ env.CONTROLLER }}.deployment.yaml
80+
echo '[CHANGELOG](https://github.com/DoodleScheduling/${{ env.CONTROLLER }}/blob/master/CHANGELOG.md)' > ./config/release/notes.md
81+
- uses: anchore/sbom-action/download-syft@v0
82+
- name: Create release and SBOM
83+
if: startsWith(github.ref, 'refs/tags/v')
84+
uses: goreleaser/goreleaser-action@v2
85+
with:
86+
version: latest
87+
args: release --release-notes=config/release/notes.md --rm-dist --skip-validate
88+
env:
89+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/size-labeler.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name: size-label
2+
on: pull_request
3+
jobs:
4+
size-label:
5+
runs-on: ubuntu-latest
6+
steps:
7+
- name: size-label
8+
uses: "pascalgn/size-label-action@851c37f157f7d64e56f41ff5d2d80316299b2d47"
9+
env:
10+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

0 commit comments

Comments
 (0)