Skip to content

Commit c0906e6

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

1 file changed

Lines changed: 22 additions & 8 deletions

File tree

modules/helm/crds.mk

Lines changed: 22 additions & 8 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,14 +65,20 @@ 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); \
62-
cat $(crd_template_header) > $(helm_chart_source_dir)/templates/crd-$$i; \
63-
$(sed_inplace) "s/REPLACE_CRD_EXPRESSION/$(crds_expression)/g" $(helm_chart_source_dir)/templates/crd-$$i; \
64-
$(sed_inplace) "s/REPLACE_CRD_NAME/$$crd_name/g" $(helm_chart_source_dir)/templates/crd-$$i; \
65-
$(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; \
67-
cat $(crd_template_footer) >> $(helm_chart_source_dir)/templates/crd-$$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); \
75+
crd_template_file=$(helm_chart_source_dir)/templates/crd-$(notdir $$i)
76+
cat $(crd_template_header) > $(crd_template_file); \
77+
$(sed_inplace) "s/REPLACE_CRD_EXPRESSION/$(crds_expression)/g" $(crd_template_file); \
78+
$(sed_inplace) "s/REPLACE_CRD_NAME/$$crd_name/g" $(crd_template_file); \
79+
$(sed_inplace) "s/REPLACE_LABELS_TEMPLATE/$(helm_labels_template_name)/g" $(crd_template_file); \
80+
$(YQ) -I2 '{"spec": .spec}' $$i >> $(crd_template_file); \
81+
cat $(crd_template_footer) >> $(crd_template_file); \
6882
done
6983

7084
@if [ -n "$$(ls $(crds_gen_temp) 2>/dev/null)" ]; then \

0 commit comments

Comments
 (0)