Skip to content

Commit 50ef480

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

1 file changed

Lines changed: 23 additions & 8 deletions

File tree

modules/helm/crds.mk

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ 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+
crds_template_include_pattern := *.yaml
44+
# Space-separated list of basenames to exclude (e.g. foo.yaml *_test.yaml)
45+
crds_template_exclude_pattern ?=
46+
47+
define filter-out-basenames
48+
$(if $(strip $(2)), \
49+
$(foreach f,$(1),$(if $(filter $(2),$(notdir $(f))),,$(f))), \
50+
$(1))
51+
endef
4352

4453
.PHONY: generate-crds
4554
## Generate CRD manifests.
@@ -57,14 +66,20 @@ generate-crds: | $(NEEDS_CONTROLLER-GEN) $(NEEDS_YQ)
5766

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

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; \
69+
$(eval crds_gen_temp_all_files := $(wildcard $(crds_gen_temp)/$(crds_template_include_pattern)))
70+
$(eval crds_gen_temp_files := $(if $(crds_template_exclude_pattern), \
71+
$(call filter-out-basenames,$(crds_gen_temp_all_files),$(crds_template_exclude_pattern)), \
72+
$(crds_gen_temp_all_files)))
73+
74+
@for f in $(crds_gen_temp_files); do \
75+
crd_name=$$($(YQ) eval '.metadata.name' $$f); \
76+
crd_template_file="$(helm_chart_source_dir)/templates/crd-$$(basename $$i)"; \
77+
cat $(crd_template_header) > $$crd_template_file; \
78+
$(sed_inplace) "s/REPLACE_CRD_EXPRESSION/$(crds_expression)/g" $$crd_template_file; \
79+
$(sed_inplace) "s/REPLACE_CRD_NAME/$$crd_name/g" $$crd_template_file; \
80+
$(sed_inplace) "s/REPLACE_LABELS_TEMPLATE/$(helm_labels_template_name)/g" $$crd_template_file; \
81+
$(YQ) -I2 '{"spec": .spec}' $$f >> $$crd_template_file; \
82+
cat $(crd_template_footer) >> $$crd_template_file; \
6883
done
6984

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

0 commit comments

Comments
 (0)