From 71ab67db9860e4241bdd05f811232d44b10d7da2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Ma=C5=82ek?= Date: Mon, 22 Apr 2024 14:54:23 +0200 Subject: [PATCH 1/6] fix: make creating DataPlanes index conditional on enabling the ControlPlane controller (#103) (#106) --- CHANGELOG.md | 4 ++++ internal/utils/index/index.go | 15 ++++++++++++--- modules/manager/controller_setup.go | 10 ++++++++-- modules/manager/run.go | 2 +- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c41dd3faf..76c109a8a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -31,6 +31,10 @@ autoscaling with `GatewayConfiguration` as the generated `DataPlane` deployment will no longer be rejected. [#79](https://github.com/Kong/gateway-operator/pull/79) +- Make creating a `DataPlane` index conditional based on enabling the `ControlPlane` + controller. This allows running KGO without `ControlPlane` CRD with its controller + disabled. + [#103](https://github.com/Kong/gateway-operator/pull/103) ## [v1.2.1] diff --git a/internal/utils/index/index.go b/internal/utils/index/index.go index 1fa7891bf..7405c9bb1 100644 --- a/internal/utils/index/index.go +++ b/internal/utils/index/index.go @@ -2,7 +2,9 @@ package index import ( "context" + "fmt" + "k8s.io/apimachinery/pkg/api/meta" "sigs.k8s.io/controller-runtime/pkg/cache" "sigs.k8s.io/controller-runtime/pkg/client" @@ -14,10 +16,17 @@ const ( DataPlaneNameIndex = "dataplane" ) -// IndexDataPlaneNameOnControlPlane indexes the ControlPlane .spec.dataplaneName field +// DataPlaneNameOnControlPlane indexes the ControlPlane .spec.dataplaneName field // on the "dataplane" key. -func IndexDataPlaneNameOnControlPlane(c cache.Cache) error { - return c.IndexField(context.Background(), &operatorv1beta1.ControlPlane{}, DataPlaneNameIndex, func(o client.Object) []string { +func DataPlaneNameOnControlPlane(ctx context.Context, c cache.Cache) error { + if _, err := c.GetInformer(ctx, &operatorv1beta1.ControlPlane{}); err != nil { + if meta.IsNoMatchError(err) { + return nil + } + return fmt.Errorf("failed to get informer for v1beta1 ControlPlane: %w, disabling indexing DataPlanes for ControlPlanes' .spec.dataplaneName", err) + } + + return c.IndexField(ctx, &operatorv1beta1.ControlPlane{}, DataPlaneNameIndex, func(o client.Object) []string { controlPlane, ok := o.(*operatorv1beta1.ControlPlane) if !ok { return []string{} diff --git a/modules/manager/controller_setup.go b/modules/manager/controller_setup.go index b8d2a809e..724cb319c 100644 --- a/modules/manager/controller_setup.go +++ b/modules/manager/controller_setup.go @@ -1,6 +1,7 @@ package manager import ( + "context" "errors" "fmt" "net/url" @@ -93,8 +94,13 @@ func (c *ControllerDef) MaybeSetupWithManager(mgr ctrl.Manager) error { return c.Controller.SetupWithManager(mgr) } -func setupIndexes(mgr manager.Manager) error { - return index.IndexDataPlaneNameOnControlPlane(mgr.GetCache()) +func setupIndexes(ctx context.Context, mgr manager.Manager, cfg Config) error { + if cfg.ControlPlaneControllerEnabled || cfg.GatewayControllerEnabled { + if err := index.DataPlaneNameOnControlPlane(ctx, mgr.GetCache()); err != nil { + return fmt.Errorf("failed to setup index for DataPlane names on ControlPlane: %w", err) + } + } + return nil } // SetupControllers returns a list of ControllerDefs based on config. diff --git a/modules/manager/run.go b/modules/manager/run.go index 427606c68..97a74ef3d 100644 --- a/modules/manager/run.go +++ b/modules/manager/run.go @@ -186,7 +186,7 @@ func Run( return fmt.Errorf("unable to start manager: %w", err) } - if err := setupIndexes(mgr); err != nil { + if err := setupIndexes(context.Background(), mgr, cfg); err != nil { return err } From fcd09c8effa3baa15df6d7f9a0cc74a7a09a8a19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Ma=C5=82ek?= Date: Mon, 22 Apr 2024 18:46:44 +0200 Subject: [PATCH 2/6] fix(ci): fix release CI by adding mise installation steps --- .github/workflows/__release-workflow.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/__release-workflow.yaml b/.github/workflows/__release-workflow.yaml index 3426cb907..ce383e8c7 100644 --- a/.github/workflows/__release-workflow.yaml +++ b/.github/workflows/__release-workflow.yaml @@ -132,6 +132,10 @@ jobs: with: go-version-file: go.mod + - uses: jdx/mise-action@v2 + with: + install: false + - name: integration tests run: make test.integration env: @@ -160,6 +164,10 @@ jobs: with: go-version-file: go.mod + - uses: jdx/mise-action@v2 + with: + install: false + - name: E2E Tests run: make test.e2e env: @@ -203,6 +211,10 @@ jobs: echo "VERSION=${VERSION}" >> $GITHUB_ENV echo ${VERSION} > VERSION + - uses: jdx/mise-action@v2 + with: + install: false + # Generated manifests are part of the release PR. - name: Generate manifests if: ${{ inputs.regenerate-manifests }} From cd6df76e05e645e20a1f555007b265803bfbc9a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Ma=C5=82ek?= Date: Tue, 23 Apr 2024 15:30:29 +0200 Subject: [PATCH 3/6] fix(ci): fix release CI to work with release branches (#206) * fix(ci): fix release CI to work with release branches * fix(ci): trigger a PR against main when a release on a release branch is created * chore: go mod tidy --- .github/workflows/__release-workflow.yaml | 63 +++++++++++++++++------ .github/workflows/release-bot.yaml | 1 + .github/workflows/release.yaml | 8 ++- go.mod | 6 +++ 4 files changed, 62 insertions(+), 16 deletions(-) diff --git a/.github/workflows/__release-workflow.yaml b/.github/workflows/__release-workflow.yaml index ce383e8c7..70b027e41 100644 --- a/.github/workflows/__release-workflow.yaml +++ b/.github/workflows/__release-workflow.yaml @@ -1,5 +1,5 @@ name: Reusable release -run-name: "Release ${{ format('{0} (type: {1})', inputs.tag, inputs.release-type) }} " +run-name: "Release ${{ format('{0} (type: {1}) (branch: {2})', inputs.tag, inputs.release-type, inputs.base) }} " on: workflow_call: @@ -28,6 +28,11 @@ on: description: The version to release (e.g. v1.2.3) type: string required: true + base: + description: The base branch from which to release and against which to create a release PR. + type: string + default: 'main' + required: false latest: description: Whether to mark this release latest type: boolean @@ -174,6 +179,11 @@ jobs: KONG_LICENSE_DATA: ${{ secrets.kong-license-data }} KONG_TEST_GATEWAY_OPERATOR_IMAGE_OVERRIDE: ${{ needs.build-push-images.outputs.full_tag }} + # NOTE: This job's steps are run when: + # - input.base is 'main': then 1 PR is created targeting 'main' + # - input.base is not 'main': then 2 PRs will be created: + # - 1 PR targeting 'main' to update VERSION and config/ + # - 1 PR targeting the release branch to update VERSION and config/ and trigger the release workflow create-release-pr: runs-on: ubuntu-latest needs: @@ -181,30 +191,39 @@ jobs: - build-push-images - test-integration-current-kubernetes - test-e2e-current-kubernetes + strategy: + matrix: + base: + - ${{ inputs.base }} + - main steps: - # Use the main branch as a base for the release. - # Any changes made on the branch that the workflow was triggered on will not be included - # in the release PR. If anything needs to be fixed before a release, it should be - # done on the main branch. + # Use the branch set via inputs as a base for the release. + # If anything needs to be fixed before the release, it should be done on the base branch + # before the release workflow is triggered. - name: Checkout repository + if: ${{ (inputs.base == 'main' && matrix.base == 'main') || (inputs.base != 'main') }} uses: actions/checkout@v4 with: fetch-depth: 0 - ref: main + ref: ${{ matrix.base }} - - name: Configure Git for private repositories (temporary until making KGO public) + - name: Configure Git for private repositories (this is needed by repositories that include this workflow and have other private dependencies) + if: ${{ (inputs.base == 'main' && matrix.base == 'main') || (inputs.base != 'main') }} run: git config --global url."https://${{ secrets.gh-pat }}@github.com".insteadOf "https://github.com" - name: Checkout KGO submodule + if: ${{ (inputs.base == 'main' && matrix.base == 'main') || (inputs.base != 'main') }} run: git submodule update --init - name: Setup golang + if: ${{ (inputs.base == 'main' && matrix.base == 'main') || (inputs.base != 'main') }} uses: actions/setup-go@v5 with: go-version-file: go.mod # The bumped version file is included in the release PR. - name: Ensure version is set + if: ${{ (inputs.base == 'main' && matrix.base == 'main') || (inputs.base != 'main') }} env: VERSION: ${{ needs.semver.outputs.fullversion }} run: | @@ -217,17 +236,19 @@ jobs: # Generated manifests are part of the release PR. - name: Generate manifests - if: ${{ inputs.regenerate-manifests }} + if: ${{ inputs.regenerate-manifests && ((inputs.base == 'main' && matrix.base == 'main') || (inputs.base != 'main')) }} run: make manifests # The generated bundle is part of the release PR. # This is done locally in this job, to avoid including unintended changes. - # If anything needs to be fixed before a release, it should be done on the main branch. + # If anything needs to be fixed before the release, it should be done on the base branch + # before the release workflow is triggered. - name: Generate bundle - if: ${{ inputs.regenerate-bundle }} + if: ${{ inputs.regenerate-bundle && ((inputs.base == 'main' && matrix.base == 'main') || (inputs.base != 'main')) }} run: make bundle - name: GPG sign the commits + if: ${{ (inputs.base == 'main' && matrix.base == 'main') || (inputs.base != 'main') }} uses: crazy-max/ghaction-import-gpg@01dd5d3ca463c7f10f7f4f7b4f177225ac661ee4 with: gpg_private_key: ${{ secrets.gpg-private-key }} @@ -235,19 +256,31 @@ jobs: git_user_signingkey: true git_commit_gpgsign: true - # PRs to the main branch will update the version file and manifests + - name: Commit message + if: ${{ (inputs.base == 'main' && matrix.base == 'main') || (inputs.base != 'main') }} + env: + # NOTE: If the base branch set for workflow is not main (it's a release branch) + # then create a commit message which will not trigger the release workflow + # (via release-bot.yaml) but which will only update VERSION and config/. + MSG: "${{ inputs.base != 'main' && matrix.base == 'main' && format('chore( {0} ): [main] {1}', inputs.release-type, env.VERSION) || format('chore( {0} ): [bot] {1}', inputs.release-type, env.VERSION) }}" + run: | + echo "MSG=${MSG}" >> $GITHUB_ENV + + # PRs to the base branch will update the version file and manifests - name: Create a release PR - uses: peter-evans/create-pull-request@70a41aba780001da0a30141984ae2a0c95d8704e + uses: peter-evans/create-pull-request@9153d834b60caba6d51c9b9510b087acf9f33f83 + if: ${{ (inputs.base == 'main' && matrix.base == 'main') || (inputs.base != 'main') }} with: token: ${{ secrets.gh-pat }} path: . + base: ${{ matrix.base }} add-paths: | VERSION config - commit-message: "chore(${{ inputs.release-type }}): [bot] ${{ env.VERSION }}" + commit-message: "${{ env.MSG }}" committer: Kong's Team k8s bot author: Kong's Team k8s bot signoff: true delete-branch: true - title: "chore(${{ inputs.release-type }}): [bot] ${{ env.VERSION }}" - body: "chore(${{ inputs.release-type }}): [bot] ${{ env.VERSION }}" + title: "${{ env.MSG }}" + body: "${{ env.MSG }}" diff --git a/.github/workflows/release-bot.yaml b/.github/workflows/release-bot.yaml index c48929dcf..f13f6520e 100644 --- a/.github/workflows/release-bot.yaml +++ b/.github/workflows/release-bot.yaml @@ -7,6 +7,7 @@ on: push: branches: - 'main' + - 'release/*' jobs: look_for_release: diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index f69f87756..0961b6037 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,5 +1,5 @@ name: release -run-name: "Release ${{ format('{0} (type: {1})', inputs.tag, inputs.release_type) }} " +run-name: "Release ${{ format('{0} (type: {1}) (branch: {2})', inputs.tag, inputs.release-type, inputs.base) }} " on: workflow_dispatch: @@ -7,6 +7,11 @@ on: tag: description: The version to release (e.g. v1.2.3) required: true + base: + description: The base branch from which to release and against which to create a release PR. + type: string + default: 'main' + required: false latest: description: Whether to tag this build latest type: boolean @@ -33,5 +38,6 @@ jobs: image-name: ${{ vars.DOCKERHUB_IMAGE_NAME }} latest: ${{ inputs.latest }} tag: ${{ inputs.tag }} + base: ${{ inputs.base }} release-type: ${{ inputs.release_type }} regenerate-manifests: true diff --git a/go.mod b/go.mod index e8cd7861e..d8086671f 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,12 @@ go 1.22 toolchain go1.22.0 +// 1.2.2 was released on main branch with a breaking change that was not +// intended to be released in 1.2.x: +// https://github.com/Kong/gateway-operator/commit/3876430e09e61edce58bd8464989e33236bd1872 +// This retraction is to prevent it from being used and from breaking builds of dependent projects. +retract v1.2.2 + require ( github.com/Masterminds/semver v1.5.0 github.com/cert-manager/cert-manager v1.14.4 From a1ee91ec6c6139aa0cdf6be3d2cbc88a8e0ff55e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Ma=C5=82ek?= Date: Tue, 23 Apr 2024 15:36:14 +0200 Subject: [PATCH 4/6] chore(ci): do not require build-push-image for release integration tests --- .github/workflows/__release-workflow.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/__release-workflow.yaml b/.github/workflows/__release-workflow.yaml index 70b027e41..5a94c2ae8 100644 --- a/.github/workflows/__release-workflow.yaml +++ b/.github/workflows/__release-workflow.yaml @@ -112,7 +112,6 @@ jobs: test-integration-current-kubernetes: runs-on: ubuntu-latest - needs: build-push-images strategy: fail-fast: true matrix: From 889e4974cb48d1269dab00cad896958ab17277ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patryk=20Ma=C5=82ek?= Date: Tue, 23 Apr 2024 15:39:16 +0200 Subject: [PATCH 5/6] chore(ci): fix release workflow parameter name --- .github/workflows/release.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 0961b6037..695df853d 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -1,5 +1,5 @@ name: release -run-name: "Release ${{ format('{0} (type: {1}) (branch: {2})', inputs.tag, inputs.release-type, inputs.base) }} " +run-name: "Release ${{ format('{0} (type: {1}) (branch: {2})', inputs.tag, inputs.release_type, inputs.base) }} " on: workflow_dispatch: From 31a94df0d2f4f0e10637762e66d32a79886778c4 Mon Sep 17 00:00:00 2001 From: Kong's Team k8s bot Date: Tue, 23 Apr 2024 13:55:45 +0000 Subject: [PATCH 6/6] chore( prerelease ): [bot] 1.2.3-rc.0 Signed-off-by: Kong's Team k8s bot --- VERSION | 2 +- config/components/manager-image/kustomization.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/VERSION b/VERSION index 6085e9465..5bb464a88 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.2.1 +1.2.3-rc.0 diff --git a/config/components/manager-image/kustomization.yaml b/config/components/manager-image/kustomization.yaml index f0a935cdc..fff4d5447 100644 --- a/config/components/manager-image/kustomization.yaml +++ b/config/components/manager-image/kustomization.yaml @@ -4,4 +4,4 @@ kind: Component images: - name: docker.io/kong/gateway-operator-oss newName: docker.io/kong/gateway-operator-oss - newTag: 1.2.1 + newTag: 1.2.3-rc.0