diff --git a/.github/workflows/manual-build.yml b/.github/workflows/manual-build.yml index e903687499..68db23a5aa 100644 --- a/.github/workflows/manual-build.yml +++ b/.github/workflows/manual-build.yml @@ -21,7 +21,7 @@ jobs: ref: ${{ github.event.inputs.branch }} - uses: actions/setup-go@v3 with: - go-version: "1.19" + go-version: "1.20" - name: Get Current Date id: date diff --git a/.github/workflows/run_admission_test.yml b/.github/workflows/run_admission_test.yml index 49c1cf668a..eca6ea2f8e 100644 --- a/.github/workflows/run_admission_test.yml +++ b/.github/workflows/run_admission_test.yml @@ -18,7 +18,7 @@ jobs: - name: Setup Go on runner uses: actions/setup-go@v3 with: - go-version: "1.19" + go-version: "1.20" - name: Set environment variables run: | diff --git a/.github/workflows/run_ci.yml b/.github/workflows/run_ci.yml index 2c64000093..84e29df41e 100644 --- a/.github/workflows/run_ci.yml +++ b/.github/workflows/run_ci.yml @@ -19,7 +19,7 @@ jobs: - uses: actions/setup-go@v2 # Could not change to version 3, see issue: # https://github.com/noobaa/noobaa-operator/issues/1031 with: - go-version: "1.19" + go-version: "1.20" - name: Deploy Dependencies id: deploy @@ -52,7 +52,7 @@ jobs: uses: actions/checkout@v3 - uses: actions/setup-go@v2 with: - go-version: "1.19" + go-version: "1.20" - name: Deploy Dependencies id: deploy @@ -81,7 +81,7 @@ jobs: uses: actions/checkout@v3 - uses: actions/setup-go@v2 with: - go-version: "1.19" + go-version: "1.20" - name: Deploy Dependencies id: deploy diff --git a/.github/workflows/run_cosi_test.yaml b/.github/workflows/run_cosi_test.yaml index cb5261553f..2fb97d5ff9 100644 --- a/.github/workflows/run_cosi_test.yaml +++ b/.github/workflows/run_cosi_test.yaml @@ -18,7 +18,7 @@ jobs: - name: Setup Go on runner uses: actions/setup-go@v3 with: - go-version: "1.19" + go-version: "1.20" - name: Set environment variables run: | diff --git a/.github/workflows/run_hac_test.yml b/.github/workflows/run_hac_test.yml index 1cb041cc46..5e11392352 100644 --- a/.github/workflows/run_hac_test.yml +++ b/.github/workflows/run_hac_test.yml @@ -13,7 +13,7 @@ jobs: uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: "1.19" + go-version: "1.20" - name: Set environment variables run: | diff --git a/.github/workflows/run_kms_dev_test.yml b/.github/workflows/run_kms_dev_test.yml index 8171468708..d729f5228d 100644 --- a/.github/workflows/run_kms_dev_test.yml +++ b/.github/workflows/run_kms_dev_test.yml @@ -13,7 +13,7 @@ jobs: uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: "1.19" + go-version: "1.20" - name: Set environment variables run: | diff --git a/.github/workflows/run_kms_ibm_kp_test.yml b/.github/workflows/run_kms_ibm_kp_test.yml index 66a4579d25..4e96bc52d5 100644 --- a/.github/workflows/run_kms_ibm_kp_test.yml +++ b/.github/workflows/run_kms_ibm_kp_test.yml @@ -16,7 +16,7 @@ jobs: uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: "1.19" + go-version: "1.20" - name: Set environment variables run: | diff --git a/.github/workflows/run_kms_kmip_test.yml b/.github/workflows/run_kms_kmip_test.yml index 0785424dc6..3ff45e459f 100644 --- a/.github/workflows/run_kms_kmip_test.yml +++ b/.github/workflows/run_kms_kmip_test.yml @@ -13,7 +13,7 @@ jobs: uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: "1.19" + go-version: "1.20" - name: Set environment variables run: | diff --git a/.github/workflows/run_kms_rotate_test.yml b/.github/workflows/run_kms_rotate_test.yml index 7d16909ab3..3abe19a82a 100644 --- a/.github/workflows/run_kms_rotate_test.yml +++ b/.github/workflows/run_kms_rotate_test.yml @@ -13,7 +13,7 @@ jobs: uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: "1.19" + go-version: "1.20" - name: Set environment variables run: | diff --git a/.github/workflows/run_kms_tls_sa_test.yml b/.github/workflows/run_kms_tls_sa_test.yml index 2fa9c034e8..2feda39ac8 100644 --- a/.github/workflows/run_kms_tls_sa_test.yml +++ b/.github/workflows/run_kms_tls_sa_test.yml @@ -13,7 +13,7 @@ jobs: uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: "1.19" + go-version: "1.20" - name: Set environment variables run: | diff --git a/.github/workflows/run_kms_tls_token_test.yml b/.github/workflows/run_kms_tls_token_test.yml index b3a6b33b2d..41d2918849 100644 --- a/.github/workflows/run_kms_tls_token_test.yml +++ b/.github/workflows/run_kms_tls_token_test.yml @@ -13,7 +13,7 @@ jobs: uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: "1.19" + go-version: "1.20" - name: Set environment variables run: | diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index a226dada14..2b73972dbd 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -13,7 +13,7 @@ jobs: uses: actions/checkout@v3 - uses: actions/setup-go@v3 with: - go-version: "1.19" + go-version: "1.20" - name: Get Current Date id: date diff --git a/Makefile b/Makefile index f79ad9200e..e1d7317eb2 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ # - git # - python3 # - minikube -# - operator-sdk +# - docker export GO111MODULE=on export GOPROXY:=https://proxy.golang.org @@ -17,6 +17,15 @@ DEV_IMAGE ?= noobaa/noobaa-operator-dev:$(VERSION) REPO ?= github.com/noobaa/noobaa-operator CATALOG_IMAGE ?= noobaa/noobaa-operator-catalog:$(VERSION) BUNDLE_IMAGE ?= noobaa/noobaa-operator-bundle:$(VERSION) +# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) +ifeq (,$(shell go env GOBIN)) +GOBIN=$(shell go env GOPATH)/bin +else +GOBIN=$(shell go env GOBIN) +endif + +CONTROLLER_GEN_VERSION=v0.12.0 +DEEPCOPY_GEN_VERSION=v0.27.0 GO_LINUX ?= GOOS=linux GOARCH=amd64 GOHOSTOS ?= $(shell go env GOHOSTOS) @@ -27,13 +36,9 @@ OLM ?= $(OUTPUT)/olm MANIFESTS ?= $(OUTPUT)/manifests obc-crd ?= required VENV ?= $(OUTPUT)/venv +CMD_MANAGER ?= cmd/manager/main.go -# OPERATOR_SDK_VERSION is for build perpuse only, the dependencies themself are -# updated to a new version as stated in the go.mod file -export OPERATOR_SDK_VERSION ?= v0.17.2 -export OPERATOR_SDK ?= build/_tools/operator-sdk-$(OPERATOR_SDK_VERSION) - -KUBECONFIG ?= build/empty-kubeconfig +export NOOBAA_OPERATOR_LOCAL ?= $(BIN)/noobaa-operator-local #------------# #- Building -# @@ -47,18 +52,21 @@ build: cli image gen-olm @echo "✅ build" .PHONY: build -cli: $(OPERATOR_SDK) gen - $(OPERATOR_SDK) run --kubeconfig="$(KUBECONFIG)" --local --operator-flags "version" +cli: gen + go build -o $(NOOBAA_OPERATOR_LOCAL) -mod=vendor $(CMD_MANAGER) + $(BIN)/noobaa-operator-local version @echo "✅ cli" .PHONY: cli -image: $(OPERATOR_SDK) gen - $(OPERATOR_SDK) build $(IMAGE) +image: $(docker) gen + go build -o $(BIN)/noobaa-operator -trimpath -mod=vendor $(CMD_MANAGER) + docker build -f build/Dockerfile -t $(IMAGE) . @echo "✅ image" .PHONY: image -dev-image: $(OPERATOR_SDK) gen - $(OPERATOR_SDK) build --go-build-args "-gcflags all=-N -gcflags all=-l" $(IMAGE) +dev-image: $(docker) gen + go build -o $(BIN)/noobaa-operator -trimpath -mod=vendor -gcflags all=-N -gcflags all=-l $(CMD_MANAGER) + docker build -f build/Dockerfile -t $(IMAGE) . docker build -f build/DockerfileDev --build-arg base_image=$(IMAGE) -t $(DEV_IMAGE) . @echo "✅ dev image" .PHONY: dev-image @@ -69,9 +77,10 @@ vendor: @echo "✅ vendor" .PHONY: vendor -run: $(OPERATOR_SDK) gen - $(OPERATOR_SDK) run --local --operator-flags "operator run" -.PHONY: run +run: gen + go build -o $(NOOBAA_OPERATOR_LOCAL) -mod=vendor $(CMD_MANAGER) + $(BIN)/noobaa-operator-local operator run + .PHONY: run clean: rm -rf $(OUTPUT) @@ -96,11 +105,6 @@ release-cli: release: release-docker release-cli .PHONY: release -$(OPERATOR_SDK): - bash build/install-operator-sdk.sh - @echo "✅ $(OPERATOR_SDK)" - - #------------# #- Generate -# #------------# @@ -113,9 +117,9 @@ pkg/bundle/deploy.go: pkg/bundler/bundler.go version/version.go $(shell find dep mkdir -p pkg/bundle go run pkg/bundler/bundler.go deploy/ pkg/bundle/deploy.go -gen-api: $(OPERATOR_SDK) gen - $(TIME) $(OPERATOR_SDK) generate k8s - $(TIME) $(OPERATOR_SDK) generate crds --crd-version v1 +gen-api: controller-gen deepcopy-gen gen + $(TIME) $(DEEPCOPY_GEN) --go-header-file="build/hack/boilerplate.go.txt" --input-dirs="./pkg/apis/noobaa/v1alpha1/..." --output-file-base="zz_generated.deepcopy" + $(TIME) $(CONTROLLER_GEN) paths=./... crd:generateEmbeddedObjectMeta=true output:crd:artifacts:config=deploy/crds/ @echo "✅ gen-api" .PHONY: gen-api @@ -127,9 +131,10 @@ gen-api-fail-if-dirty: gen-api ) .PHONY: gen-api-fail-if-dirty -gen-olm: $(OPERATOR_SDK) gen +gen-olm: gen rm -rf $(OLM) - $(OPERATOR_SDK) run --kubeconfig="$(KUBECONFIG)" --local --operator-flags "olm catalog -n my-noobaa-operator --dir $(OLM)" + go build -o $(NOOBAA_OPERATOR_LOCAL) -mod=vendor $(CMD_MANAGER) + $(NOOBAA_OPERATOR_LOCAL) olm catalog -n my-noobaa-operator --dir $(OUTPUT)/olm python3 -m venv $(VENV) && \ . $(VENV)/bin/activate && \ pip3 install --upgrade pip && \ @@ -139,7 +144,6 @@ gen-olm: $(OPERATOR_SDK) gen @echo "✅ gen-olm" .PHONY: gen-olm - gen-odf-package: cli rm -rf $(MANIFESTS) MANIFESTS="$(MANIFESTS)" CSV_NAME="$(csv-name)" SKIP_RANGE="$(skip-range)" REPLACES="$(replaces)" CORE_IMAGE="$(core-image)" DB_IMAGE="$(db-image)" OPERATOR_IMAGE="$(operator-image)" COSI_SIDECAR_IMAGE="$(cosi-sidecar-image)" OBC_CRD="$(obc-crd)" build/gen-odf-package.sh @@ -191,7 +195,7 @@ test-core-config-map-flow: .PHONY: test-core-config-map-flow # test-olm runs tests for the OLM package -test-olm: $(OPERATOR_SDK) gen-olm +test-olm: gen-olm $(TIME) ./test/test-olm.sh $(CATALOG_IMAGE) @echo "✅ test-olm" .PHONY: test-olm @@ -265,3 +269,30 @@ test-validations: ginkgo -v pkg/validations @echo "✅ test-validations" .PHONY: test-validations + +# find or download controller-gen if necessary +controller-gen: +ifneq ($(CONTROLLER_GEN_VERSION), $(shell controller-gen --version | awk -F ":" '{print $2}')) + @{ \ + echo "Installing controller-gen@$(CONTROLLER_GEN_VERSION)" ;\ + set -e ;\ + go install -mod=readonly sigs.k8s.io/controller-tools/cmd/controller-gen@$(CONTROLLER_GEN_VERSION) ;\ + echo "Installed controller-gen@$(CONTROLLER_GEN_VERSION)" ;\ + } +CONTROLLER_GEN=$(GOBIN)/controller-gen +else +CONTROLLER_GEN=$(shell which controller-gen) +endif + +deepcopy-gen: +ifneq ($(DEEPCOPY_GEN_VERSION), $(shell deepcopy-gen --version | awk -F ":" '{print $2}')) + @{ \ + echo "Installing deepcopy-gen@$(DEEPCOPY_GEN_VERSION)" ;\ + set -e ;\ + go install -mod=readonly k8s.io/code-generator/cmd/deepcopy-gen@$(DEEPCOPY_GEN_VERSION) ;\ + echo "Installed deepcopy-gen@$(DEEPCOPY_GEN_VERSION)" ;\ + } +DEEPCOPY_GEN=$(GOBIN)/deepcopy-gen +else +DEEPCOPY_GEN=$(shell which deepcopy-gen) +endif \ No newline at end of file diff --git a/build/hack/boilerplate.go.txt b/build/hack/boilerplate.go.txt new file mode 100644 index 0000000000..66d27e5b78 --- /dev/null +++ b/build/hack/boilerplate.go.txt @@ -0,0 +1,32 @@ +/* +Copyright 2021 The Noobaa authors. + +This file may be used, at your option, according to either the GNU AGPL 3.0 or +the Apache V2 license. + +--- +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU Affero General Public License as published by the Free +Software Foundation, either version 3 of the License, or (at your option) any +later version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License along +with this program. If not, see . + +--- +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ diff --git a/go.mod b/go.mod index 5d1d130290..3482e1090f 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/noobaa/noobaa-operator/v5 -go 1.19 +go 1.20 require ( cloud.google.com/go/storage v1.30.1 diff --git a/pkg/apis/noobaa/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/noobaa/v1alpha1/zz_generated.deepcopy.go index dc0a39ee6e..90f678f6bd 100644 --- a/pkg/apis/noobaa/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/noobaa/v1alpha1/zz_generated.deepcopy.go @@ -1,6 +1,40 @@ +//go:build !ignore_autogenerated // +build !ignore_autogenerated -// Code generated by operator-sdk-v0.17.2. DO NOT EDIT. +/* +Copyright 2021 The Noobaa authors. + +This file may be used, at your option, according to either the GNU AGPL 3.0 or +the Apache V2 license. + +--- +This program is free software: you can redistribute it and/or modify it under +the terms of the GNU Affero General Public License as published by the Free +Software Foundation, either version 3 of the License, or (at your option) any +later version. + +This program is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License along +with this program. If not, see . + +--- +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +// Code generated by deepcopy-gen. DO NOT EDIT. package v1alpha1 diff --git a/pkg/cli/cli.go b/pkg/cli/cli.go index 2a48e66557..390a8e3a1e 100644 --- a/pkg/cli/cli.go +++ b/pkg/cli/cli.go @@ -66,10 +66,10 @@ func Cmd() *cobra.Command { util.InitLogger(logrus.DebugLevel) - rand.Seed(time.Now().UTC().UnixNano()) + r := rand.New(rand.NewSource(time.Now().UTC().UnixNano())) logo := ASCIILogo1 - if rand.Intn(2) == 0 { // 50% chance + if r.Intn(2) == 0 { // 50% chance logo = ASCIILogo2 } diff --git a/test/test-olm.sh b/test/test-olm.sh index 4e38c352e0..6ea9f42017 100755 --- a/test/test-olm.sh +++ b/test/test-olm.sh @@ -17,13 +17,9 @@ fi CATALOG_IMAGE=$1 VERSION=$(go run cmd/version/main.go) -if [ -z "${OPERATOR_SDK}" ]; then - OPERATOR_SDK=operator-sdk -fi - function install_olm() { echo "----> Install OLM and Operator Marketplace ..." - ${OPERATOR_SDK} olm install --version 0.16.1 || true + ${NOOBAA_OPERATOR_LOCAL} olm install || true # kubectl apply -f https://github.com/operator-framework/operator-lifecycle-manager/releases/download/0.10.0/crds.yaml # kubectl apply -f https://github.com/operator-framework/operator-lifecycle-manager/releases/download/0.10.0/olm.yaml # kubectl apply -f https://github.com/operator-framework/operator-marketplace/raw/master/deploy/upstream/01_namespace.yaml @@ -69,14 +65,14 @@ function wait_for_operator() { function test_operator() { MINI_RESOURCES='{"requests":{"cpu":"10m","memory":"128Mi"}}' - ${OPERATOR_SDK} run --local --operator-flags "system create --core-resources $MINI_RESOURCES --db-resources $MINI_RESOURCES --endpoint-resources ${MINI_RESOURCES}" + ${NOOBAA_OPERATOR_LOCAL} --mini install while [ "$(kubectl get noobaa/noobaa -o jsonpath={.status.phase})" != "Ready" ] do echo -n '.' sleep 3 - ${OPERATOR_SDK} run --local --operator-flags "status" + ${NOOBAA_OPERATOR_LOCAL} status done - ${OPERATOR_SDK} run --local --operator-flags "status" + ${NOOBAA_OPERATOR_LOCAL} status } function main() {