@@ -146,11 +146,12 @@ defaults:
146
146
147
147
gofmt -w $(DEFAULTS_TEST_FILE)
148
148
149
+ # this encounters sed issues on MacOS, quick fix is to use gsed or to escape the parentheses i.e. \( \)
149
150
.PHONY : manifests
150
151
manifests : controller-gen kustomize # # Generate RBAC objects.
151
152
$(CONTROLLER_GEN ) rbac:roleName=manager-role webhook paths=" ./..."
152
153
$(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
154
155
git restore config/*
155
156
156
157
.PHONY : fmt
@@ -387,3 +388,25 @@ verify-imports: openshift-goimports ## Run import verifications.
387
388
.PHONY : scorecard-bundle
388
389
scorecard-bundle : install-operator-sdk # # Run scorecard tests on bundle image.
389
390
$(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