Skip to content
This repository has been archived by the owner on Oct 22, 2024. It is now read-only.

Commit

Permalink
operator-sdk 1.15.0, kustomize 4.4.1, controller-gen 0.7.0
Browse files Browse the repository at this point in the history
When generating the bundle with operator-sdk 1.6.1, verification for
OpenShift fails because there operator-sdk 1.13.1 is used which complains:

ERRO[0000] Error: Value pmem-csi-operator: invalid service account found in bundle. sa name cannot match service account defined for deployment spec in CSV

(cherry picked from commit 4e8e9dc)
  • Loading branch information
pohly committed Jan 11, 2022
1 parent 6acfa2a commit 4ef304c
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 54 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ include test/start-stop.make
include test/test.make

#Kustomize latest release version
KUSTOMIZE_VERSION=v4.0.5
KUSTOMIZE_VERSION=v4.4.1
_work/kustomize_${KUSTOMIZE_VERSION}_linux_amd64.tar.gz:
curl -L https://github.com/kubernetes-sigs/kustomize/releases/download/kustomize/${KUSTOMIZE_VERSION}/kustomize_${KUSTOMIZE_VERSION}_linux_amd64.tar.gz -o $(abspath $@)

Expand Down
4 changes: 2 additions & 2 deletions deploy/crd/pmem-csi.intel.com_pmemcsideployments.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# This file was generated by controller-gen v0.3.0 via 'make operator-generate-crd'
# This file was generated by controller-gen v0.7.0 via 'make operator-generate-crd'

---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.3.0
controller-gen.kubebuilder.io/version: v0.7.0
creationTimestamp: null
name: pmemcsideployments.pmem-csi.intel.com
spec:
Expand Down
86 changes: 35 additions & 51 deletions operator/operator.make
Original file line number Diff line number Diff line change
@@ -1,51 +1,30 @@
OPERATOR_SDK_VERSION=1.6.1
OPERATOR_SDK_VERSION=1.15.0
CONTROLLER_GEN_VERSION=v0.7.0
CONTROLLER_GEN=_work/bin/controller-gen-$(CONTROLLER_GEN_VERSION)

# download operator-sdk binary
_work/bin/operator-sdk-$(OPERATOR_SDK_VERSION):
mkdir -p _work/bin/ 2> /dev/null
# Building operator-sdk from sources as that needs fixes for:
# https://github.com/operator-framework/operator-sdk/pull/4816
tmpdir=`mktemp -d` && \
trap 'set -x; rm -rf $$tmpdir' EXIT && \
git clone --branch $(OPERATOR_SDK_VERSION)+fixes https://github.com/avalluri/operator-sdk.git $$tmpdir && \
cd $$tmpdir && $(MAKE) build/operator-sdk && \
cp $$tmpdir/build/operator-sdk $(abspath $@) && \
chmod a+x $(abspath $@)
cd $(dir $@); ln -sf operator-sdk-$(OPERATOR_SDK_VERSION) operator-sdk
mkdir -p $(@D)
curl -L https://github.com/operator-framework/operator-sdk/releases/download/v$(OPERATOR_SDK_VERSION)/operator-sdk_linux_amd64 -o $@
chmod a+x $@
ln -sf $(@F) $(@D)/operator-sdk

# Re-generates the K8S source. This target is supposed to run
# upon any changes made to operator api.
#
# GOROOT is needed because of https://github.com/operator-framework/operator-sdk/issues/1854#issuecomment-525132306
operator-generate-k8s: controller-gen
GOROOT=$(shell $(GO) env GOROOT) $(CONTROLLER_GEN) object paths=./pkg/apis/...
operator-generate-k8s: $(CONTROLLER_GEN)
$< object paths=./pkg/apis/...

# find or download if necessary controller-gen
# this make target is copied from Makefile generated
# by operator-sdk init
controller-gen:
ifeq (, $(shell which controller-gen))
@{ \
set -e; \
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
cd $$CONTROLLER_GEN_TMP_DIR ;\
GOPATH=$$($(GO) env GOPATH) ;\
$(GO) mod init tmp ;\
$(GO) get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.3.0 ;\
rm -rf $$CONTROLLER_GEN_TMP_DIR; \
}
CONTROLLER_GEN=$(GOPATH)/bin/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif
# Build controller-gen from source.
$(CONTROLLER_GEN):
mkdir -p $(@D)
GOBIN=$(abspath $(@D)) $(GO) install sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION)
ln -sf controller-gen $@

ifeq ($(REPO_ROOT), )
REPO_ROOT=$(shell pwd)
endif
MANIFESTS_DIR=$(REPO_ROOT)/deploy/kustomize/olm-catalog
CATALOG_DIR=$(REPO_ROOT)/deploy/olm-catalog
BUNDLE_DIR=$(REPO_ROOT)/deploy/olm-bundle/$(MAJOR_MINOR_PATCH_VERSION)
CRD_DIR=$(REPO_ROOT)/deploy/crd

