Skip to content

Commit b4d7cfd

Browse files
committed
Allow for excluding CRD template files
Signed-off-by: Erik Godding Boye <egboye@gmail.com>
1 parent 8187c64 commit b4d7cfd

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

modules/helm/crds.mk

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,14 @@ endif
4040
crds_dir ?= deploy/crds
4141
crds_dir_readme := $(dir $(lastword $(MAKEFILE_LIST)))/crds_dir.README.md
4242
crds_expression ?= .Values.crds.enabled
43+
crd_template_include_pattern := *.yaml
44+
crd_template_exclude_pattern ?= # e.g. foo.yaml *_test.yaml
45+
46+
define filter-out-basenames
47+
$(foreach f,$(1), \
48+
$(if $(filter $(2),$(notdir $(f))),, $(f)) \
49+
)
50+
endef
4351

4452
.PHONY: generate-crds
4553
## Generate CRD manifests.
@@ -57,13 +65,18 @@ generate-crds: | $(NEEDS_CONTROLLER-GEN) $(NEEDS_YQ)
5765

5866
@echo "Updating CRDs with helm templating, writing to $(helm_chart_source_dir)/templates"
5967

60-
@for i in $$(ls $(crds_gen_temp)); do \
61-
crd_name=$$($(YQ) eval '.metadata.name' $(crds_gen_temp)/$$i); \
68+
$(eval crds_gen_temp_all_files := $(wildcard $(crds_gen_temp)/$(crd_template_include_pattern)))
69+
$(eval crds_gen_temp_files := $(if $(crd_template_exclude_pattern), \
70+
$(call filter-out-basenames,$(crds_gen_temp_all_files),$(crd_template_exclude_pattern)), \
71+
$(crds_gen_temp_all_files)))
72+
73+
@for i in $(crds_gen_temp_files); do \
74+
crd_name=$$($(YQ) eval '.metadata.name' $$i); \
6275
cat $(crd_template_header) > $(helm_chart_source_dir)/templates/crd-$$i; \
6376
$(sed_inplace) "s/REPLACE_CRD_EXPRESSION/$(crds_expression)/g" $(helm_chart_source_dir)/templates/crd-$$i; \
6477
$(sed_inplace) "s/REPLACE_CRD_NAME/$$crd_name/g" $(helm_chart_source_dir)/templates/crd-$$i; \
6578
$(sed_inplace) "s/REPLACE_LABELS_TEMPLATE/$(helm_labels_template_name)/g" $(helm_chart_source_dir)/templates/crd-$$i; \
66-
$(YQ) -I2 '{"spec": .spec}' $(crds_gen_temp)/$$i >> $(helm_chart_source_dir)/templates/crd-$$i; \
79+
$(YQ) -I2 '{"spec": .spec}' $$i >> $(helm_chart_source_dir)/templates/crd-$(notdir $$i); \
6780
cat $(crd_template_footer) >> $(helm_chart_source_dir)/templates/crd-$$i; \
6881
done
6982

0 commit comments

Comments
 (0)