Skip to content

Commit

Permalink
Update CRDs to v1beta1 (#12)
Browse files Browse the repository at this point in the history
Now, `CRDs` are put in the `./templates` folder. If you don't want `helm` to manage them, you can set `Values.crds.install: false`.
  • Loading branch information
allanger authored Mar 15, 2023
1 parent 74a1f9d commit f6d1307
Show file tree
Hide file tree
Showing 23 changed files with 935 additions and 223 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/chart-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

Expand All @@ -23,7 +23,7 @@ jobs:
git config user.email "$GITHUB_ACTOR@users.noreply.github.com"
- name: Install Helm
uses: azure/setup-helm@v1
uses: azure/setup-helm@v3
with:
version: v3.9.4

Expand Down
16 changes: 10 additions & 6 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
changed_charts: ${{ steps.get-chart.outputs.changed_charts }}
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
path: charts
fetch-depth: 2 # to be able to obtain files changed in the latest commit
Expand All @@ -33,16 +33,16 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-python@v2
- uses: actions/setup-python@v3
with:
python-version: 3.7

- name: Install Helm
uses: azure/setup-helm@v1
uses: azure/setup-helm@v3
with:
version: v3.9.4

Expand All @@ -61,7 +61,7 @@ jobs:
k8s_version: ['v1.21.6', 'v1.22.3', 'v1.23.1', 'v1.24.3']
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3

# The existing apparmor profile for mysql needs to be removed.
# https://github.com/actions/virtual-environments/issues/181
Expand All @@ -70,6 +70,7 @@ jobs:
run: |
set -x
sudo apt-get remove mysql-server --purge
sudo apt-get update -y
sudo apt-get install apparmor-profiles
sudo apparmor_parser -R /etc/apparmor.d/usr.sbin.mysqld
Expand All @@ -78,8 +79,11 @@ jobs:
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
run: ./tests/db-operator/integration.sh
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,11 @@ lint: ## lint helm manifests
@helm lint -f charts/db-operator/values.yaml -f charts/db-operator/ci/ci-1-values.yaml --strict ./charts/db-operator
@helm lint -f charts/db-instances/values.yaml --strict ./charts/db-instances

cert-manager: ## install cert-manager chart if not exist and install local chart using helm upgrade --install command
@helm repo add jetstack https://charts.jetstack.io
@helm repo update
@helm upgrade --install --create-namespace --namespace cert-manager cert-manager jetstack/cert-manager --set installCRDs=true

db-operator: ## install db-operator chart if not exist and install local chart using helm upgrade --install command
@helm upgrade --install --create-namespace --namespace operator my-dboperator charts/db-operator -f charts/db-operator/values.yaml -f charts/db-operator/values-local.yaml
@helm upgrade --install --create-namespace --namespace operator my-dboperator charts/db-operator -f charts/db-operator/values.yaml -f charts/db-operator/values-local.yaml
@kubectl rollout status deploy/db-operator -n 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.3.4
version: 1.4.0
2 changes: 1 addition & 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/v1alpha1"
apiVersion: "kci.rocks/v1beta1"
kind: "DbInstance"
metadata:
name: {{ $name }}
Expand Down
4 changes: 2 additions & 2 deletions charts/db-operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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.9.1"
appVersion: "1.10.0"
description: A Database Operator
name: db-operator
version: 1.5.1
version: 1.7.0
20 changes: 20 additions & 0 deletions charts/db-operator/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
# db-operator
DB Operator is Kubernetes operator

## Upgrading to `v1.10.0`
CRDs are moved to the `templates` folder, so now they are part of the release. It means that when migration you will get errors about resource ownership. 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.

For example:

```BASH
$ helm upgrade my-release .
Error: UPGRADE FAILED: rendered manifests contain a resource that already exists. Unable to continue with update: CustomResourceDefinition "databases.kci.rocks" in namespace "" exists and cannot be imported into the current release: invalid ownership metadata; label validation error: missing key "app.kubernetes.io/managed-by": must be set to "Helm"; annotation validation error: missing key "meta.helm.sh/release-name": must be set to "my-release"; annotation validation error: missing key "meta.helm.sh/release-namespace": must be set to "default"
```

So you should add following metadata:
```YAML
metadata:
labels:
"app.kubernetes.io/managed-by": Helm
annotations:
"meta.helm.sh/release-name": my-release
"meta.helm.sh/release-namespace": default
```
## Installing Chart
To install the chart with the release name my-release:
```
Expand Down
196 changes: 0 additions & 196 deletions charts/db-operator/crds/kci.rocks_dbinstances.yaml

This file was deleted.

5 changes: 0 additions & 5 deletions charts/db-operator/crds/readme.md

This file was deleted.

15 changes: 15 additions & 0 deletions charts/db-operator/templates/certificate/certificate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{{- if .Values.webhook.certificate.create }}
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
name: {{ .Values.webhook.certificate.name }}
spec:
dnsNames:
- {{ .Values.webhook.serviceName }}.{{ .Release.Namespace }}.svc
- {{ .Values.webhook.serviceName }}.{{ .Release.Namespace }}.svc.cluster.local
issuerRef:
kind: {{ .Values.webhook.certificate.issuer.kind }}
name: {{ .Values.webhook.certificate.issuer.name }}
secretName: {{ .Values.webhook.certificate.secretName }}
{{- end }}
10 changes: 10 additions & 0 deletions charts/db-operator/templates/certificate/issuer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{- if .Values.webhook.certificate.issuer.create }}
---
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
name: {{ .Values.webhook.certificate.issuer.name }}
namespace: {{ .Release.Namespace }}
spec:
selfSigned: {}
{{- end }}
Loading

0 comments on commit f6d1307

Please sign in to comment.