diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6651f6225b1..18244da68d9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -19,7 +19,7 @@ jobs: with: go-version: '~1.19' - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v3 + uses: goreleaser/goreleaser-action@v4 with: version: v1.11.2 args: release -f ./build/.goreleaser.yml --rm-dist diff --git a/RELEASE.md b/RELEASE.md index 4f00aad65b7..3c130a888b2 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -86,13 +86,8 @@ The releases occur in an account in the Google Cloud (See [here](https://console ### To build the Kubebuilder CLI binaries: -A trigger `build-kb-release` is configured to call [build/cloudbuild.yaml](build/cloudbuild.yaml). -This trigger will be executed when any new tag be published. -The tags must be built from the release branch (Currently, `release-3`). - -Also, we have a trigger to generate snapshots builds from the master branch. -This trigger will call [build/cloudbuild_snapshot.yaml](build/cloudbuild_snapshot.yaml) -when any change needs to be performed on master. +A trigger GitHub action [release](.github/workflows/release.yml) is trigged when a new tag is pushed. +This action will caall the job [./build/.goreleaser.yml](./build/.goreleaser.yml). ### To build the Kubebuilder-tools: (Artifacts required to use ENV TEST) diff --git a/build/.goreleaser.yml b/build/.goreleaser.yml index 881dab0aa54..1b207212896 100644 --- a/build/.goreleaser.yml +++ b/build/.goreleaser.yml @@ -44,7 +44,7 @@ builds: - darwin_amd64 - darwin_arm64 env: - - KUBERNETES_VERSION=1.25.0 + - KUBERNETES_VERSION=1.26.0 - CGO_ENABLED=0 # Only binaries of the form "kubebuilder_${goos}_${goarch}" will be released. diff --git a/build/build_kubebuilder.sh b/build/build_kubebuilder.sh deleted file mode 100755 index 6569396b865..00000000000 --- a/build/build_kubebuilder.sh +++ /dev/null @@ -1,111 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2018 The Kubernetes Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This script runs goreleaser using the build/.goreleaser.yml config. -# While it can be run locally, it is intended to be run by cloudbuild -# in the goreleaser/goreleaser image. - -function usage() { - echo " - This script runs goreleaser using the build/.goreleaser.yml config. - While it can be run locally, it is intended to be run by cloudbuild - in the goreleaser/goreleaser image. - - GORELEASER_FLAGS: contains flags to pass to the goreleaser binary (default: only --config is set). - - SNAPSHOT: if set to any value, runs goreleaser in snapshot mode with mock release notes (default: unset). - - NOTES_FLAGS: contains flags to pass to the notes binary (sigs.k8s.io/kubebuilder-release-tools/notes). - Does nothing if SNAPSHOT is set. (default: unset). - - Examples: - - # Run in snapshot mode: fake release notes, nothing is published, binaries build in '$(pwd)/dist' - \$ SNAPSHOT=1 $0 - - # Add a release type to the release notes - \$ NOTES_FLAGS=\"-r beta\" $0 -" -} - -# GORELEASER_FLAGS contains flags for goreleaser such that the binary can be run -# in local/snapshot/prod mode from the same script. -# NOTE: if --snapshot is in GORELEASER_FLAGS, the release is not published to GitHub -# and the build is available under $PWD/dist. -GORELEASER_FLAGS="${GORELEASER_FLAGS:-}" -# NOTES_FLAGS contains flags for the release notes generator (see install_notes for details). -NOTES_FLAGS="${NOTES_FLAGS:-}" -# SNAPSHOT is set by the CLI flag parser if --snapshot is a passed flag. -# If not set, release notes are not generated. -SNAPSHOT="${SNAPSHOT:-}" - -while [ $# -gt 0 ]; do - case $1 in - -h|--help) - usage - exit 0 - ;; - esac -done - - -# install_notes installs kubebuilder's release notes generator globally with name "notes". -function install_notes() { - local tmp=$(mktemp -d) - pushd "$tmp" - go mod init tmp - # Get by commit because v0.1.1 cannot be retrieved via `go get`. - go get sigs.k8s.io/kubebuilder-release-tools/notes@4777888c377a26956f1831d5b9207eea1fa3bf29 - popd - rm -rf "$tmp" -} - -set -o errexit -set -o pipefail - -# Generate real release notes. -if [ -z "$SNAPSHOT" ]; then - tmp_notes="$(mktemp)" - trap "rm -f ${tmp_notes}" EXIT - install_notes - if [[ -n "${CLOUD_BUILD}" ]]; then - # we refresh just before this, no point (plus, we fiddle with the current branch a bit) - NOTES_FLAGS+=" --use-upstream=false" - # we can look for tag alpha/beta here too - # (TODO(directxman12): this should be in the tool) - [[ "${TAG_NAME}" == "v"*"-alpha."* ]] && NOTES_FLAGS+=" -r alpha" - [[ "${TAG_NAME}" == "v"*"-beta."* ]] && NOTES_FLAGS+=" -r beta" - [[ "${TAG_NAME}" == "v"*"-rc."* ]] && NOTES_FLAGS+=" -r rc" - fi - # TODO(cmacedo): figure out how to download the release notes and let it available in the cloud build - # Currently it does not work: https://github.com/kubernetes-sigs/kubebuilder/issues/2667 - # notes $NOTES_FLAGS | tee "$tmp_notes" - notes="Mock Release Notes for $(git describe --tags --always --broken)" - # we need to delete the tag for the release notes script, so restore it when done so that - # go releaser can find the right tag - if [[ -n "${TAG_NAME}" ]]; then - git tag ${TAG_NAME} - fi - GORELEASER_FLAGS="${GORELEASER_FLAGS} --release-notes=${tmp_notes}" -else - # TODO(estroz): figure out how to generate snapshot release notes with the kubebuilder generator. - echo "Running in snapshot mode. Release notes will not be generated from commits." - notes="Mock Release Notes for $(git describe --tags --always --broken)" - GORELEASER_FLAGS="${GORELEASER_FLAGS} --snapshot --rm-dist --skip-validate --release-notes <(echo \"${notes}\")" -fi - -# eval to run process substitution. -eval goreleaser release --config=build/.goreleaser.yml $GORELEASER_FLAGS diff --git a/build/cloudbuild.yaml b/build/cloudbuild.yaml deleted file mode 100644 index 70c62748c40..00000000000 --- a/build/cloudbuild.yaml +++ /dev/null @@ -1,47 +0,0 @@ -# Copyright 2018 The Kubernetes Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Instructions to run locally: -# Download google container builder: https://github.com/GoogleCloudPlatform/cloud-build-local -# $ mkdir cloudbuild -# $ cloud-build-local --config=build/cloudbuild_local.yaml --dryrun=false --write-workspace=./cloudbuild . -# Release tar will be in ./cloudbuild - -steps: -- name: "gcr.io/cloud-builders/git" - entrypoint: 'bash' - args: - - '-c' - - | - git fetch --tags --unshallow - git for-each-ref --contains HEAD - # TAG_NAME is defined by GCB, so uses 1 dollar sign, BRANCH_NAME is bash, so we need to escape it - # with two dollar signs - export BRANCH_NAME=$(git for-each-ref --format="%(refname:strip=-1)" --contains HEAD 'refs/remotes/origin/release-*') - export ALL_BRANCHES=$(git for-each-ref --format="%(refname:strip=-1)" 'refs/remotes/origin/release-*') - echo "branch: $${BRANCH_NAME}, tag: ${TAG_NAME}, all release branches: $${ALL_BRANCHES}" - for branch in $${ALL_BRANCHES}; do - git branch $${branch} origin/$${branch} - done - git branch -f $${BRANCH_NAME} HEAD - git checkout $${BRANCH_NAME} - git branch --set-upstream-to=origin/$${BRANCH_NAME} - git tag -d ${TAG_NAME} -- name: "goreleaser/goreleaser:v1.11.2" - entrypoint: "bash" - args: ["build/build_kubebuilder.sh"] - env: - - 'TAG_NAME=$TAG_NAME' - - 'CLOUD_BUILD=true' - - 'GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}' \ No newline at end of file diff --git a/build/cloudbuild_local.yaml b/build/cloudbuild_local.yaml deleted file mode 100644 index ed97f90aa34..00000000000 --- a/build/cloudbuild_local.yaml +++ /dev/null @@ -1,25 +0,0 @@ -# Copyright 2018 The Kubernetes Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Instructions to run locally: -# Download google container builder: https://github.com/GoogleCloudPlatform/cloud-build-local -# $ mkdir cloudbuild -# $ cloud-build-local --config=build/cloudbuild_local.yaml --dryrun=false --write-workspace=./cloudbuild . -# Release tar will be in ./cloudbuild - -steps: -- name: "goreleaser/goreleaser:v1.11.2" - entrypoint: "bash" - env: ["SNAPSHOT=1"] - args: ["build/build_kubebuilder.sh"] diff --git a/build/cloudbuild_snapshot.yaml b/build/cloudbuild_snapshot.yaml deleted file mode 100644 index 9eaf2d4ffc4..00000000000 --- a/build/cloudbuild_snapshot.yaml +++ /dev/null @@ -1,48 +0,0 @@ -# Copyright 2018 The Kubernetes Authors. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# Instructions to run locally: -# Download google container builder: https://github.com/GoogleCloudPlatform/cloud-build-local -# $ mkdir cloudbuild -# $ cloud-build-local --config=build/cloudbuild_snapshot.yaml --dryrun=false --write-workspace=./cloudbuild . -# Release tar will be in ./cloudbuild - -steps: -- name: "goreleaser/goreleaser:v1.11.2" - entrypoint: "bash" - env: ["SNAPSHOT=1"] - args: ["build/build_kubebuilder.sh"] - timeout: 30m -- name: "ubuntu" - args: ["tar", "-zcvf", "kubebuilder_linux_amd64.tar.gz", "-C", "dist/kubebuilder_linux_amd64_v1", "kubebuilder"] -- name: "gcr.io/cloud-builders/gsutil" - args: ["-h", "Content-Type:application/gzip", "cp", "kubebuilder_linux_amd64.tar.gz", "gs://kubebuilder-release/kubebuilder_master_linux_amd64.tar.gz"] -- name: "ubuntu" - args: ["tar", "-zcvf", "kubebuilder_linux_arm64.tar.gz", "-C", "dist/kubebuilder_linux_arm64", "kubebuilder"] -- name: "gcr.io/cloud-builders/gsutil" - args: ["-h", "Content-Type:application/gzip", "cp", "kubebuilder_linux_arm64.tar.gz", "gs://kubebuilder-release/kubebuilder_master_linux_arm64.tar.gz"] -- name: "ubuntu" - args: ["tar", "-zcvf", "kubebuilder_linux_ppc64le.tar.gz", "-C", "dist/kubebuilder_linux_ppc64le", "kubebuilder"] -- name: "gcr.io/cloud-builders/gsutil" - args: ["-h", "Content-Type:application/gzip", "cp", "kubebuilder_linux_ppc64le.tar.gz", "gs://kubebuilder-release/kubebuilder_master_linux_ppc64le.tar.gz"] -- name: "ubuntu" - args: ["tar", "-zcvf", "kubebuilder_darwin_amd64.tar.gz", "-C", "dist/kubebuilder_darwin_amd64_v1", "kubebuilder"] -- name: "gcr.io/cloud-builders/gsutil" - args: ["-h", "Content-Type:application/gzip", "cp", "kubebuilder_darwin_amd64.tar.gz", "gs://kubebuilder-release/kubebuilder_master_darwin_amd64.tar.gz"] -- name: "ubuntu" - args: ["tar", "-zcvf", "kubebuilder_darwin_arm64.tar.gz", "-C", "dist/kubebuilder_darwin_arm64", "kubebuilder"] -- name: "gcr.io/cloud-builders/gsutil" - args: ["-h", "Content-Type:application/gzip", "cp", "kubebuilder_darwin_arm64.tar.gz", "gs://kubebuilder-release/kubebuilder_master_darwin_arm64.tar.gz"] - - diff --git a/docs/book/src/SUMMARY.md b/docs/book/src/SUMMARY.md index 3a90c65b218..a2eb8a02ae0 100644 --- a/docs/book/src/SUMMARY.md +++ b/docs/book/src/SUMMARY.md @@ -6,8 +6,6 @@ [Architecture](./architecture.md) -[FAQ](./faq.md) - --- - [Tutorial: Building CronJob](cronjob-tutorial/cronjob-tutorial.md) @@ -134,6 +132,8 @@ --- +[FAQ](./faq.md) + [Appendix: The TODO Landing Page](./TODO.md) [plugins]: ./plugins/plugins.md diff --git a/docs/book/src/component-config-tutorial/testdata/project/Makefile b/docs/book/src/component-config-tutorial/testdata/project/Makefile index e833f6285ad..a551a6e1cca 100644 --- a/docs/book/src/component-config-tutorial/testdata/project/Makefile +++ b/docs/book/src/component-config-tutorial/testdata/project/Makefile @@ -2,7 +2,7 @@ # Image URL to use all building/pushing image targets IMG ?= controller:latest # ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary. -ENVTEST_K8S_VERSION = 1.25.0 +ENVTEST_K8S_VERSION = 1.26.0 # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) ifeq (,$(shell go env GOBIN)) diff --git a/docs/book/src/cronjob-tutorial/testdata/emptycontroller.go b/docs/book/src/cronjob-tutorial/testdata/emptycontroller.go index 9a1fc29be4e..bc941060ec0 100644 --- a/docs/book/src/cronjob-tutorial/testdata/emptycontroller.go +++ b/docs/book/src/cronjob-tutorial/testdata/emptycontroller.go @@ -55,6 +55,16 @@ needed to run. As we add more functionality, we'll need to revisit these. // +kubebuilder:rbac:groups=batch.tutorial.kubebuilder.io,resources=cronjobs,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=batch.tutorial.kubebuilder.io,resources=cronjobs/status,verbs=get;update;patch +/* +The `ClusterRole` manifest at `config/rbac/role.yaml` is generated from the above markers via controller-gen with the following command: +*/ + +// make manifests + +/* +NOTE: If you receive an error, please run the specified command in the error and re-run `make manifests`. +*/ + /* `Reconcile` actually performs the reconciling for a single named object. Our [Request](https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/reconcile?tab=doc#Request) just has a name, but we can use the client to fetch diff --git a/docs/book/src/migration/manually_migration_guide_gov3_to_gov4.md b/docs/book/src/migration/manually_migration_guide_gov3_to_gov4.md index cae361c45ca..e776bb5beb9 100644 --- a/docs/book/src/migration/manually_migration_guide_gov3_to_gov4.md +++ b/docs/book/src/migration/manually_migration_guide_gov3_to_gov4.md @@ -16,11 +16,17 @@ The recommended upgrade approach is to follow the [Migration Guide go/v3 to go/v ## Migration from project config version "go/v3" to "go/v4" -Update `PROJECT` file layout which stores the information about the resources are use to enable plugins to make useful decisions when scaffolding. +Update the `PROJECT` file layout which stores information about the resources that are used to enable plugins make +useful decisions while scaffolding. The `layout` field indicates the scaffolding and the primary plugin version in use. -Furthermore, the `PROJECT` file itself is now versioned. The `version` field corresponds to the version of the `PROJECT` file itself, while the `layout` field indicates the scaffolding and the primary plugin version in use. +### Steps to migrate + +#### Migrate the layout version into the PROJECT file + +The following steps describe the manual changes required to bring the project configuration file (`PROJECT`). +These change will add the information that Kubebuilder would add when generating the file. This file can be found in the root directory. -Update: +Update the PROJECT file by replacing: ```yaml layout: @@ -35,16 +41,119 @@ layout: ``` -### Steps to migrate +#### Changes to the layout -- Update the `main.go` with the changes which can be found in the samples under testdata for the release tag used. (see for example `testdata/project-v4/main.go`). -- Update the Makefile with the changes which can be found in the samples under testdata for the release tag used. (see for example `testdata/project-v4/Makefile`) -- Update the `go.mod` with the changes which can be found in the samples under `testdata` for the release tag used. (see for example `testdata/project-v4/go.mod`). Then, run -`go mod tidy` to ensure that you get the latest dependencies and your Golang code has no breaking changes. -- Update the manifest under `config/` directory with all changes performed in the default scaffold done with `go/v4-alpha` plugin. (see for example `testdata/project-v4/config/`) to get all changes in the -default scaffolds to be applied on your project -- Create `config/samples/kustomization.yaml` with all CR samples specified. (see for example `testdata/project-v4/config/samples/kustomization.yaml`) -- Replace the import `admissionv1beta1 "k8s.io/api/admission/v1beta1"` with `admissionv1 "k8s.io/api/admission/v1"` in the webhook test files +##### New layout: + +- The directory `apis` was renamed to `api` to follow the standard +- The `controller(s)` directory has been moved under a new directory called `internal` and renamed to singular as well `controller` +- The `main.go` previously scaffolded in the root directory has been moved under a new directory called `cmd` + +Therefore, you can check the changes in the layout results into: + +```sh +... +├── cmd +│ └── main.go +├── internal +│ └── controller +└── api +``` + +##### Migrating to the new layout: + +- Create a new directory `cmd` and move the `main.go` under it. +- If your project support multi-group the APIs are scaffold under a directory called `apis`. Rename this directory to `api` +- Move the `controllers` directory under the `internal` and rename it for `controller` +- Now ensure that the imports will be updated accordingly by: + - Update the `main.go` imports to look for the new path of your controllers under the `pkg` directory + +**Then, let's update the scaffolds paths** + +- Update the Dockerfile to ensure that you will have: + +``` +COPY cmd/main.go cmd/main.go +COPY api/ api/ +COPY internal/controller/ internal/controller/ +``` + +Then, replace: + +``` +RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager main.go + +``` + +With: + +``` +RUN CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/main.go +``` + +- Update the Makefile targets to build and run the manager by replacing: + +``` +.PHONY: build +build: manifests generate fmt vet ## Build manager binary. + go build -o bin/manager main.go + +.PHONY: run +run: manifests generate fmt vet ## Run a controller from your host. + go run ./main.go +``` + +With: + +``` +.PHONY: build +build: manifests generate fmt vet ## Build manager binary. + go build -o bin/manager cmd/main.go + +.PHONY: run +run: manifests generate fmt vet ## Run a controller from your host. + go run ./cmd/main.go +``` + +- Update the `internal/controller/suite_test.go` to set the path for the `CRDDirectoryPaths`: + +Replace: + +``` +CRDDirectoryPaths: []string{filepath.Join("..", "config", "crd", "bases")}, +``` + +With: + +``` +CRDDirectoryPaths: []string{filepath.Join("..", "..", "config", "crd", "bases")}, +``` + +Note that if your project has multiple groups (`multigroup:true`) then the above update should result into `"..", "..", "..",` instead of `"..",".."` + +#### Now, let's update the PATHs in the PROJECT file accordingly + +The PROJECT tracks the paths of all APIs used in your project. Ensure that they now point to `api/...` as the following example: + +Before update: + group: crew + kind: Captain + path: sigs.k8s.io/kubebuilder/testdata/project-v4/apis/crew/v1 +``` + +After Update: + +``` + group: crew + kind: Captain + path: sigs.k8s.io/kubebuilder/testdata/project-v4/api/crew/v1 +``` + +### Update kustomize manifests with the changes made so far + +- Update the manifest under `config/` directory with all changes performed in the default scaffold done with `go/v4-alpha` plugin. (see for example `testdata/project-v4/config/`) to get all changes in the + default scaffolds to be applied on your project +- Create `config/samples/kustomization.yaml` with all Custom Resources samples specified into `config/samples`. _(see for example `testdata/project-v4/config/samples/kustomization.yaml`)_ +### If you have webhooks: + +Replace the import `admissionv1beta1 "k8s.io/api/admission/v1beta1"` with `admissionv1 "k8s.io/api/admission/v1"` in the webhook test files + +### Makefile updates + +Update the Makefile with the changes which can be found in the samples under testdata for the release tag used. (see for example `testdata/project-v4/Makefile`) + +### Update the dependencies + +Update the `go.mod` with the changes which can be found in the samples under `testdata` for the release tag used. (see for example `testdata/project-v4/go.mod`). Then, run +`go mod tidy` to ensure that you get the latest dependencies and your Golang code has no breaking changes. + ### Verification In the steps above, you updated your project manually with the goal of ensuring that it follows diff --git a/docs/book/src/migration/migration_guide_gov3_to_gov4.md b/docs/book/src/migration/migration_guide_gov3_to_gov4.md index c7741e8b398..a62bb33cc91 100644 --- a/docs/book/src/migration/migration_guide_gov3_to_gov4.md +++ b/docs/book/src/migration/migration_guide_gov3_to_gov4.md @@ -50,7 +50,7 @@ module tutorial.kubebuilder.io/migration-project Now, we can finish initializing the project with kubebuilder. ```bash -kubebuilder init --domain tutorial.kubebuilder.io plugins=go/v4-alpha +kubebuilder init --domain tutorial.kubebuilder.io --plugins=go/v4-alpha ```