Skip to content

Commit 81400ae

Browse files
dimakisFiona-Waters
authored andcommitted
build: split crds into their own files
1 parent 07f6abf commit 81400ae

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

Makefile

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,12 @@ defaults:
146146

147147
gofmt -w $(DEFAULTS_TEST_FILE)
148148

149+
# this encounters sed issues on MacOS, quick fix is to use gsed or to escape the parentheses i.e. \( \)
149150
.PHONY: manifests
150151
manifests: controller-gen kustomize ## Generate RBAC objects.
151152
$(CONTROLLER_GEN) rbac:roleName=manager-role webhook paths="./..."
152153
$(SED) -i -E "s|(- )\${MCAD_REPO}.*|\1\${MCAD_CRD}|" config/crd/mcad/kustomization.yaml
153-
$(KUSTOMIZE) build config/crd/mcad > config/crd/mcad.yaml
154+
$(KUSTOMIZE) build config/crd/mcad > config/crd/mcad.yaml && make split_yaml FILE=config/crd/mcad.yaml
154155
git restore config/*
155156

156157
.PHONY: fmt
@@ -387,3 +388,25 @@ verify-imports: openshift-goimports ## Run import verifications.
387388
.PHONY: scorecard-bundle
388389
scorecard-bundle: install-operator-sdk ## Run scorecard tests on bundle image.
389390
$(OPERATOR_SDK) scorecard bundle
391+
392+
393+
FILE ?= input.yaml # Default value, it isn't a file, but the make cmds fill hang for longer without it
394+
temp_dir := temp_split
395+
output_dir := 'config/crd/'
396+
397+
# this works on a MacOS by replacing awk with gawk
398+
.PHONY: split_yaml
399+
split_yaml:
400+
@mkdir -p $(temp_dir)
401+
@awk '/apiVersion: /{if (x>0) close("$(temp_dir)/section_" x ".yaml"); x++}{print > "$(temp_dir)/section_"x".yaml"}' $(FILE)
402+
@$(MAKE) process_sections
403+
404+
.PHONY: process_sections
405+
process_sections:
406+
@mkdir -p $(output_dir)
407+
@for section_file in $(temp_dir)/section_*; do \
408+
metadata_name=$$(yq e '.metadata.name' $$section_file); \
409+
file_name=$$(echo $$metadata_name | awk -F'.' '{print $$2"."$$3"_"$$1".yaml"}'); \
410+
mv $$section_file $(output_dir)/$$file_name; \
411+
done
412+
@rm -r $(temp_dir)

0 commit comments

Comments
 (0)