diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b5a16aae..5772118e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -33,5 +33,5 @@ jobs: args: --clean --snapshot env: REPO: ${{ github.repository }} - REGISTRY: + REGISTRY: "" \ No newline at end of file diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 0f426bb3..9afab6e0 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -24,7 +24,7 @@ jobs: uses: golangci/golangci-lint-action@v6 with: args: --timeout=5m - version: v1.60 + version: v1.64 tests: runs-on: ubuntu-latest diff --git a/Makefile b/Makefile index f260fc2b..dd7cc30b 100644 --- a/Makefile +++ b/Makefile @@ -4,15 +4,13 @@ VERSION ?= $(shell git describe --tags --always --dirty --match="v[0-9]*") ## Dependencies -GOLANGCI_LINT_VERSION := v1.63.4 -CONTROLLER_TOOLS_VERSION ?= v0.14.0 +GOLANGCI_LINT_VERSION := v1.64.8 GINKGO_VERSION ?= v2.21.0 -ENVTEST_VERSION ?= latest +ENVTEST_VERSION ?= v0.0.0-20250505003155-b6c5897febe5 ENVTEST_K8S_VERSION := 1.31.0 CRD_REF_DOCS_VER ?= v0.1.0 GOLANGCI_LINT ?= go run github.com/golangci/golangci-lint/cmd/golangci-lint@$(GOLANGCI_LINT_VERSION) -CONTROLLER_GEN ?= go run sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_TOOLS_VERSION) GINKGO ?= go run github.com/onsi/ginkgo/v2/ginkgo@$(GINKGO_VERSION) CRD_REF_DOCS := go run github.com/elastic/crd-ref-docs@$(CRD_REF_DOCS_VER) @@ -22,7 +20,7 @@ export KUBEBUILDER_ASSETS ?= $(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin .PHONY: all -all: version build-crds build package ## Run 'make' or 'make all' to run 'version', 'build-crds', 'build' and 'package' +all: version generate build package ## Run 'make' or 'make all' to run 'version', 'generate', 'build' and 'package' .PHONY: version version: ## Print the current version @@ -51,7 +49,6 @@ push-%: docker push $(REPO)/$*:latest docker push $(REPO)/$*:dev - .PHONY: test test: ## Run all the tests $(GINKGO) -v -r --label-filter=$(label-filter) @@ -68,17 +65,16 @@ test-controller: ## Run the controller tests (pkg/controller) test-e2e: ## Run the e2e tests $(GINKGO) -v -r tests -.PHONY: build-crds -build-crds: ## Build the CRDs specs - @# This will return non-zero until all of our objects in ./pkg/apis can generate valid crds. - @# allowDangerousTypes is needed for struct that use floats - $(CONTROLLER_GEN) crd:generateEmbeddedObjectMeta=true,allowDangerousTypes=false \ - paths=./pkg/apis/... \ - output:crd:dir=./charts/k3k/crds +.PHONY: generate +generate: ## Generate the CRDs specs + go generate ./... .PHONY: docs docs: ## Build the CRDs and CLI docs - $(CRD_REF_DOCS) --config=./docs/crds/config.yaml --renderer=markdown --source-path=./pkg/apis/k3k.io/v1alpha1 --output-path=./docs/crds/crd-docs.md + $(CRD_REF_DOCS) --config=./docs/crds/config.yaml \ + --renderer=markdown \ + --source-path=./pkg/apis/k3k.io/v1alpha1 \ + --output-path=./docs/crds/crd-docs.md @go run ./docs/cli/genclidoc.go .PHONY: lint @@ -86,7 +82,7 @@ lint: ## Find any linting issues in the project $(GOLANGCI_LINT) run --timeout=5m .PHONY: validate -validate: build-crds docs ## Validate the project checking for any dependency or doc mismatch +validate: generate docs ## Validate the project checking for any dependency or doc mismatch $(GINKGO) unfocus go mod tidy git status --porcelain @@ -103,4 +99,4 @@ install: ## Install K3k with Helm on the targeted Kubernetes cluster .PHONY: help help: ## Show this help. - @egrep -h '\s##\s' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m %-30s\033[0m %s\n", $$1, $$2}' \ No newline at end of file + @egrep -h '\s##\s' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m %-30s\033[0m %s\n", $$1, $$2}' diff --git a/docs/development.md b/docs/development.md index 73b9ea5c..fccafdf1 100644 --- a/docs/development.md +++ b/docs/development.md @@ -33,7 +33,7 @@ To see all the available Make commands you can run `make help`, i.e: ``` -> % make help - all Run 'make' or 'make all' to run 'version', 'build-crds', 'build' and 'package' + all Run 'make' or 'make all' to run 'version', 'generate', 'build' and 'package' version Print the current version build Build the the K3k binaries (k3k, k3k-kubelet and k3kcli) package Package the k3k and k3k-kubelet Docker images @@ -42,8 +42,8 @@ To see all the available Make commands you can run `make help`, i.e: test-unit Run the unit tests (skips the e2e) test-controller Run the controller tests (pkg/controller) test-e2e Run the e2e tests - build-crds Build the CRDs specs - docs Build the CRDs docs + generate Generate the CRDs specs + docs Build the CRDs and CLI docs lint Find any linting issues in the project validate Validate the project checking for any dependency or doc mismatch install Install K3k with Helm on the targeted Kubernetes cluster @@ -88,7 +88,7 @@ The required binaries for `envtest` are installed with [`setup-envtest`](https:/ ## CRDs and Docs -We are using Kubebuilder and `controller-gen` to build the needed CRDs. To generate the specs you can run `make build-crds`. +We are using Kubebuilder and `controller-gen` to build the needed CRDs. To generate the specs you can run `make generate`. Remember also to update the CRDs documentation running the `make docs` command. diff --git a/go.mod b/go.mod index eb3be3ef..8d938b99 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/rancher/k3k -go 1.23.4 +go 1.24.2 replace ( github.com/google/cel-go => github.com/google/cel-go v0.17.7 diff --git a/hack/boilerplate.go.txt b/hack/boilerplate.go.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh deleted file mode 100755 index ed8e69d0..00000000 --- a/hack/update-codegen.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/usr/bin/env bash - -set -o errexit -set -o nounset -set -o pipefail - -set -x -CODEGEN_GIT_PKG=https://github.com/kubernetes/code-generator.git -git clone --depth 1 ${CODEGEN_GIT_PKG} || true - -K8S_VERSION=$(cat go.mod | grep -m1 "k8s.io/apiserver" | cut -d " " -f 2) -SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. -CODEGEN_PKG=./code-generator - -# cd into the git dir to checkout the code gen version compatible with the k8s version that this is using -cd $CODEGEN_PKG -git fetch origin tag ${K8S_VERSION} -git checkout ${K8S_VERSION} -cd - - -source ${CODEGEN_PKG}/kube_codegen.sh - -kube::codegen::gen_helpers \ - --boilerplate "${SCRIPT_ROOT}/hack/boilerplate.go.txt" \ - --input-pkg-root "${SCRIPT_ROOT}/pkg/apis" \ - --output-base "${SCRIPT_ROOT}/pkg/apis" - -rm -rf code-generator diff --git a/main.go b/main.go index 8c88741c..63677b5a 100644 --- a/main.go +++ b/main.go @@ -1,4 +1,4 @@ -//go:generate ./hack/update-codegen.sh +//go:generate ./scripts/generate package main import ( diff --git a/pkg/apis/k3k.io/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/k3k.io/v1alpha1/zz_generated.deepcopy.go index e5f0f28d..b4ede03b 100644 --- a/pkg/apis/k3k.io/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/k3k.io/v1alpha1/zz_generated.deepcopy.go @@ -1,20 +1,18 @@ //go:build !ignore_autogenerated -// +build !ignore_autogenerated -// Code generated by deepcopy-gen. DO NOT EDIT. +// Code generated by controller-gen. DO NOT EDIT. package v1alpha1 import ( - v1 "k8s.io/api/core/v1" + "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Addon) DeepCopyInto(out *Addon) { *out = *in - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Addon. @@ -34,7 +32,6 @@ func (in *Cluster) DeepCopyInto(out *Cluster) { out.TypeMeta = in.TypeMeta in.Spec.DeepCopyInto(&out.Spec) in.Status.DeepCopyInto(&out.Status) - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Cluster. @@ -67,7 +64,6 @@ func (in *ClusterList) DeepCopyInto(out *ClusterList) { (*in)[i].DeepCopyInto(&(*out)[i]) } } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterList. @@ -95,7 +91,6 @@ func (in *ClusterSet) DeepCopyInto(out *ClusterSet) { out.TypeMeta = in.TypeMeta in.Spec.DeepCopyInto(&out.Spec) in.Status.DeepCopyInto(&out.Status) - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterSet. @@ -128,7 +123,6 @@ func (in *ClusterSetList) DeepCopyInto(out *ClusterSetList) { (*in)[i].DeepCopyInto(&(*out)[i]) } } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterSetList. @@ -179,7 +173,6 @@ func (in *ClusterSetSpec) DeepCopyInto(out *ClusterSetSpec) { *out = new(PodSecurityAdmissionLevel) **out = **in } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterSetSpec. @@ -202,7 +195,6 @@ func (in *ClusterSetStatus) DeepCopyInto(out *ClusterSetStatus) { (*in)[i].DeepCopyInto(&(*out)[i]) } } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterSetStatus. @@ -294,7 +286,6 @@ func (in *ClusterSpec) DeepCopyInto(out *ClusterSpec) { (*out)[key] = val.DeepCopy() } } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterSpec. @@ -316,7 +307,6 @@ func (in *ClusterStatus) DeepCopyInto(out *ClusterStatus) { copy(*out, *in) } in.Persistence.DeepCopyInto(&out.Persistence) - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ClusterStatus. @@ -347,7 +337,6 @@ func (in *ExposeConfig) DeepCopyInto(out *ExposeConfig) { *out = new(NodePortConfig) (*in).DeepCopyInto(*out) } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExposeConfig. @@ -370,7 +359,6 @@ func (in *IngressConfig) DeepCopyInto(out *IngressConfig) { (*out)[key] = val } } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IngressConfig. @@ -396,7 +384,6 @@ func (in *LoadBalancerConfig) DeepCopyInto(out *LoadBalancerConfig) { *out = new(int32) **out = **in } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new LoadBalancerConfig. @@ -422,7 +409,6 @@ func (in *NodePortConfig) DeepCopyInto(out *NodePortConfig) { *out = new(int32) **out = **in } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NodePortConfig. @@ -443,7 +429,6 @@ func (in *PersistenceConfig) DeepCopyInto(out *PersistenceConfig) { *out = new(string) **out = **in } - return } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PersistenceConfig. diff --git a/scripts/generate b/scripts/generate new file mode 100755 index 00000000..4a5012f7 --- /dev/null +++ b/scripts/generate @@ -0,0 +1,13 @@ +#!/bin/bash + +set -eou pipefail + + +CONTROLLER_TOOLS_VERSION=v0.14.0 + +# This will return non-zero until all of our objects in ./pkg/apis can generate valid crds. +# allowDangerousTypes is needed for struct that use floats +go run sigs.k8s.io/controller-tools/cmd/controller-gen@${CONTROLLER_TOOLS_VERSION} \ + crd:generateEmbeddedObjectMeta=true,allowDangerousTypes=false \ + object paths=./pkg/apis/... \ + output:crd:dir=./charts/k3k/crds