Skip to content

Commit

Permalink
Merge pull request #4985 from twz123/backport-4894-to-release-1.30
Browse files Browse the repository at this point in the history
[Backport release-1.30] Move generated CRDs into their own directory
  • Loading branch information
twz123 authored Sep 17, 2024
2 parents 385d106 + 76010af commit 70cdb88
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 10 deletions.
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

0 comments on commit 70cdb88

Please sign in to comment.