Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport release-1.30] Move generated CRDs into their own directory #4985

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,13 @@ pkg/apis/etcd/v1beta1/.controller-gen.stamp: gen_output_dir = etcd
codegen_targets += $(controllergen_targets)

pkg/apis/%/.controller-gen.stamp: .k0sbuild.docker-image.k0s hack/tools/boilerplate.go.txt hack/tools/Makefile.variables
rm -rf 'static/manifests/$(gen_output_dir)/CustomResourceDefinition'
mkdir -p 'static/manifests/$(gen_output_dir)'
rm -rf 'static/_crds/$(gen_output_dir)'
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/$(gen_output_dir)/CustomResourceDefinition' \
crd output:crd:dir='static/_crds/$(gen_output_dir)' \
&& mv -f -- "$$gendir"/zz_generated.deepcopy.go '$(dir $@).'
touch -- '$@'

Expand All @@ -160,15 +159,15 @@ 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: $(controllergen_targets) # to generate the CRDs into static/manifests/*/CustomResourceDefinition
static/zz_generated_assets.go: $(controllergen_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 \
static/manifests/helm/CustomResourceDefinition/... \
static/manifests/v1beta1/CustomResourceDefinition/... \
static/manifests/autopilot/CustomResourceDefinition/... \
static/manifests/etcd/CustomResourceDefinition/... \
static/_crds/helm/... \
static/_crds/v1beta1/... \
static/_crds/autopilot/... \
static/_crds/etcd/... \
static/manifests/calico/... \
static/manifests/windows/... \
static/misc/...
Expand Down
6 changes: 4 additions & 2 deletions pkg/component/controller/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,17 @@ func (c CRD) Init(_ context.Context) error {

// Run unpacks manifests from bindata
func (c CRD) Start(_ context.Context) error {
// crdAssetsPath := path.Join("_crds", c.assetsDir)

for _, bundle := range c.bundles {
crds, err := static.AssetDir(fmt.Sprintf("manifests/%s/CustomResourceDefinition", bundle))
crds, err := static.AssetDir(fmt.Sprintf("_crds/%s", bundle))
if err != nil {
return fmt.Errorf("can't unbundle CRD `%s` manifests: %w", bundle, err)
}

for _, filename := range crds {
manifestName := fmt.Sprintf("%s-crd-%s", bundle, filename)
content, err := static.Asset(fmt.Sprintf("manifests/%s/CustomResourceDefinition/%s", bundle, filename))
content, err := static.Asset(fmt.Sprintf("_crds/%s/%s", bundle, filename))
if err != nil {
return fmt.Errorf("failed to fetch crd `%s`: %w", filename, err)
}
Expand Down
Loading