Skip to content

Commit 772fb8b

Browse files
authored
oadp-1.1: yq format when for make test. pin gomega to v1.22 (#859)
* master: Makefile Automate operator-sdk install, preserve nullables. (#846) * Makefile automate operator-sdk installation * pin yq to 4.28.1 for go 1.17 * Preserve DPA nullables for `make test` Signed-off-by: Tiger Kaovilai <[email protected]> Signed-off-by: Tiger Kaovilai <[email protected]> * ran `make bundle` Signed-off-by: Tiger Kaovilai <[email protected]>
1 parent 19c4952 commit 772fb8b

File tree

8 files changed

+48
-31
lines changed

8 files changed

+48
-31
lines changed

Makefile

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
153153
# Commenting out default which overwrites scoped config/rbac/role.yaml
154154
# GOFLAGS="-mod=mod" $(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
155155
GOFLAGS="-mod=mod" $(CONTROLLER_GEN) $(CRD_OPTIONS) webhook paths="./..." output:crd:artifacts:config=config/crd/bases
156+
# run make nullables to generate nullable fields after all manifest changesin dependent targets.
157+
# It's not included here because `test` and `bundle` target have different yaml styes.
158+
# To keep dpa CRD the same, nullables have been added to test and bundle target separately.
156159

157160
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
158161
GOFLAGS="-mod=mod" $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
@@ -163,7 +166,7 @@ fmt: ## Run go fmt against code.
163166
vet: ## Run go vet against code.
164167
go vet -mod=mod ./...
165168

166-
test: manifests generate fmt vet envtest ## Run tests.
169+
test: manifests nullables generate fmt vet envtest ## Run tests.
167170
KUBEBUILDER_ASSETS="$(ENVTESTPATH)" go test -mod=mod ./controllers/... ./pkg/... -coverprofile cover.out
168171

169172

@@ -290,48 +293,62 @@ rm -rf $$TMP_DIR ;\
290293
}
291294
endef
292295

293-
$(GOBIN)/yq:
294-
go install github.com/mikefarah/yq/v4@latest
296+
YQ = $(shell pwd)/bin/yq
297+
yq: ## Download yq locally if necessary.
298+
# 4.28.1 is latest with go 1.17 go.mod
299+
$(call go-install-tool,$(YQ),github.com/mikefarah/yq/[email protected])
300+
301+
OPERATOR_SDK = $(shell pwd)/bin/operator-sdk
302+
operator-sdk:
303+
# Download operator-sdk locally if does not exist
304+
if [ ! -f $(OPERATOR_SDK) ]; then \
305+
curl -Lo $(OPERATOR_SDK) https://github.com/operator-framework/operator-sdk/releases/download/v1.23.0/operator-sdk_$(shell go env GOOS)_$(shell go env GOARCH) ; \
306+
chmod +x $(OPERATOR_SDK); \
307+
fi
295308

296309
.PHONY: bundle
297-
bundle: manifests kustomize ## Generate bundle manifests and metadata, then validate generated files.
298-
operator-sdk generate kustomize manifests -q
310+
bundle: manifests kustomize operator-sdk ## Generate bundle manifests and metadata, then validate generated files.
311+
$(OPERATOR_SDK) generate kustomize manifests -q
299312
cd config/manager && $(KUSTOMIZE) edit set image controller=$(IMG)
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
313+
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle -q --extra-service-accounts "velero" --overwrite --version $(VERSION) $(BUNDLE_METADATA_OPTS)
314+
@make nullables
302315
# Copy updated bundle.Dockerfile to CI's Dockerfile.bundle
303316
# TODO: update CI to use generated one
304317
cp bundle.Dockerfile build/Dockerfile.bundle
305-
operator-sdk bundle validate ./bundle
318+
$(OPERATOR_SDK) bundle validate ./bundle
319+
320+
.PHONY: nullables
321+
nullables:
322+
@make nullable-crds-bundle nullable-crds-config # patch nullables in CRDs
306323

307324
.PHONY: nullable-crds-bundle
308325
nullable-crds-bundle: DPA_SPEC_CONFIG_PROP = .spec.versions.0.schema.openAPIV3Schema.properties.spec.properties.configuration.properties
309326
nullable-crds-bundle: PROP_RESOURCE_ALLOC = properties.podConfig.properties.resourceAllocations
310327
nullable-crds-bundle: VELERO_RESOURCE_ALLOC = $(DPA_SPEC_CONFIG_PROP).velero.$(PROP_RESOURCE_ALLOC)
311328
nullable-crds-bundle: RESTIC_RESOURCE_ALLOC = $(DPA_SPEC_CONFIG_PROP).restic.$(PROP_RESOURCE_ALLOC)
312329
nullable-crds-bundle: DPA_CRD_YAML ?= bundle/manifests/oadp.openshift.io_dataprotectionapplications.yaml
313-
nullable-crds-bundle: $(GOBIN)/yq
330+
nullable-crds-bundle: yq
314331
# Velero CRD
315-
@$(GOBIN)/yq '$(VELERO_RESOURCE_ALLOC).nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
332+
@$(YQ) '$(VELERO_RESOURCE_ALLOC).nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
316333
@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
334+
@$(YQ) '$(VELERO_RESOURCE_ALLOC).properties.limits.nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
318335
@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
336+
@$(YQ) '$(VELERO_RESOURCE_ALLOC).properties.limits.additionalProperties.nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
320337
@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
338+
@$(YQ) '$(VELERO_RESOURCE_ALLOC).properties.requests.nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
322339
@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
340+
@$(YQ) '$(VELERO_RESOURCE_ALLOC).properties.requests.additionalProperties.nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
324341
@mv $(DPA_CRD_YAML).yqresult $(DPA_CRD_YAML)
325342
# Restic CRD
326-
@$(GOBIN)/yq '$(RESTIC_RESOURCE_ALLOC).nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
343+
@$(YQ) '$(RESTIC_RESOURCE_ALLOC).nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
327344
@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
345+
@$(YQ) '$(RESTIC_RESOURCE_ALLOC).properties.limits.nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
329346
@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
347+
@$(YQ) '$(RESTIC_RESOURCE_ALLOC).properties.limits.additionalProperties.nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
331348
@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
349+
@$(YQ) '$(RESTIC_RESOURCE_ALLOC).properties.requests.nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
333350
@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
351+
@$(YQ) '$(RESTIC_RESOURCE_ALLOC).properties.requests.additionalProperties.nullable = true' $(DPA_CRD_YAML) > $(DPA_CRD_YAML).yqresult
335352
@mv $(DPA_CRD_YAML).yqresult $(DPA_CRD_YAML)
336353

337354
.PHONY: nullable-crds-config
@@ -353,17 +370,17 @@ GIT_REV:=$(shell git rev-parse --short HEAD)
353370
deploy-olm: THIS_OPERATOR_IMAGE?=ttl.sh/oadp-operator-$(GIT_REV):1h # Set target specific variable
354371
deploy-olm: THIS_BUNDLE_IMAGE?=ttl.sh/oadp-operator-bundle-$(GIT_REV):1h # Set target specific variable
355372
deploy-olm: DEPLOY_TMP:=$(shell mktemp -d)/ # Set target specific variable
356-
deploy-olm:
373+
deploy-olm: operator-sdk ## Build current branch operator image, bundle image, push and install via OLM
357374
oc whoami # Check if logged in
358375
oc create namespace $(OADP_TEST_NAMESPACE) # This should error out if namespace already exists, delete namespace (to clear current resources) before proceeding
359376
@echo "DEPLOY_TMP: $(DEPLOY_TMP)"
360377
# build and push operator and bundle image
361-
# use operator-sdk to install bundle to authenticated cluster
378+
# use $(OPERATOR_SDK) to install bundle to authenticated cluster
362379
cp -r . $(DEPLOY_TMP) && cd $(DEPLOY_TMP) && \
363380
IMG=$(THIS_OPERATOR_IMAGE) BUNDLE_IMG=$(THIS_BUNDLE_IMAGE) \
364381
make docker-build docker-push bundle bundle-build bundle-push; \
365382
rm -rf $(DEPLOY_TMP)
366-
operator-sdk run bundle $(THIS_BUNDLE_IMAGE) --namespace $(OADP_TEST_NAMESPACE)
383+
$(OPERATOR_SDK) run bundle $(THIS_BUNDLE_IMAGE) --namespace $(OADP_TEST_NAMESPACE)
367384

368385
.PHONY: opm
369386
OPM = ./bin/opm

build/Dockerfile.bundle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/
77
LABEL operators.operatorframework.io.bundle.package.v1=oadp-operator
88
LABEL operators.operatorframework.io.bundle.channels.v1=stable,stable-1.1
99
LABEL operators.operatorframework.io.bundle.channel.default.v1=stable-1.1
10-
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.21.0
10+
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.23.0
1111
LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1
1212
LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v3
1313

bundle.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/
77
LABEL operators.operatorframework.io.bundle.package.v1=oadp-operator
88
LABEL operators.operatorframework.io.bundle.channels.v1=stable,stable-1.1
99
LABEL operators.operatorframework.io.bundle.channel.default.v1=stable-1.1
10-
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.21.0
10+
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.23.0
1111
LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1
1212
LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v3
1313

bundle/manifests/oadp-operator.clusterserviceversion.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ metadata:
170170
operators.openshift.io/infrastructure-features: '["Disconnected"]'
171171
operators.openshift.io/valid-subscription: '["OpenShift Container Platform", "OpenShift
172172
Platform Plus"]'
173-
operators.operatorframework.io/builder: operator-sdk-v1.21.0
173+
operators.operatorframework.io/builder: operator-sdk-v1.23.0
174174
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
175175
repository: https://github.com/openshift/oadp-operator
176176
support: Red Hat

bundle/manifests/oadp.openshift.io_cloudstorages.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ spec:
6464
- aws
6565
type: string
6666
region:
67-
description: region` for the bucket to be in, will be us-east-1 if
67+
description: region for the bucket to be in, will be us-east-1 if
6868
not set.
6969
type: string
7070
tags:
7171
additionalProperties:
7272
type: string
73-
description: tags` for the bucket
73+
description: tags for the bucket
7474
type: object
7575
required:
7676
- creationSecret

bundle/metadata/annotations.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ annotations:
66
operators.operatorframework.io.bundle.package.v1: oadp-operator
77
operators.operatorframework.io.bundle.channels.v1: stable,stable-1.1
88
operators.operatorframework.io.bundle.channel.default.v1: stable-1.1
9-
operators.operatorframework.io.metrics.builder: operator-sdk-v1.21.0
9+
operators.operatorframework.io.metrics.builder: operator-sdk-v1.23.0
1010
operators.operatorframework.io.metrics.mediatype.v1: metrics+v1
1111
operators.operatorframework.io.metrics.project_layout: go.kubebuilder.io/v3
1212

config/crd/bases/oadp.openshift.io_cloudstorages.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ spec:
6666
- aws
6767
type: string
6868
region:
69-
description: region` for the bucket to be in, will be us-east-1 if
69+
description: region for the bucket to be in, will be us-east-1 if
7070
not set.
7171
type: string
7272
tags:
7373
additionalProperties:
7474
type: string
75-
description: tags` for the bucket
75+
description: tags for the bucket
7676
type: object
7777
required:
7878
- creationSecret

tests/e2e/dpa_deployment_suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ var _ = Describe("Configuration testing for DPA Custom Resource", func() {
204204
PodConfig: &oadpv1alpha1.PodConfig{},
205205
DefaultPlugins: []oadpv1alpha1.DefaultPlugin{
206206
oadpv1alpha1.DefaultPluginCSI,
207-
func () oadpv1alpha1.DefaultPlugin {
207+
func() oadpv1alpha1.DefaultPlugin {
208208
if provider == "aws" {
209209
return oadpv1alpha1.DefaultPluginAWS
210210
} else if provider == "azure" {

0 commit comments

Comments
 (0)