diff --git a/Makefile b/Makefile index a1bba5163..683bd4542 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ endif ifneq (,$(DAPPER_HOST_ARCH)) -OPERATOR_SDK_VERSION := 1.0.1 +OPERATOR_SDK_VERSION := 1.23.0 OPERATOR_SDK := $(CURDIR)/bin/operator-sdk KUSTOMIZE_VERSION := 3.10.0 @@ -76,24 +76,6 @@ BUNDLE_DEFAULT_CHANNEL := --default-channel=$(DEFAULT_CHANNEL) endif BUNDLE_METADATA_OPTS ?= $(BUNDLE_CHANNELS) $(BUNDLE_DEFAULT_CHANNEL) -# Options for 'packagemanifests' -IS_CHANNEL_DEFAULT ?= 1 -ifneq ($(origin FROM_VERSION), undefined) -ifneq ($(FROM_VERSION), 0.0.0) -PKG_FROM_VERSION := --from-version=$(FROM_VERSION) -REPLACES_OP := add -else -REPLACES_OP := remove -endif -endif -ifneq ($(origin CHANNEL), undefined) -PKG_CHANNELS := --channel=$(CHANNEL) -endif -ifeq ($(IS_CHANNEL_DEFAULT), 1) -PKG_IS_DEFAULT_CHANNEL := --default-channel -endif -PKG_MAN_OPTS ?= $(PKG_FROM_VERSION) $(PKG_CHANNELS) $(PKG_IS_DEFAULT_CHANNEL) - # Set the kustomize base path ifeq ($(IS_OCP), true) KUSTOMIZE_BASE_PATH := $(CURDIR)/config/openshift @@ -154,11 +136,17 @@ bin/%/submariner-operator: $(VENDOR_MODULES) main.go $(EMBEDDED_YAMLS) ci: $(EMBEDDED_YAMLS) golangci-lint markdownlint unit build images -# Operator CRDs +# Download controller-gen locally if not already downloaded. +CONTROLLER_TOOLS_VERSION := 0.9.2 $(CONTROLLER_GEN): $(VENDOR_MODULES) mkdir -p $(@D) - $(GO) build -o $@ sigs.k8s.io/controller-tools/cmd/controller-gen + test -s $(CURDIR)/bin/controller-gen || $(GO) build -o $@ sigs.k8s.io/controller-tools/cmd/controller-gen + ## TODO (Jaanki) Use go install instead + # $(GO) install sigs.k8s.io/controller-tools/cmd/controller-gen@v$(CONTROLLER_TOOLS_VERSION) +controller-gen: $(CONTROLLER_GEN) + +# Operator CRDs deploy/crds/submariner.io_servicediscoveries.yaml: ./api/v1alpha1/servicediscovery_types.go $(VENDOR_MODULES) | $(CONTROLLER_GEN) $(CONTROLLER_GEN) $(CRD_OPTIONS) paths="./..." output:crd:artifacts:config=deploy/crds test -f $@ @@ -182,11 +170,13 @@ is-semantic-version: $(error 'ERROR: VERSION "$(BUNDLE_VERSION)" does not match the format required by operator-sdk.') endif -# TODO: a workaround until this issue will be fixed https://github.com/kubernetes-sigs/kustomize/issues/4008 +## Download kustomize locally if not already downloaded. +KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" $(KUSTOMIZE): mkdir -p $(@D) - #GOBIN=$(CURDIR)/bin GO111MODULE=on $(GO) get sigs.k8s.io/kustomize/kustomize/v3 - scripts/kustomize/install_kustomize.sh $(KUSTOMIZE_VERSION) $(CURDIR)/bin + test -s $(CURDIR)/bin/kustomize || { curl -s $(KUSTOMIZE_INSTALL_SCRIPT) | bash -s -- $(subst v,,$(KUSTOMIZE_VERSION)) $(CURDIR)/bin; } + +kustomize: $(KUSTOMIZE) # Generate kustomization.yaml for bundle kustomization: $(OPERATOR_SDK) $(KUSTOMIZE) is-semantic-version manifests @@ -209,16 +199,6 @@ bundle: $(KUSTOMIZE) $(OPERATOR_SDK) kustomization sed -i -e 's/$$(VERSION)/$(VERSION)/g' bundle/manifests/submariner.clusterserviceversion.yaml $(OPERATOR_SDK) bundle validate ./bundle -# Generate package manifests -packagemanifests: $(OPERATOR_SDK) $(KUSTOMIZE) kustomization - ($(KUSTOMIZE) build $(KUSTOMIZE_BASE_PATH) \ - | $(OPERATOR_SDK) generate packagemanifests -q --version $(BUNDLE_VERSION) $(PKG_MAN_OPTS)) - (cd config/bundle && $(KUSTOMIZE) edit add resource ../../packagemanifests/$(BUNDLE_VERSION)/submariner.clusterserviceversion.yaml) - $(KUSTOMIZE) build config/bundle/ --load_restrictor=LoadRestrictionsNone --output packagemanifests/$(BUNDLE_VERSION)/submariner.clusterserviceversion.yaml - sed -i -e 's/$$(SHORT_VERSION)/$(SHORT_VERSION)/g' packagemanifests/$(BUNDLE_VERSION)/submariner.clusterserviceversion.yaml - sed -i -e 's/$$(VERSION)/$(VERSION)/g' packagemanifests/$(BUNDLE_VERSION)/submariner.clusterserviceversion.yaml - mv packagemanifests/$(BUNDLE_VERSION)/submariner.clusterserviceversion.yaml packagemanifests/$(BUNDLE_VERSION)/submariner.v$(BUNDLE_VERSION).clusterserviceversion.yaml - # Statically validate the operator bundle using Scorecard. scorecard: bundle olm clusters timeout 60 bash -c "until KUBECONFIG=$(DAPPER_OUTPUT)/kubeconfigs/kind-config-cluster1 \ @@ -233,25 +213,21 @@ golangci-lint: $(EMBEDDED_YAMLS) unit: $(EMBEDDED_YAMLS) # Operator SDK -# On version bumps, the checksum will need to be updated manually. -# If necessary, the verification *keys* can be updated as follows: -# * update scripts/operator-sdk-signing-key.asc, import the relevant key, -# and export it with -# gpg --armor --export-options export-minimal --export \ -# ${fingerprint} >> scripts/operator-sdk-signing-key.asc -# (replacing ${fingerprint} with the full fingerprint); -# * to update scripts/operator-sdk-signing-keyring.gpg, run -# gpg --no-options -q --batch --no-default-keyring \ -# --output scripts/operator-sdk-signing-keyring.gpg \ -# --dearmor scripts/operator-sdk-signing-key.asc $(OPERATOR_SDK): - curl -Lo $@ "https://github.com/operator-framework/operator-sdk/releases/download/v${OPERATOR_SDK_VERSION}/operator-sdk-v${OPERATOR_SDK_VERSION}-x86_64-linux-gnu" - curl -Lo $@.asc "https://github.com/operator-framework/operator-sdk/releases/download/v${OPERATOR_SDK_VERSION}/operator-sdk-v${OPERATOR_SDK_VERSION}-x86_64-linux-gnu.asc" - gpgv --keyring scripts/operator-sdk-signing-keyring.gpg $@.asc $@ - sha256sum -c scripts/operator-sdk.sha256 + mkdir -p bin && \ + cd bin && \ + curl -Lo $@ "https://github.com/operator-framework/operator-sdk/releases/download/v${OPERATOR_SDK_VERSION}/operator-sdk_linux_amd64" && \ + curl -Lo checksums.txt.asc "https://github.com/operator-framework/operator-sdk/releases/download/v${OPERATOR_SDK_VERSION}/checksums.txt.asc" && \ + curl -Lo checksums.txt "https://github.com/operator-framework/operator-sdk/releases/download/v${OPERATOR_SDK_VERSION}/checksums.txt" \ + ## TODO (Jaanki) Add checksums + #gpg --verify checksums.txt.asc checksums.txt + #gpgv --keyring scripts/operator-sdk-signing-keyring.gpg $@.asc $@ + #sha256sum -c scripts/operator-sdk.sha256 chmod a+x $@ -.PHONY: build ci clean bundle packagemanifests kustomization is-semantic-version olm scorecard system-test +operator-sdk: $(OPERATOR_SDK) + +.PHONY: build ci clean bundle kustomization is-semantic-version olm scorecard system-test controller-gen kustomize operator-sdk else @@ -263,7 +239,7 @@ Makefile.dapper: include Makefile.dapper -.PHONY: deploy bundle packagemanifests kustomization is-semantic-version licensecheck +.PHONY: deploy bundle kustomization is-semantic-version licensecheck controller-gen kustomize operator-sdk endif diff --git a/PROJECT b/PROJECT index 53206697c..b8c57871b 100644 --- a/PROJECT +++ b/PROJECT @@ -1,8 +1,34 @@ domain: submariner.io -layout: go.kubebuilder.io/v2 -projectName: submariner -repo: github.com/submariner-io/submariner-operator -version: 3-alpha -multigroup: true +layout: +- go.kubebuilder.io/v3 plugins: - go.sdk.operatorframework.io/v2-alpha: {} + manifests.sdk.operatorframework.io/v2: {} + scorecard.sdk.operatorframework.io/v2: {} +projectName: submariner-operator +repo: github.com/submariner-io/submariner-operator +resources: +- api: + crdVersion: v1 + namespaced: true + controller: true + domain: submariner.io + kind: Broker + path: github.com/submariner-io/submariner-operator/api/v1alpha1 + version: v1alpha1 +- api: + crdVersion: v1 + namespaced: true + controller: true + domain: submariner.io + kind: Submariner + path: github.com/submariner-io/submariner-operator/api/v1alpha1 + version: v1alpha1 +- api: + crdVersion: v1 + namespaced: true + controller: true + domain: submariner.io + kind: ServiceDiscovery + path: github.com/submariner-io/submariner-operator/api/v1alpha1 + version: v1alpha1 +version: "3" diff --git a/scripts/kustomize/install_kustomize.sh b/scripts/kustomize/install_kustomize.sh deleted file mode 100755 index 382073e3a..000000000 --- a/scripts/kustomize/install_kustomize.sh +++ /dev/null @@ -1,133 +0,0 @@ -#!/usr/bin/env bash - -# If no argument is given -> Downloads the most recently released -# kustomize binary to your current working directory. -# (e.g. 'install_kustomize.sh') -# -# If one argument is given -> -# If that argument is in the format of #.#.#, downloads the specified -# version of the kustomize binary to your current working directory. -# If that argument is something else, downloads the most recently released -# kustomize binary to the specified directory. -# (e.g. 'install_kustomize.sh 3.8.2' or 'install_kustomize.sh $(go env GOPATH)/bin') -# -# If two arguments are given -> Downloads the specified version of the -# kustomize binary to the specified directory. -# (e.g. 'install_kustomize.sh 3.8.2 $(go env GOPATH)/bin') -# -# Fails if the file already exists. - -set -e - -# Unset CDPATH to restore default cd behavior. An exported CDPATH can -# cause cd to output the current directory to STDOUT. -unset CDPATH - -where=$PWD - -release_url=https://api.github.com/repos/kubernetes-sigs/kustomize/releases -if [ -n "$1" ]; then - if [[ "$1" =~ ^[0-9]+(\.[0-9]+){2}$ ]]; then - version=v$1 - release_url=${release_url}/tags/kustomize%2F$version - elif [ -n "$2" ]; then - echo "The first argument should be the requested version." - exit 1 - else - where="$1" - fi -fi - -if [ -n "$2" ]; then - where="$2" -fi - -if ! test -d "$where"; then - echo "$where does not exist. Create it first." - exit 1 -fi - -# Emulates `readlink -f` behavior, as this is not available by default on MacOS -# See: https://stackoverflow.com/questions/1055671/how-can-i-get-the-behavior-of-gnus-readlink-f-on-a-mac -function readlink_f { - TARGET_FILE=$1 - - cd "$(dirname "$TARGET_FILE")" - TARGET_FILE=$(basename "$TARGET_FILE") - - # Iterate down a (possible) chain of symlinks - while [ -L "$TARGET_FILE" ] - do - TARGET_FILE=$(readlink "$TARGET_FILE") - cd "$(dirname "$TARGET_FILE")" - TARGET_FILE=$(readlink "$TARGET_FILE") - done - - # Compute the canonicalized name by finding the physical path - # for the directory we're in and appending the target file. - PHYS_DIR=$(pwd -P) - RESULT=$PHYS_DIR/$TARGET_FILE - echo "$RESULT" -} - -where="$(readlink_f "$where")/" - -if [ -f "${where}kustomize" ]; then - echo "${where}kustomize exists. Remove it first." - exit 1 -elif [ -d "${where}kustomize" ]; then - echo "${where}kustomize exists and is a directory. Remove it first." - exit 1 -fi - -tmpDir=$(mktemp -d) -if [[ ! "$tmpDir" || ! -d "$tmpDir" ]]; then - echo "Could not create temp dir." - exit 1 -fi - -function cleanup { - rm -rf "$tmpDir" -} - -trap cleanup EXIT ERR - -pushd "$tmpDir" >& /dev/null - -opsys=windows -arch=amd64 -if [[ "$OSTYPE" == linux* ]]; then - opsys=linux -elif [[ "$OSTYPE" == darwin* ]]; then - opsys=darwin -fi - -RELEASE_URL=$(curl -s "$release_url" |\ - grep "browser_download.*${opsys}_${arch}" |\ - cut -d '"' -f 4 |\ - sort -V | tail -n 1) - -if [ -z "$RELEASE_URL" ]; then - echo "Version $version does not exist." - exit 1 -fi - -CHECKSUMS_URL=$(curl -s "$release_url" |\ - grep "browser_download.*checksums.txt" |\ - cut -d '"' -f 4 |\ - sort -V | tail -n 1) - -curl -sLO "$RELEASE_URL" -curl -sLO "$CHECKSUMS_URL" - -sha256sum --ignore-missing -c checksums.txt - -tar xzf ./kustomize_v*_${opsys}_${arch}.tar.gz - -cp ./kustomize "$where" - -popd >& /dev/null - -"${where}"kustomize version - -echo "kustomize installed to ${where}kustomize"