From 583cf5daeab5d0291389c6f2eafa594d5baddc33 Mon Sep 17 00:00:00 2001 From: Tom Wieczorek Date: Mon, 26 Aug 2024 11:48:17 +0200 Subject: [PATCH] Move generated CRDs into their own directory Introduce the static/_crds/* directories, which replace the static/manifests/*/CustomResourceDefinition directories. The underscore in the name prevents go tools from descending into the folder when looking for go files. This makes it safe to run go commands at the same time as generating the CRDs in this folder. This prevents errors like the following: go: finding module for package github.com/k0sproject/k0s/static/manifests/v1beta1/CustomResourceDefinition go: finding module for package github.com/k0sproject/k0s/static/manifests/helm/CustomResourceDefinition go: finding module for package github.com/k0sproject/k0s/static/manifests/autopilot/CustomResourceDefinition go: finding module for package github.com/k0sproject/k0s/static/manifests/etcd/CustomResourceDefinition go: github.com/k0sproject/k0s/static/manifests/autopilot/CustomResourceDefinition: no matching versions for query "latest" go: github.com/k0sproject/k0s/static/manifests/etcd/CustomResourceDefinition: no matching versions for query "latest" go: github.com/k0sproject/k0s/static/manifests/helm/CustomResourceDefinition: no matching versions for query "latest" go: github.com/k0sproject/k0s/static/manifests/v1beta1/CustomResourceDefinition: no matching versions for query "latest" make: *** [Makefile:113: go.sum] Error 1 Signed-off-by: Tom Wieczorek --- Makefile | 9 ++++----- pkg/component/controller/crd.go | 2 +- .../autopilot}/autopilot.k0sproject.io_controlnodes.yaml | 0 .../autopilot}/autopilot.k0sproject.io_plans.yaml | 0 .../autopilot.k0sproject.io_updateconfigs.yaml | 0 .../etcd}/etcd.k0sproject.io_etcdmembers.yaml | 0 .../helm}/helm.k0sproject.io_charts.yaml | 0 .../k0s}/k0s.k0sproject.io_clusterconfigs.yaml | 0 8 files changed, 5 insertions(+), 6 deletions(-) rename static/{manifests/autopilot/CustomResourceDefinition => _crds/autopilot}/autopilot.k0sproject.io_controlnodes.yaml (100%) rename static/{manifests/autopilot/CustomResourceDefinition => _crds/autopilot}/autopilot.k0sproject.io_plans.yaml (100%) rename static/{manifests/autopilot/CustomResourceDefinition => _crds/autopilot}/autopilot.k0sproject.io_updateconfigs.yaml (100%) rename static/{manifests/etcd/CustomResourceDefinition => _crds/etcd}/etcd.k0sproject.io_etcdmembers.yaml (100%) rename static/{manifests/helm/CustomResourceDefinition => _crds/helm}/helm.k0sproject.io_charts.yaml (100%) rename static/{manifests/k0s/CustomResourceDefinition => _crds/k0s}/k0s.k0sproject.io_clusterconfigs.yaml (100%) diff --git a/Makefile b/Makefile index f2fabd1f280c..24e527631cc8 100644 --- a/Makefile +++ b/Makefile @@ -123,14 +123,13 @@ $(foreach gv,$(api_group_versions),$(eval $(foreach t,$(api_group_version_target controller_gen_targets := $(foreach gv,$(api_group_versions),pkg/apis/$(gv)/.controller-gen.stamp) codegen_targets := $(controller_gen_targets) $(controller_gen_targets): .k0sbuild.docker-image.k0s hack/tools/boilerplate.go.txt hack/tools/Makefile.variables - rm -rf 'static/manifests/$(dir $(@:pkg/apis/%/.controller-gen.stamp=%))CustomResourceDefinition' - mkdir -p 'static/manifests/$(dir $(@:pkg/apis/%/.controller-gen.stamp=%))' + rm -rf 'static/_crds/$(dir $(@:pkg/apis/%/.controller-gen.stamp=%))' gendir="$$(mktemp -d .controller-gen.XXXXXX.tmp)" \ && trap "rm -rf -- $$gendir" INT EXIT \ && CGO_ENABLED=0 $(GO) run sigs.k8s.io/controller-tools/cmd/controller-gen@v$(controller-gen_version) \ paths="./$(dir $@)..." \ object:headerFile=hack/tools/boilerplate.go.txt output:object:dir="$$gendir" \ - crd output:crd:dir='static/manifests/$(dir $(@:pkg/apis/%/.controller-gen.stamp=%))CustomResourceDefinition' \ + crd output:crd:dir='static/_crds/$(dir $(@:pkg/apis/%/.controller-gen.stamp=%))' \ && mv -f -- "$$gendir"/zz_generated.deepcopy.go '$(dir $@).' touch -- '$@' @@ -167,12 +166,12 @@ pkg/client/clientset/.client-gen.stamp: .k0sbuild.docker-image.k0s hack/tools/bo touch -- '$@' codegen_targets += static/zz_generated_assets.go -static/zz_generated_assets.go: $(controller_gen_targets) # to generate the CRDs into static/manifests/*/CustomResourceDefinition +static/zz_generated_assets.go: $(controller_gen_targets) # to generate the CRDs into static/_crds/* static/zz_generated_assets.go: $(shell find static/manifests/calico static/manifests/windows static/misc -type f) static/zz_generated_assets.go: .k0sbuild.docker-image.k0s hack/tools/Makefile.variables CGO_ENABLED=0 $(GO) run github.com/kevinburke/go-bindata/go-bindata@v$(go-bindata_version) \ -o '$@' -pkg static -prefix static \ - $(foreach gv,$(api_group_versions),static/manifests/$(dir $(gv))CustomResourceDefinition/...) \ + $(foreach gv,$(api_group_versions),static/_crds/$(dir $(gv))...) \ static/manifests/calico/... \ static/manifests/windows/... \ static/misc/... diff --git a/pkg/component/controller/crd.go b/pkg/component/controller/crd.go index ba82fa57c8cc..147f146b464b 100644 --- a/pkg/component/controller/crd.go +++ b/pkg/component/controller/crd.go @@ -70,7 +70,7 @@ func (c CRD) Init(_ context.Context) error { // Run unpacks manifests from bindata func (c CRD) Start(_ context.Context) error { - crdAssetsPath := path.Join("manifests", c.assetsDir, "CustomResourceDefinition") + crdAssetsPath := path.Join("_crds", c.assetsDir) crds, err := static.AssetDir(crdAssetsPath) if err != nil { return fmt.Errorf("can't unbundle CRD `%s` manifests: %w", c.bundle, err) diff --git a/static/manifests/autopilot/CustomResourceDefinition/autopilot.k0sproject.io_controlnodes.yaml b/static/_crds/autopilot/autopilot.k0sproject.io_controlnodes.yaml similarity index 100% rename from static/manifests/autopilot/CustomResourceDefinition/autopilot.k0sproject.io_controlnodes.yaml rename to static/_crds/autopilot/autopilot.k0sproject.io_controlnodes.yaml diff --git a/static/manifests/autopilot/CustomResourceDefinition/autopilot.k0sproject.io_plans.yaml b/static/_crds/autopilot/autopilot.k0sproject.io_plans.yaml similarity index 100% rename from static/manifests/autopilot/CustomResourceDefinition/autopilot.k0sproject.io_plans.yaml rename to static/_crds/autopilot/autopilot.k0sproject.io_plans.yaml diff --git a/static/manifests/autopilot/CustomResourceDefinition/autopilot.k0sproject.io_updateconfigs.yaml b/static/_crds/autopilot/autopilot.k0sproject.io_updateconfigs.yaml similarity index 100% rename from static/manifests/autopilot/CustomResourceDefinition/autopilot.k0sproject.io_updateconfigs.yaml rename to static/_crds/autopilot/autopilot.k0sproject.io_updateconfigs.yaml diff --git a/static/manifests/etcd/CustomResourceDefinition/etcd.k0sproject.io_etcdmembers.yaml b/static/_crds/etcd/etcd.k0sproject.io_etcdmembers.yaml similarity index 100% rename from static/manifests/etcd/CustomResourceDefinition/etcd.k0sproject.io_etcdmembers.yaml rename to static/_crds/etcd/etcd.k0sproject.io_etcdmembers.yaml diff --git a/static/manifests/helm/CustomResourceDefinition/helm.k0sproject.io_charts.yaml b/static/_crds/helm/helm.k0sproject.io_charts.yaml similarity index 100% rename from static/manifests/helm/CustomResourceDefinition/helm.k0sproject.io_charts.yaml rename to static/_crds/helm/helm.k0sproject.io_charts.yaml diff --git a/static/manifests/k0s/CustomResourceDefinition/k0s.k0sproject.io_clusterconfigs.yaml b/static/_crds/k0s/k0s.k0sproject.io_clusterconfigs.yaml similarity index 100% rename from static/manifests/k0s/CustomResourceDefinition/k0s.k0sproject.io_clusterconfigs.yaml rename to static/_crds/k0s/k0s.k0sproject.io_clusterconfigs.yaml