From dcab3283ae0b2464f366b9c9aceacb2adf0b5eeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Ma=C5=82ek?= Date: Mon, 23 Dec 2024 16:51:01 +0100 Subject: [PATCH] feat: add version information to CRDs --- .github/workflows/release.yaml | 27 ++++++++++----- .../workflows/release_on_version_change.yaml | 33 +++++++++++++++++++ Makefile | 3 +- README.md | 19 +++++++++-- VERSION | 2 ++ ...uration.konghq.com_kongcacertificates.yaml | 1 + ...iguration.konghq.com_kongcertificates.yaml | 1 + ...uration.konghq.com_kongconsumergroups.yaml | 1 + ...onfiguration.konghq.com_kongconsumers.yaml | 1 + ...uration.konghq.com_kongcredentialacls.yaml | 1 + ...tion.konghq.com_kongcredentialapikeys.yaml | 1 + ...n.konghq.com_kongcredentialbasicauths.yaml | 1 + ...ration.konghq.com_kongcredentialhmacs.yaml | 1 + ...uration.konghq.com_kongcredentialjwts.yaml | 1 + ...q.com_kongdataplaneclientcertificates.yaml | 1 + .../configuration.konghq.com_kongkeys.yaml | 1 + .../configuration.konghq.com_kongkeysets.yaml | 1 + ...configuration.konghq.com_konglicenses.yaml | 1 + ...uration.konghq.com_kongpluginbindings.yaml | 1 + .../configuration.konghq.com_kongplugins.yaml | 1 + .../configuration.konghq.com_kongroutes.yaml | 1 + ...configuration.konghq.com_kongservices.yaml | 1 + .../configuration.konghq.com_kongsnis.yaml | 1 + .../configuration.konghq.com_kongtargets.yaml | 1 + ...onfiguration.konghq.com_kongupstreams.yaml | 1 + .../configuration.konghq.com_kongvaults.yaml | 1 + ...nghq.com_konnectapiauthconfigurations.yaml | 1 + ...onghq.com_konnectgatewaycontrolplanes.yaml | 1 + ...troller.konghq.com_kongservicefacades.yaml | 1 + ...n.konghq.com_ingressclassparameterses.yaml | 1 + ...uration.konghq.com_kongclusterplugins.yaml | 1 + ...uration.konghq.com_kongconsumergroups.yaml | 1 + ...onfiguration.konghq.com_kongconsumers.yaml | 1 + ...uration.konghq.com_kongcustomentities.yaml | 1 + ...onfiguration.konghq.com_kongingresses.yaml | 1 + ...configuration.konghq.com_konglicenses.yaml | 1 + .../configuration.konghq.com_kongplugins.yaml | 1 + ...ation.konghq.com_kongupstreampolicies.yaml | 1 + .../configuration.konghq.com_kongvaults.yaml | 1 + ...configuration.konghq.com_tcpingresses.yaml | 1 + ...configuration.konghq.com_udpingresses.yaml | 1 + scripts/crds-generator/main.go | 28 +++++++++++++++- 42 files changed, 135 insertions(+), 13 deletions(-) create mode 100644 .github/workflows/release_on_version_change.yaml create mode 100644 VERSION diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 437d6e8..71a83c8 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -2,6 +2,16 @@ name: Create release run-name: "Release ${{ format('{0} (branch: {1})', inputs.tag, github.ref_name) }} " on: + workflow_call: + inputs: + tag: + description: "Tag to release (e.g. v1.0.0)" + required: true + type: string + latest: + description: "Whether to tag this release latest" + required: true + type: boolean workflow_dispatch: inputs: tag: @@ -12,7 +22,6 @@ on: description: "Whether to tag this release latest" required: true type: boolean - default: false jobs: tests: @@ -29,7 +38,7 @@ jobs: - uses: mukunku/tag-exists-action@v1.6.0 id: check-tag with: - tag: ${{ github.event.inputs.tag }} + tag: ${{ inputs.tag }} env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: fail if tag already exists @@ -39,7 +48,7 @@ jobs: id: parse-semver uses: booxmedialtd/ws-action-parse-semver@v1.4.7 with: - input_string: ${{ github.event.inputs.tag }} + input_string: ${{ inputs.tag }} version_extractor_regex: 'v(.*)$' release: @@ -56,16 +65,16 @@ jobs: See [changelog] for a complete list of changes. - [changelog]: https://github.com/${{ github.repository }}/blob/main/CHANGELOG.md#${{ github.event.inputs.tag }} + [changelog]: https://github.com/${{ github.repository }}/blob/main/CHANGELOG.md#${{ inputs.tag }} #### Install CRDs from all channels ```shell - kustomize build github.com/${{ github.repository }}/config/crd/gateway-operator\?ref=${{ github.event.inputs.tag }} | kubectl apply -f - - kustomize build github.com/${{ github.repository }}/config/crd/ingress-controller\?ref=${{ github.event.inputs.tag }} | kubectl apply -f - - kustomize build github.com/${{ github.repository }}/config/crd/ingress-controller-incubator\?ref=${{ github.event.inputs.tag }} | kubectl apply -f - + kustomize build github.com/${{ github.repository }}/config/crd/gateway-operator\?ref=${{ inputs.tag }} | kubectl apply -f - + kustomize build github.com/${{ github.repository }}/config/crd/ingress-controller\?ref=${{ inputs.tag }} | kubectl apply -f - + kustomize build github.com/${{ github.repository }}/config/crd/ingress-controller-incubator\?ref=${{ inputs.tag }} | kubectl apply -f - ``` token: ${{ secrets.GITHUB_TOKEN }} - tag: ${{ github.event.inputs.tag }} + tag: ${{ inputs.tag }} commit: ${{ github.sha }} prerelease: ${{ needs.verify-tag.outputs.prerelease != '' }} - makeLatest: ${{ github.event.inputs.latest == 'true' }} + makeLatest: ${{ inputs.latest == 'true' }} diff --git a/.github/workflows/release_on_version_change.yaml b/.github/workflows/release_on_version_change.yaml new file mode 100644 index 0000000..467ca38 --- /dev/null +++ b/.github/workflows/release_on_version_change.yaml @@ -0,0 +1,33 @@ +name: Trigger release based on VERSION file change + +on: + push: + paths: + - VERSION + branches: + - main + +jobs: + version: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.version.outputs.version }} + latest: ${{ steps.version.outputs.version == 'latest' }} + steps: + - uses: actions/checkout@v4 + - id: version + run: | + echo "version=$(head -1 VERSION)" >> "$GITHUB_OUTPUT" + echo "latest=$(tail -1 VERSION)" >> "$GITHUB_OUTPUT" + - name: Validate semver + uses: booxmedialtd/ws-action-parse-semver@v1.4.7 + with: + input_string: ${{ steps.version.outputs.version }} + version_extractor_regex: 'v(.*)$' + trigger_release: + needs: + - version + uses: ./.github/workflows/release.yaml + with: + tag: ${{ needs.version.outputs.version }} + latest: ${{ needs.version.outputs.latest }} diff --git a/Makefile b/Makefile index 0c9fc1d..b3e1fbe 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,7 @@ REPO_URL ?= github.com/kong/kubernetes-configuration # NOTE: this is not neeed now before v2, but will be needed in the future. #GO_MOD_MAJOR_VERSION ?= $(subst $(REPO_URL)/,,$(shell go list -m)) REPO_INFO ?= $(shell git config --get remote.origin.url) +VERSION ?= $(shell head -1 VERSION) ifndef COMMIT COMMIT := $(shell git rev-parse --short HEAD) @@ -155,7 +156,7 @@ generate.apitypes-funcs: .PHONY: generate.crds generate.crds: controller-gen ## Generate WebhookConfiguration and CustomResourceDefinition objects. # Use gotypesalias=0 as a workaround for https://github.com/kubernetes-sigs/controller-tools/issues/1088. - GODEBUG=gotypesalias=0 go run ./scripts/crds-generator + VERSION=$(VERSION) GODEBUG=gotypesalias=0 go run ./scripts/crds-generator .PHONY: generate.deepcopy generate.deepcopy: controller-gen diff --git a/README.md b/README.md index 8b845b4..ea27035 100644 --- a/README.md +++ b/README.md @@ -80,10 +80,25 @@ When you add a new CRD make sure to ## How to release? +Releases are driven by changes in the [`VERSION`](./VERSION) file. +This file contains 2 lines: + +- The first line is the version number (e.g. `1.0.0`). +- The second line indicates if the version should be marked as latest or not + (e.g. `latest` for latest, anything else is not marked as latest). + +To release a new version: + +- Pick a new version. - Make sure a changelog is updated with the new version, the release date, and all the changes. -- Trigger a [release workflow]. This will create a tag a release in GitHub. +- Update the [`VERSION`](./VERSION) file with said version and whether the version should be marked as latest. + This can be done in a separate PR or along with the PR that introduces the changes. + +The [`release_on_version_change.yaml`][release_on_change_workflow] +workflow will be triggered when a commit changing the `VERSION` file is pushed to the `main` branch. +Releases created with this approach will be marked as latest -[release workflow]: https://github.com/Kong/kubernetes-configuration/actions/workflows/release.yaml +[release_on_change_workflow]: .github/workflows/release_on_version_change.yaml ## Available custom markers diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..38bfbed --- /dev/null +++ b/VERSION @@ -0,0 +1,2 @@ +v1.0.1 +latest diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongcacertificates.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongcacertificates.yaml index 89ad746..80ec4e7 100644 --- a/config/crd/gateway-operator/configuration.konghq.com_kongcacertificates.yaml +++ b/config/crd/gateway-operator/configuration.konghq.com_kongcacertificates.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: gateway-operator + kubernetes-configuration.konghq.com/version: v1.0.1 name: kongcacertificates.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongcertificates.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongcertificates.yaml index 4e06b3d..bf9c089 100644 --- a/config/crd/gateway-operator/configuration.konghq.com_kongcertificates.yaml +++ b/config/crd/gateway-operator/configuration.konghq.com_kongcertificates.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: gateway-operator + kubernetes-configuration.konghq.com/version: v1.0.1 name: kongcertificates.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongconsumergroups.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongconsumergroups.yaml index e6bcc9b..8a31c1b 100644 --- a/config/crd/gateway-operator/configuration.konghq.com_kongconsumergroups.yaml +++ b/config/crd/gateway-operator/configuration.konghq.com_kongconsumergroups.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: ingress-controller,gateway-operator + kubernetes-configuration.konghq.com/version: v1.0.1 name: kongconsumergroups.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongconsumers.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongconsumers.yaml index a9858db..430dabc 100644 --- a/config/crd/gateway-operator/configuration.konghq.com_kongconsumers.yaml +++ b/config/crd/gateway-operator/configuration.konghq.com_kongconsumers.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: ingress-controller,gateway-operator + kubernetes-configuration.konghq.com/version: v1.0.1 name: kongconsumers.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongcredentialacls.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongcredentialacls.yaml index 08364c1..1a8dd1a 100644 --- a/config/crd/gateway-operator/configuration.konghq.com_kongcredentialacls.yaml +++ b/config/crd/gateway-operator/configuration.konghq.com_kongcredentialacls.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: gateway-operator + kubernetes-configuration.konghq.com/version: v1.0.1 name: kongcredentialacls.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongcredentialapikeys.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongcredentialapikeys.yaml index 2f4ca9c..f34e4a8 100644 --- a/config/crd/gateway-operator/configuration.konghq.com_kongcredentialapikeys.yaml +++ b/config/crd/gateway-operator/configuration.konghq.com_kongcredentialapikeys.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: gateway-operator + kubernetes-configuration.konghq.com/version: v1.0.1 name: kongcredentialapikeys.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongcredentialbasicauths.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongcredentialbasicauths.yaml index a25489c..79b8f17 100644 --- a/config/crd/gateway-operator/configuration.konghq.com_kongcredentialbasicauths.yaml +++ b/config/crd/gateway-operator/configuration.konghq.com_kongcredentialbasicauths.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: gateway-operator + kubernetes-configuration.konghq.com/version: v1.0.1 name: kongcredentialbasicauths.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongcredentialhmacs.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongcredentialhmacs.yaml index 320bfcc..ec49742 100644 --- a/config/crd/gateway-operator/configuration.konghq.com_kongcredentialhmacs.yaml +++ b/config/crd/gateway-operator/configuration.konghq.com_kongcredentialhmacs.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: gateway-operator + kubernetes-configuration.konghq.com/version: v1.0.1 name: kongcredentialhmacs.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongcredentialjwts.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongcredentialjwts.yaml index 0479318..63a63cd 100644 --- a/config/crd/gateway-operator/configuration.konghq.com_kongcredentialjwts.yaml +++ b/config/crd/gateway-operator/configuration.konghq.com_kongcredentialjwts.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: gateway-operator + kubernetes-configuration.konghq.com/version: v1.0.1 name: kongcredentialjwts.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongdataplaneclientcertificates.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongdataplaneclientcertificates.yaml index e1824fe..6849d57 100644 --- a/config/crd/gateway-operator/configuration.konghq.com_kongdataplaneclientcertificates.yaml +++ b/config/crd/gateway-operator/configuration.konghq.com_kongdataplaneclientcertificates.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: gateway-operator + kubernetes-configuration.konghq.com/version: v1.0.1 name: kongdataplaneclientcertificates.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongkeys.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongkeys.yaml index c2c458c..27be046 100644 --- a/config/crd/gateway-operator/configuration.konghq.com_kongkeys.yaml +++ b/config/crd/gateway-operator/configuration.konghq.com_kongkeys.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: gateway-operator + kubernetes-configuration.konghq.com/version: v1.0.1 name: kongkeys.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongkeysets.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongkeysets.yaml index 02d4b01..292f878 100644 --- a/config/crd/gateway-operator/configuration.konghq.com_kongkeysets.yaml +++ b/config/crd/gateway-operator/configuration.konghq.com_kongkeysets.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: gateway-operator + kubernetes-configuration.konghq.com/version: v1.0.1 name: kongkeysets.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/gateway-operator/configuration.konghq.com_konglicenses.yaml b/config/crd/gateway-operator/configuration.konghq.com_konglicenses.yaml index 0bab85e..55291ae 100644 --- a/config/crd/gateway-operator/configuration.konghq.com_konglicenses.yaml +++ b/config/crd/gateway-operator/configuration.konghq.com_konglicenses.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: ingress-controller,gateway-operator + kubernetes-configuration.konghq.com/version: v1.0.1 name: konglicenses.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongpluginbindings.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongpluginbindings.yaml index 3a0a7f0..fa8d44a 100644 --- a/config/crd/gateway-operator/configuration.konghq.com_kongpluginbindings.yaml +++ b/config/crd/gateway-operator/configuration.konghq.com_kongpluginbindings.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: gateway-operator + kubernetes-configuration.konghq.com/version: v1.0.1 name: kongpluginbindings.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongplugins.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongplugins.yaml index f8a2bdc..0d99ac1 100644 --- a/config/crd/gateway-operator/configuration.konghq.com_kongplugins.yaml +++ b/config/crd/gateway-operator/configuration.konghq.com_kongplugins.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: ingress-controller,gateway-operator + kubernetes-configuration.konghq.com/version: v1.0.1 name: kongplugins.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongroutes.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongroutes.yaml index daae4b8..fc7914f 100644 --- a/config/crd/gateway-operator/configuration.konghq.com_kongroutes.yaml +++ b/config/crd/gateway-operator/configuration.konghq.com_kongroutes.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: gateway-operator + kubernetes-configuration.konghq.com/version: v1.0.1 name: kongroutes.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongservices.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongservices.yaml index 299d18a..943219b 100644 --- a/config/crd/gateway-operator/configuration.konghq.com_kongservices.yaml +++ b/config/crd/gateway-operator/configuration.konghq.com_kongservices.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: gateway-operator + kubernetes-configuration.konghq.com/version: v1.0.1 name: kongservices.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongsnis.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongsnis.yaml index 0d28b2f..a1be7ac 100644 --- a/config/crd/gateway-operator/configuration.konghq.com_kongsnis.yaml +++ b/config/crd/gateway-operator/configuration.konghq.com_kongsnis.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: gateway-operator + kubernetes-configuration.konghq.com/version: v1.0.1 name: kongsnis.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongtargets.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongtargets.yaml index ff4b8d0..3164df8 100644 --- a/config/crd/gateway-operator/configuration.konghq.com_kongtargets.yaml +++ b/config/crd/gateway-operator/configuration.konghq.com_kongtargets.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: gateway-operator + kubernetes-configuration.konghq.com/version: v1.0.1 name: kongtargets.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongupstreams.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongupstreams.yaml index 0369b90..60130e6 100644 --- a/config/crd/gateway-operator/configuration.konghq.com_kongupstreams.yaml +++ b/config/crd/gateway-operator/configuration.konghq.com_kongupstreams.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: gateway-operator + kubernetes-configuration.konghq.com/version: v1.0.1 name: kongupstreams.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/gateway-operator/configuration.konghq.com_kongvaults.yaml b/config/crd/gateway-operator/configuration.konghq.com_kongvaults.yaml index 26b463b..83e0667 100644 --- a/config/crd/gateway-operator/configuration.konghq.com_kongvaults.yaml +++ b/config/crd/gateway-operator/configuration.konghq.com_kongvaults.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: ingress-controller,gateway-operator + kubernetes-configuration.konghq.com/version: v1.0.1 name: kongvaults.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/gateway-operator/konnect.konghq.com_konnectapiauthconfigurations.yaml b/config/crd/gateway-operator/konnect.konghq.com_konnectapiauthconfigurations.yaml index 88a8758..5e900c2 100644 --- a/config/crd/gateway-operator/konnect.konghq.com_konnectapiauthconfigurations.yaml +++ b/config/crd/gateway-operator/konnect.konghq.com_konnectapiauthconfigurations.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: gateway-operator + kubernetes-configuration.konghq.com/version: v1.0.1 name: konnectapiauthconfigurations.konnect.konghq.com spec: group: konnect.konghq.com diff --git a/config/crd/gateway-operator/konnect.konghq.com_konnectgatewaycontrolplanes.yaml b/config/crd/gateway-operator/konnect.konghq.com_konnectgatewaycontrolplanes.yaml index f1442ab..5c2ece6 100644 --- a/config/crd/gateway-operator/konnect.konghq.com_konnectgatewaycontrolplanes.yaml +++ b/config/crd/gateway-operator/konnect.konghq.com_konnectgatewaycontrolplanes.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: gateway-operator + kubernetes-configuration.konghq.com/version: v1.0.1 name: konnectgatewaycontrolplanes.konnect.konghq.com spec: group: konnect.konghq.com diff --git a/config/crd/ingress-controller-incubator/incubator.ingress-controller.konghq.com_kongservicefacades.yaml b/config/crd/ingress-controller-incubator/incubator.ingress-controller.konghq.com_kongservicefacades.yaml index fd5f70e..2ff1e9d 100644 --- a/config/crd/ingress-controller-incubator/incubator.ingress-controller.konghq.com_kongservicefacades.yaml +++ b/config/crd/ingress-controller-incubator/incubator.ingress-controller.konghq.com_kongservicefacades.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: ingress-controller-incubator + kubernetes-configuration.konghq.com/version: v1.0.1 name: kongservicefacades.incubator.ingress-controller.konghq.com spec: group: incubator.ingress-controller.konghq.com diff --git a/config/crd/ingress-controller/configuration.konghq.com_ingressclassparameterses.yaml b/config/crd/ingress-controller/configuration.konghq.com_ingressclassparameterses.yaml index 99533cd..b957d93 100644 --- a/config/crd/ingress-controller/configuration.konghq.com_ingressclassparameterses.yaml +++ b/config/crd/ingress-controller/configuration.konghq.com_ingressclassparameterses.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: ingress-controller + kubernetes-configuration.konghq.com/version: v1.0.1 name: ingressclassparameterses.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/ingress-controller/configuration.konghq.com_kongclusterplugins.yaml b/config/crd/ingress-controller/configuration.konghq.com_kongclusterplugins.yaml index d37b4be..7894288 100644 --- a/config/crd/ingress-controller/configuration.konghq.com_kongclusterplugins.yaml +++ b/config/crd/ingress-controller/configuration.konghq.com_kongclusterplugins.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: ingress-controller + kubernetes-configuration.konghq.com/version: v1.0.1 name: kongclusterplugins.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/ingress-controller/configuration.konghq.com_kongconsumergroups.yaml b/config/crd/ingress-controller/configuration.konghq.com_kongconsumergroups.yaml index e6bcc9b..8a31c1b 100644 --- a/config/crd/ingress-controller/configuration.konghq.com_kongconsumergroups.yaml +++ b/config/crd/ingress-controller/configuration.konghq.com_kongconsumergroups.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: ingress-controller,gateway-operator + kubernetes-configuration.konghq.com/version: v1.0.1 name: kongconsumergroups.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/ingress-controller/configuration.konghq.com_kongconsumers.yaml b/config/crd/ingress-controller/configuration.konghq.com_kongconsumers.yaml index a9858db..430dabc 100644 --- a/config/crd/ingress-controller/configuration.konghq.com_kongconsumers.yaml +++ b/config/crd/ingress-controller/configuration.konghq.com_kongconsumers.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: ingress-controller,gateway-operator + kubernetes-configuration.konghq.com/version: v1.0.1 name: kongconsumers.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/ingress-controller/configuration.konghq.com_kongcustomentities.yaml b/config/crd/ingress-controller/configuration.konghq.com_kongcustomentities.yaml index 25ae59e..91d3028 100644 --- a/config/crd/ingress-controller/configuration.konghq.com_kongcustomentities.yaml +++ b/config/crd/ingress-controller/configuration.konghq.com_kongcustomentities.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: ingress-controller + kubernetes-configuration.konghq.com/version: v1.0.1 name: kongcustomentities.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/ingress-controller/configuration.konghq.com_kongingresses.yaml b/config/crd/ingress-controller/configuration.konghq.com_kongingresses.yaml index ab55608..8b70818 100644 --- a/config/crd/ingress-controller/configuration.konghq.com_kongingresses.yaml +++ b/config/crd/ingress-controller/configuration.konghq.com_kongingresses.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: ingress-controller + kubernetes-configuration.konghq.com/version: v1.0.1 name: kongingresses.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/ingress-controller/configuration.konghq.com_konglicenses.yaml b/config/crd/ingress-controller/configuration.konghq.com_konglicenses.yaml index 0bab85e..55291ae 100644 --- a/config/crd/ingress-controller/configuration.konghq.com_konglicenses.yaml +++ b/config/crd/ingress-controller/configuration.konghq.com_konglicenses.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: ingress-controller,gateway-operator + kubernetes-configuration.konghq.com/version: v1.0.1 name: konglicenses.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/ingress-controller/configuration.konghq.com_kongplugins.yaml b/config/crd/ingress-controller/configuration.konghq.com_kongplugins.yaml index f8a2bdc..0d99ac1 100644 --- a/config/crd/ingress-controller/configuration.konghq.com_kongplugins.yaml +++ b/config/crd/ingress-controller/configuration.konghq.com_kongplugins.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: ingress-controller,gateway-operator + kubernetes-configuration.konghq.com/version: v1.0.1 name: kongplugins.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/ingress-controller/configuration.konghq.com_kongupstreampolicies.yaml b/config/crd/ingress-controller/configuration.konghq.com_kongupstreampolicies.yaml index 860a1c7..3bc9b21 100644 --- a/config/crd/ingress-controller/configuration.konghq.com_kongupstreampolicies.yaml +++ b/config/crd/ingress-controller/configuration.konghq.com_kongupstreampolicies.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: ingress-controller + kubernetes-configuration.konghq.com/version: v1.0.1 labels: gateway.networking.k8s.io/policy: direct name: kongupstreampolicies.configuration.konghq.com diff --git a/config/crd/ingress-controller/configuration.konghq.com_kongvaults.yaml b/config/crd/ingress-controller/configuration.konghq.com_kongvaults.yaml index 26b463b..83e0667 100644 --- a/config/crd/ingress-controller/configuration.konghq.com_kongvaults.yaml +++ b/config/crd/ingress-controller/configuration.konghq.com_kongvaults.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: ingress-controller,gateway-operator + kubernetes-configuration.konghq.com/version: v1.0.1 name: kongvaults.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/ingress-controller/configuration.konghq.com_tcpingresses.yaml b/config/crd/ingress-controller/configuration.konghq.com_tcpingresses.yaml index 02f2562..7e99ca0 100644 --- a/config/crd/ingress-controller/configuration.konghq.com_tcpingresses.yaml +++ b/config/crd/ingress-controller/configuration.konghq.com_tcpingresses.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: ingress-controller + kubernetes-configuration.konghq.com/version: v1.0.1 name: tcpingresses.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/config/crd/ingress-controller/configuration.konghq.com_udpingresses.yaml b/config/crd/ingress-controller/configuration.konghq.com_udpingresses.yaml index af78a19..56f1736 100644 --- a/config/crd/ingress-controller/configuration.konghq.com_udpingresses.yaml +++ b/config/crd/ingress-controller/configuration.konghq.com_udpingresses.yaml @@ -4,6 +4,7 @@ kind: CustomResourceDefinition metadata: annotations: kubernetes-configuration.konghq.com/channels: ingress-controller + kubernetes-configuration.konghq.com/version: v1.0.1 name: udpingresses.configuration.konghq.com spec: group: configuration.konghq.com diff --git a/scripts/crds-generator/main.go b/scripts/crds-generator/main.go index 0315781..6167402 100644 --- a/scripts/crds-generator/main.go +++ b/scripts/crds-generator/main.go @@ -31,6 +31,9 @@ const ( // ChannelsAnnotation is the annotation key that's used to mark the channels a CRD belongs to. ChannelsAnnotation = "kubernetes-configuration.konghq.com/channels" + + // VersionAnnotation is the annotation key that's used to mark the version of the CRD. + VersionAnnotation = "kubernetes-configuration.konghq.com/version" ) // AllChannels is a list of all available channels. @@ -38,6 +41,11 @@ var AllChannels = []ChannelType{IngressControllerChannelType, IngressControllerI // Code is inspired by https://github.com/kubernetes-sigs/gateway-api/blob/1fe2b9f8ee99a6475a65eedd1ce060f363a8634d/pkg/generator/main.go. func main() { + version := os.Getenv("VERSION") + if version == "" { + log.Fatalf("VERSION environment variable is required") + } + roots, err := loader.LoadRoots( // Needed to parse generated register functions. "k8s.io/apimachinery/pkg/runtime/schema", @@ -71,6 +79,7 @@ func main() { yamlOpts := []*genall.WriteYAMLOptions{ genall.WithTransform(transformRemoveCRDStatus), genall.WithTransform(genall.TransformRemoveCreationTimestamp), + genall.WithTransform(addVersion(version)), } generator := &crd.Generator{} @@ -141,7 +150,6 @@ kind: Kustomization resources: %s` resources := strings.Join(lo.Map(crdFiles, func(f string, _ int) string { - return fmt.Sprintf(" - %s", filepath.Base(f)) }), "\n") kustomizeContent := fmt.Sprintf(kustomizeFileTemplate, resources) @@ -192,3 +200,21 @@ func transformRemoveCRDStatus(obj map[string]interface{}) error { delete(obj, "status") return nil } + +// addVersion adds the version annotation to the CRD. +func addVersion(version string) func(obj map[string]interface{}) error { + return func(obj map[string]interface{}) error { + metadata, ok := obj["metadata"] + if !ok { + metadata = map[string]interface{}{} + obj["metadata"] = metadata + } + annotations, ok := metadata.(map[interface{}]interface{})["annotations"] + if !ok { + annotations = map[string]interface{}{} + obj["metadata"].(map[string]interface{})["annotations"] = metadata + } + annotations.(map[interface{}]interface{})[VersionAnnotation] = version + return nil + } +}