Skip to content

Commit 337dc4c

Browse files
committed
Use yq to add nullables to bundle CRD (#796)
* remove placeholder deployment, use operator-sdk `--extra-service-accounts`, yq +nullables * use var to shorten yq eval expression
1 parent 2b11fe1 commit 337dc4c

File tree

7 files changed

+1608
-1943
lines changed

7 files changed

+1608
-1943
lines changed

Makefile

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -290,22 +290,55 @@ rm -rf $$TMP_DIR ;\
290290
}
291291
endef
292292

293-
yq:
293+
$(GOBIN)/yq:
294294
go install github.com/mikefarah/yq/v4@latest
295295

296296
.PHONY: bundle
297-
bundle: manifests kustomize yq ## Generate bundle manifests and metadata, then validate generated files.
297+
bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
298298
operator-sdk generate kustomize manifests -q
299299
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
300-
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
301-
# Removes placeholder velero deployment used so `operator-sdk generate bundle` adds velero service account and role to bundle CSV using yq. See https://github.com/mikefarah/yq/#install
302-
$(GOBIN)/yq eval 'del(.spec.install.spec.deployments.1)' bundle/manifests/oadp-operator.clusterserviceversion.yaml > bundle/manifests/oadp-operator.clusterserviceversion.yaml.yqresult
303-
mv bundle/manifests/oadp-operator.clusterserviceversion.yaml.yqresult bundle/manifests/oadp-operator.clusterserviceversion.yaml
300+
$(KUSTOMIZE) build config/manifests | operator-sdk generate bundle -q --extra-service-accounts "velero" --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
301+
@make nullable-crds-bundle nullable-crds-config # patch nullables in CRDs
304302
# Copy updated bundle.Dockerfile to CI's Dockerfile.bundle
305303
# TODO: update CI to use generated one
306304
cp bundle.Dockerfile build/Dockerfile.bundle
307305
operator-sdk bundle validate ./bundle
308306

307+
.PHONY: nullable-crds-bundle
308+
nullable-crds-bundle: DPA_SPEC_CONFIG_PROP = .spec.versions.0.schema.openAPIV3Schema.properties.spec.properties.configuration.properties
309+
nullable-crds-bundle: PROP_RESOURCE_ALLOC = properties.podConfig.properties.resourceAllocations
310+
nullable-crds-bundle: VELERO_RESOURCE_ALLOC = $(DPA_SPEC_CONFIG_PROP).velero.$(PROP_RESOURCE_ALLOC)
311+
nullable-crds-bundle: RESTIC_RESOURCE_ALLOC = $(DPA_SPEC_CONFIG_PROP).restic.$(PROP_RESOURCE_ALLOC)
312+
nullable-crds-bundle: DPA_CRD_YAML ?= bundle/manifests/oadp.openshift.io_dataprotectionapplications.yaml
313+
nullable-crds-bundle: $(GOBIN)/yq
314+
# Velero CRD
315+
@$(GOBIN)/yq '$(VELERO_RESOURCE_ALLOC).nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
316+
@mv $(DPA_CRD_YAML).yqresult $(DPA_CRD_YAML)
317+
@$(GOBIN)/yq '$(VELERO_RESOURCE_ALLOC).properties.limits.nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
318+
@mv $(DPA_CRD_YAML).yqresult $(DPA_CRD_YAML)
319+
@$(GOBIN)/yq '$(VELERO_RESOURCE_ALLOC).properties.limits.additionalProperties.nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
320+
@mv $(DPA_CRD_YAML).yqresult $(DPA_CRD_YAML)
321+
@$(GOBIN)/yq '$(VELERO_RESOURCE_ALLOC).properties.requests.nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
322+
@mv $(DPA_CRD_YAML).yqresult $(DPA_CRD_YAML)
323+
@$(GOBIN)/yq '$(VELERO_RESOURCE_ALLOC).properties.requests.additionalProperties.nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
324+
@mv $(DPA_CRD_YAML).yqresult $(DPA_CRD_YAML)
325+
# Restic CRD
326+
@$(GOBIN)/yq '$(RESTIC_RESOURCE_ALLOC).nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
327+
@mv $(DPA_CRD_YAML).yqresult $(DPA_CRD_YAML)
328+
@$(GOBIN)/yq '$(RESTIC_RESOURCE_ALLOC).properties.limits.nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
329+
@mv $(DPA_CRD_YAML).yqresult $(DPA_CRD_YAML)
330+
@$(GOBIN)/yq '$(RESTIC_RESOURCE_ALLOC).properties.limits.additionalProperties.nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
331+
@mv $(DPA_CRD_YAML).yqresult $(DPA_CRD_YAML)
332+
@$(GOBIN)/yq '$(RESTIC_RESOURCE_ALLOC).properties.requests.nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
333+
@mv $(DPA_CRD_YAML).yqresult $(DPA_CRD_YAML)
334+
@$(GOBIN)/yq '$(RESTIC_RESOURCE_ALLOC).properties.requests.additionalProperties.nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
335+
@mv $(DPA_CRD_YAML).yqresult $(DPA_CRD_YAML)
336+
337+
.PHONY: nullable-crds-config
338+
nullable-crds-config: DPA_CRD_YAML ?= config/crd/bases/oadp.openshift.io_dataprotectionapplications.yaml
339+
nullable-crds-config:
340+
DPA_CRD_YAML=$(DPA_CRD_YAML) make nullable-crds-bundle
341+
309342
.PHONY: bundle-build
310343
bundle-build: ## Build the bundle image.
311344
docker build -f bundle.Dockerfile -t $(BUNDLE_IMG) . $(DOCKER_BUILD_ARGS)

0 commit comments

Comments
 (0)