Skip to content

Commit

Permalink
Remove operator-sdk dependency
Browse files Browse the repository at this point in the history
list of changes:
Replaced operator-sdk command to generate
1. crds with controller-gen cmd to align with go1.20
2. noobaa-operator and noobaa-operator-local directly with go build cmds
3. noobaa images with docker cmd

Signed-off-by: Vinayakswami Hariharmath <[email protected]>
  • Loading branch information
vh05 authored and Vh1 committed Jul 26, 2023
1 parent 2e79ce0 commit fa37576
Show file tree
Hide file tree
Showing 18 changed files with 147 additions and 54 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/manual-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run_admission_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/run_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run_cosi_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run_hac_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run_kms_dev_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run_kms_ibm_kp_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run_kms_kmip_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run_kms_rotate_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run_kms_tls_sa_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run_kms_tls_token_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
87 changes: 59 additions & 28 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# - git
# - python3
# - minikube
# - operator-sdk
# - docker

export GO111MODULE=on
export GOPROXY:=https://proxy.golang.org
Expand All @@ -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)
Expand All @@ -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 -#
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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 -#
#------------#
Expand All @@ -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

Expand All @@ -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 && \
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
32 changes: 32 additions & 0 deletions build/hack/boilerplate.go.txt
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.

---
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.
*/
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
36 changes: 35 additions & 1 deletion pkg/apis/noobaa/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Loading

0 comments on commit fa37576

Please sign in to comment.