Skip to content

Commit e6f4ba3

Browse files
authored
updated Makefile to generate proper CSV (#988)
* fixed make manifests for OperandConfig CRD - to have preserve unknown fields for ConfigService.spec Signed-off-by: Henry H Li <[email protected]> * regenerated deepcopy Signed-off-by: Henry H Li <[email protected]> * added make kustomize Signed-off-by: Henry H Li <[email protected]> * added make run-bundle and make cleanup-bundle - updated related make targets for generating proper bundle CSV - yq automatically added indentation to CSV downgraded operator sdk version to v1.29.0 - because hitting same issue as cs-operator operator-framework/operator-sdk#6584 Signed-off-by: Henry H Li <[email protected]> * changed tests to use ExtensionWithMarker type Signed-off-by: Henry H Li <[email protected]> --------- Signed-off-by: Henry H Li <[email protected]>
1 parent 9b77e06 commit e6f4ba3

File tree

10 files changed

+413
-302
lines changed

10 files changed

+413
-302
lines changed

Makefile

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
KUBECTL ?= $(shell which kubectl)
1919
OPERATOR_SDK ?= $(shell which operator-sdk)
2020
OPM ?= $(shell which opm)
21+
KUSTOMIZE ?= $(shell which kustomize)
22+
KUSTOMIZE_VERSION=v3.8.7
2123

2224
ENVCRDS_DIR=$(shell pwd)/testcrds
2325

@@ -33,7 +35,9 @@ VERSION ?= $(shell git describe --exact-match 2> /dev/null || \
3335
RELEASE_VERSION ?= $(shell cat ./version/version.go | grep "Version =" | awk '{ print $$3}' | tr -d '"')
3436
LATEST_VERSION ?= latest
3537
OPERATOR_SDK_VERSION=v1.24.0
36-
YQ_VERSION=v4.3.1
38+
YQ_VERSION=v4.17.2
39+
DEFAULT_CHANNEL ?= v$(shell cat ./version/version.go | grep "Version =" | awk '{ print $$3}' | tr -d '"' | cut -d '.' -f1,2)
40+
CHANNELS ?= $(DEFAULT_CHANNEL)
3741

3842
LOCAL_OS := $(shell uname)
3943
ifeq ($(LOCAL_OS),Linux)
@@ -134,6 +138,19 @@ else
134138
YQ=$(shell which yq)
135139
endif
136140

141+
kustomize: ## Install kustomize
142+
ifeq (, $(shell which kustomize 2>/dev/null))
143+
@{ \
144+
set -e ;\
145+
mkdir -p bin ;\
146+
echo "Downloading kustomize ...";\
147+
curl -sSLo - https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/$(KUSTOMIZE_VERSION)/kustomize_$(KUSTOMIZE_VERSION)_$(LOCAL_OS)_$(LOCAL_ARCH).tar.gz | tar xzf - -C bin/ ;\
148+
}
149+
KUSTOMIZE=$(realpath ./bin/kustomize)
150+
else
151+
KUSTOMIZE=$(shell which kustomize)
152+
endif
153+
137154
operator-sdk:
138155
ifneq ($(shell operator-sdk version | cut -d ',' -f1 | cut -d ':' -f2 | tr -d '"' | xargs | cut -d '.' -f1), v1)
139156
@{ \
@@ -191,6 +208,10 @@ bundle-manifests:
191208
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle \
192209
-q --overwrite --version $(OPERATOR_VERSION) $(BUNDLE_METADATA_OPTS)
193210
$(OPERATOR_SDK) bundle validate ./bundle
211+
$(YQ) eval-all -i '.spec.relatedImages = load("config/manifests/bases/operand-deployment-lifecycle-manager.clusterserviceversion.yaml").spec.relatedImages' bundle/manifests/operand-deployment-lifecycle-manager.clusterserviceversion.yaml
212+
# Need to replace fields this way to avoid changing PROJECT name and CSV file name, which may or may not impact CICD automation
213+
$(YQ) e -i '.annotations["operators.operatorframework.io.bundle.package.v1"] = "ibm-odlm"' bundle/metadata/annotations.yaml
214+
sed -i'' s/operand-deployment-lifecycle-manager/ibm-odlm/ bundle.Dockerfile
194215

195216
generate-all: manifests kustomize operator-sdk ## Generate bundle manifests, metadata and package manifests
196217
$(OPERATOR_SDK) generate kustomize manifests -q
@@ -245,8 +266,8 @@ build-operator-image: $(CONFIG_DOCKER_TARGET) ## Build the operator image.
245266
--build-arg GOARCH=$(LOCAL_ARCH) -f Dockerfile .
246267

247268
build-operator-dev-image: ## Build the operator dev image.
248-
@echo "Building the $(OPERATOR_IMAGE_NAME) docker image..."
249-
@docker build -t $(OPERATOR_IMAGE_NAME):$(VERSION) \
269+
@echo "Building the $(DEV_REGISTRY)/$(OPERATOR_IMAGE_NAME) docker image..."
270+
@docker build -t $(DEV_REGISTRY)/$(OPERATOR_IMAGE_NAME):$(VERSION) \
250271
--build-arg VCS_REF=$(VCS_REF) --build-arg VCS_URL=$(VCS_URL) \
251272
--build-arg GOARCH=$(LOCAL_ARCH) -f Dockerfile .
252273

@@ -260,7 +281,6 @@ build-test-operator-image: $(CONFIG_DOCKER_TARGET) ## Build the operator test im
260281

261282
build-push-dev-image: build-operator-dev-image ## Build and push the operator dev images.
262283
@echo "Pushing the $(DEV_REGISTRY)/$(OPERATOR_IMAGE_NAME):$(VERSION) docker image to $(DEV_REGISTRY)..."
263-
@docker tag $(OPERATOR_IMAGE_NAME):$(VERSION) $(DEV_REGISTRY)/$(OPERATOR_IMAGE_NAME):$(VERSION)
264284
@docker push $(DEV_REGISTRY)/$(OPERATOR_IMAGE_NAME):$(VERSION)
265285

266286
build-push-image: $(CONFIG_DOCKER_TARGET) build-operator-image ## Build and push the operator images.
@@ -269,12 +289,9 @@ build-push-image: $(CONFIG_DOCKER_TARGET) build-operator-image ## Build and pus
269289
@docker push $(ARTIFACTORYA_REGISTRY)/$(OPERATOR_IMAGE_NAME)-$(LOCAL_ARCH):$(VERSION)
270290

271291
build-push-bundle-image: yq
272-
@cp -f bundle/manifests/operand-deployment-lifecycle-manager.clusterserviceversion.yaml /tmp/operand-deployment-lifecycle-manager.clusterserviceversion.yaml
273-
$(YQ) eval -i 'del(.spec.replaces)' bundle/manifests/operand-deployment-lifecycle-manager.clusterserviceversion.yaml
274292
@docker build -f bundle.Dockerfile -t $(QUAY_REGISTRY)/$(BUNDLE_IMAGE_NAME)-$(LOCAL_ARCH):$(VERSION) .
275293
@echo "Pushing the $(BUNDLE_IMAGE_NAME) docker image for $(LOCAL_ARCH)..."
276294
@docker push $(QUAY_REGISTRY)/$(BUNDLE_IMAGE_NAME)-$(LOCAL_ARCH):$(VERSION)
277-
@mv /tmp/operand-deployment-lifecycle-manager.clusterserviceversion.yaml bundle/manifests/operand-deployment-lifecycle-manager.clusterserviceversion.yaml
278295

279296
build-catalog-source:
280297
@opm -u docker index add --bundles $(QUAY_REGISTRY)/$(BUNDLE_IMAGE_NAME)-$(LOCAL_ARCH):$(VERSION) --tag $(QUAY_REGISTRY)/$(OPERATOR_IMAGE_NAME)-catalog:$(VERSION)
@@ -285,6 +302,12 @@ build-catalog: build-push-bundle-image build-catalog-source
285302
multiarch-image: $(CONFIG_DOCKER_TARGET) ## Generate multiarch images for operator image.
286303
@MAX_PULLING_RETRY=20 RETRY_INTERVAL=30 common/scripts/multiarch_image.sh $(ARTIFACTORYA_REGISTRY) $(OPERATOR_IMAGE_NAME) $(VERSION) $(RELEASE_VERSION)
287304

305+
run-bundle:
306+
$(OPERATOR_SDK) run bundle $(QUAY_REGISTRY)/$(BUNDLE_IMAGE_NAME)-$(LOCAL_ARCH):$(VERSION) --install-mode OwnNamespace
307+
308+
cleanup-bundle:
309+
$(OPERATOR_SDK) cleanup ibm-odlm
310+
288311
##@ Help
289312
help: ## Display this help
290313
@echo "Usage:\n make \033[36m<target>\033[0m"

api/v1alpha1/operandconfig_types.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,17 @@ type OperandConfigSpec struct {
3131
Services []ConfigService `json:"services,omitempty"`
3232
}
3333

34+
// +kubebuilder:pruning:PreserveUnknownFields
35+
type ExtensionWithMarker struct {
36+
runtime.RawExtension `json:",inline"`
37+
}
38+
3439
// ConfigService defines the configuration of the service.
3540
type ConfigService struct {
3641
// Name is the subscription name.
3742
Name string `json:"name"`
3843
// Spec is the configuration map of custom resource.
39-
Spec map[string]runtime.RawExtension `json:"spec,omitempty"`
44+
Spec map[string]ExtensionWithMarker `json:"spec,omitempty"`
4045
// State is a flag to enable or disable service.
4146
State string `json:"state,omitempty"`
4247
// Resources is used to specify the kubernetes resources that are needed for the service.

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 81 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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=ibm-odlm
88
LABEL operators.operatorframework.io.bundle.channels.v1=v4.2
99
LABEL operators.operatorframework.io.bundle.channel.default.v1=v4.2
10-
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.24.0
10+
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.29.0
1111
LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1
1212
LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v3
1313

0 commit comments

Comments
 (0)