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

Generate crds #38

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
6 changes: 4 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-go@v4
- run: go install github.com/google/yamlfmt/cmd/yamlfmt@latest
- run: cd charts/db-operator && ./scripts/gen_crds
- uses: actions/setup-python@v3
with:
python-version: 3.7
Expand All @@ -56,7 +58,7 @@ jobs:
- name: Run chart-testing (list-changed)
id: list-changed
run: |
changed=$(ct list-changed --chart-dirs helm --target-branch ${{ github.event.repository.default_branch }})
changed=$(ct list-changed --target-branch ${{ github.event.repository.default_branch }})
if [[ -n "$changed" ]]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
fi
Expand Down
2 changes: 1 addition & 1 deletion 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
name: db-operator
version: 1.16.1
version: 1.17.0
# ---------------------------------------------------------------------------------
# -- All supported k8s versions are in the test:
# -- https://github.com/db-operator/charts/blob/main/.github/workflows/test.yaml
Expand Down
34 changes: 34 additions & 0 deletions charts/db-operator/scripts/crd.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{{- if .Values.crds.install }}
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: ${CRD_CONTROLLER_GEN_VERSION}
{{- if .Values.webhook.certificate.create }}
cert-manager.io/inject-ca-from: {{ .Release.Namespace }}/{{ .Values.webhook.certificate.name}}
{{ else }}
cert-manager.io/inject-ca-from-secret: {{ .Release.Namespace }}/{{ .Values.webhook.certificate.secretName}}
{{- end }}
{{- if .Values.crds.keep }}
helm.sh/resource-policy: keep
{{- end }}
{{- with .Values.crds.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
name: ${CRD_NAME}
spec:
{{- if .Values.webhook.enabled }}
conversion:
strategy: Webhook
webhook:
clientConfig:
service:
namespace: {{ .Release.Namespace }}
name: {{ include "webhook.name" . }}
path: /convert
conversionReviewVersions:
${CRD_CONVERSION_VERSIONS}
{{- end }}
${CRD_SPEC}
{{- end }}
32 changes: 32 additions & 0 deletions charts/db-operator/scripts/gen_crds
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/env bash

# Get the current db-operator version
VERSION=$(yq .appVersion Chart.yaml)
echo $VERSION

CURRENT_DIR=${PWD}
CRD_DIR="${PWD}/templates/crds"
mkdir "${CRD_DIR}"

# Prepare the db-operator repo
cd /tmp
git clone git@github.com:db-operator/db-operator.git dbo
cd dbo
git checkout "v${VERSION}"

# Generate CRDs
for crd in $(find config/crd/bases -type f); do
export CRD_SPEC=$(yq '.spec' $crd | yamlfmt - | sed -e 's/^/ /')
export CRD_NAME=$(yq '.metadata.name' $crd)
export CRD_CONTROLLER_GEN_VERSION=$(yq '.metadata.annotations."controller-gen.kubebuilder.io/version"' $crd)
CRD_PLURAL_NAME=$(yq '.spec.names.plural' $crd)
export CRD_CONVERSION_VERSIONS=$(yq '.spec.conversion.webhook.conversionReviewVersions' \
./config/crd/patches/webhook_in_$CRD_PLURAL_NAME.yaml | sed -e 's/^/ /')
WEBHOOK_FILE_NAME="webhook_in_${CRD_PLURAL_NAME}.yaml"
envsubst < $CURRENT_DIR/scripts/crd.tmpl > $CRD_DIR/$CRD_NAME.yaml
done

# Cleanup
rm -rf /tmp/dbo


Loading
Loading