MANIFESTS_DIR=deploy/kustomize/olm-catalog
CATALOG_DIR=deploy/olm-catalog
BUNDLE_DIR=deploy/olm-bundle/$(MAJOR_MINOR_PATCH_VERSION)
CRD_DIR=deploy/crd
# CHANNELS: A comma-separated list of channels the generated
# bundle belongs to. This supposed to be all the channel names we support.
# Currently, alpha(all < v1.0) and stable(=v1.0)
Expand All @@ -65,11 +44,10 @@ PATCH_REPLACES := sed -i -e 's;\(.*\)\(version:.*\);\1replaces: pmem-csi-operato
PATCH_DATE := sed -i -e 's;\(.*createdAt: \).*;\1$(shell date +%FT%TZ);g'

# Generate CRD
operator-generate-crd: controller-gen
operator-generate-crd: $(CONTROLLER_GEN)
@echo "Generating CRD in $(CRD_DIR) ..."
cd $(REPO_ROOT) && $(CONTROLLER_GEN) crd:trivialVersions=true,crdVersions=v1 paths=./pkg/apis/... output:dir=$(CRD_DIR)/
version="$(shell $(CONTROLLER_GEN) --version |cut -f2 -d':')"; \
sed -i "1s/^/# This file was generated by controller-gen$$version via 'make operator-generate-crd'\n/" $(CRD_DIR)/*
$(CONTROLLER_GEN) crd paths=./pkg/apis/... output:dir=$(CRD_DIR)
sed -i "1s/^/# This file was generated by controller-gen $(CONTROLLER_GEN_VERSION) via 'make operator-generate-crd'\n/" $(CRD_DIR)/*

# Generate bundle manifests for OLM
# The bundle.Dockerfile file is generated in the $root folder,
Expand All @@ -81,21 +59,27 @@ operator-generate-crd: controller-gen
# test configurations.
operator-generate-bundle: _work/bin/operator-sdk-$(OPERATOR_SDK_VERSION) _work/kustomize operator-generate-crd
@echo "Generating operator bundle in $(BUNDLE_DIR) ..."
@_work/kustomize build --load-restrictor LoadRestrictionsNone $(MANIFESTS_DIR) | $< generate bundle --version=$(MAJOR_MINOR_PATCH_VERSION) \
--kustomize-dir=$(MANIFESTS_DIR) --output-dir=$(BUNDLE_DIR) --channels ${CHANNELS} --default-channel ${DEFAULT_CHANNEL}
rm -rf $(BUNDLE_DIR)
mkdir -p $(BUNDLE_DIR)
# Generate input YAML first. This might fail...
_work/kustomize build --load-restrictor LoadRestrictionsNone $(MANIFESTS_DIR) >$(BUNDLE_DIR)/manifests.yaml
# Specifying --kustomize-dir seems redundant because stdin already contains our ClusterServiceVersion,
# but without it the final ClusterServiceVersion in the bundle just has some automatically generated fields.
cat $(BUNDLE_DIR)/manifests.yaml | $< generate bundle --kustomize-dir=$(MANIFESTS_DIR) --version=$(MAJOR_MINOR_PATCH_VERSION) --output-dir=$(BUNDLE_DIR) --channels ${CHANNELS} --default-channel ${DEFAULT_CHANNEL}
rm $(BUNDLE_DIR)/manifests.yaml
$(PATCH_VERSIONS) $(BUNDLE_DIR)/manifests/pmem-csi-operator.clusterserviceversion.yaml
ifdef REPLACES
@$(PATCH_REPLACES) $(BUNDLE_DIR)/manifests/pmem-csi-operator.clusterserviceversion.yaml
$(PATCH_REPLACES) $(BUNDLE_DIR)/manifests/pmem-csi-operator.clusterserviceversion.yaml
endif
$(PATCH_DATE) $(BUNDLE_DIR)/manifests/pmem-csi-operator.clusterserviceversion.yaml
@sed -i -e "s;$(BUNDLE_DIR)/;;g" -e "/scorecard/d" -e '/FROM scratch/a LABEL com.redhat.openshift.versions="$(OPENSHIFT_VERSIONS)"' bundle.Dockerfile
@sed -i -e "/scorecard/d" $(BUNDLE_DIR)/metadata/annotations.yaml
@mv bundle.Dockerfile $(BUNDLE_DIR)
sed -i -e "s;$(BUNDLE_DIR)/;;g" -e "/scorecard/d" -e '/FROM scratch/a LABEL com.redhat.openshift.versions="$(OPENSHIFT_VERSIONS)"' bundle.Dockerfile
sed -i -e "/scorecard/d" $(BUNDLE_DIR)/metadata/annotations.yaml
mv bundle.Dockerfile $(BUNDLE_DIR)
@make operator-validate-bundle

operator-validate-bundle: _work/bin/operator-sdk-$(OPERATOR_SDK_VERSION) $(BUNDLE_DIR)
@if ! OUT="$$($< bundle validate --select-optional name=operatorhub $(BUNDLE_DIR))"; then \
echo >&2 "ERROR: Operator bundle did not pass validation:"; \
echo >&2 "ERROR: Operator bundle in $(BUNDLE_DIR) did not pass validation:"; \
echo >&2 "$$OUT"; \
exit 1; \
fi
Expand Down

0 comments on commit 4ef304c

Please sign in to comment.