diff --git a/Makefile b/Makefile index 0cb14109..2bc07472 100644 --- a/Makefile +++ b/Makefile @@ -6,8 +6,8 @@ GOBIN=$(shell go env GOBIN) endif # Take tools from GOBIN -CONTROLLER_GEN=$(GOBIN)/controller-gen -KUSTOMIZE=$(GOBIN)/kustomize +CONTROLLER_GEN ?= $(GOBIN)/controller-gen +KUSTOMIZE ?= $(GOBIN)/kustomize IMG ?= "NOIMG" @@ -21,16 +21,18 @@ test: generate fmt vet static-crd gen-semver go test ./... -coverprofile cover.out # Build manager binary for csi-replicator -sidecar-manager: pre +build-sidecar-manager: pre CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/dell-csi-replicator cmd/csi-replicator/main.go -sidecar-migrator: pre +build-sidecar-migrator: pre CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/dell-csi-migrator cmd/csi-migrator/main.go # Build manager binary for csi-node re scanner -sidecar-node-rescanner: pre +build-sidecar-node-rescanner: pre CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/dell-csi-node-rescanner cmd/csi-node-rescanner/main.go # Build manager binary for replication-controller -controller-manager: pre +build-controller-manager: pre CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o bin/dell-replication-controller cmd/replication-controller/main.go +# Build all binaries for replication +build: build-sidecar-manager build-sidecar-migrator build-sidecar-node-rescanner build-controller-manager # Run against the configured Kubernetes cluster in ~/.kube/config run-sidecar: pre static-crd @@ -99,8 +101,7 @@ vet: gen-semver go vet ./... # Install Go tools to build the code -tools: - go list -f '{{range .Imports}}{{.}} {{end}}' pkg/tools/tools.go | xargs go install +tools: controller-gen kustomize # Generate code generate: tools @@ -143,16 +144,16 @@ images: gen-semver images-push: gen-semver make -f image.mk images-push -image-sidecar-dev: sidecar-manager +image-sidecar-dev: build-sidecar-manager make -f image.mk sidecar-dev -image-controller-dev: controller-manager +image-controller-dev: build-controller-manager make -f image.mk controller-dev -image-migrator-dev: sidecar-migrator +image-migrator-dev: build-sidecar-migrator make -f image.mk sidecar-migrator-dev -image-node-rescanner-dev: sidecar-node-rescanner +image-node-rescanner-dev: build-sidecar-node-rescanner make -f image.mk sidecar-node-rescanner-dev #To start mock-grpc server start-server-win: @@ -185,3 +186,39 @@ gen-coverage-replication-controller: #To generate coverage for all the controllers gen-coverage: ( cd controllers; go clean -cache; go test -race -v -cover ./... -coverprofile cover.out ) + +## Tool Versions +KUSTOMIZE_VERSION ?= v5.4.3 +CONTROLLER_TOOLS_VERSION ?= v0.15.0 + +# find or download controller-gen +# download controller-gen if necessary +controller-gen: +ifeq (, $(shell which controller-gen)) + @{ \ + set -e ;\ + CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\ + cd $$CONTROLLER_GEN_TMP_DIR ;\ + go mod init tmp ;\ + go install sigs.k8s.io/controller-tools/cmd/controller-gen@${CONTROLLER_TOOLS_VERSION} ;\ + rm -rf $$CONTROLLER_GEN_TMP_DIR ;\ + } +CONTROLLER_GEN=$(GOBIN)/controller-gen +else +CONTROLLER_GEN=$(shell which controller-gen) +endif + +kustomize: +ifeq (, $(shell which kustomize)) + @{ \ + set -e ;\ + KUSTOMIZE_TMP_DIR=$$(mktemp -d) ;\ + cd $$KUSTOMIZE_TMP_DIR ;\ + go mod init tmp ;\ + GO111MODULE=on go install sigs.k8s.io/kustomize/kustomize/v5@${KUSTOMIZE_VERSION} ;\ + rm -rf $$KUSTOMIZE_TMP_DIR ;\ + } +KUSTOMIZE=$(GOBIN)/kustomize +else +KUSTOMIZE=$(shell which kustomize) +endif diff --git a/README.md b/README.md index 604042fd..314fa07c 100644 --- a/README.md +++ b/README.md @@ -62,26 +62,30 @@ This project contains multiple go modules, and you can build multiple binaries & This project relies on the following tools which have to be installed in order to generate certain manifests. -| Tool | Version | -| --------- | ----------- | -| controller-gen | v0.4.1 | -| kustomize | v3.10.0 | +| Tool | Version | +| ----------------- | ------------ | +| controller-gen | v0.15.0 | +| kustomize | v5.4.3 | The above tools can also be installed by running the command `make tools`. ### Custom Resource Definitions -Run the command `make manifests` to build the CSM Replication CRDs. This command invokes `controller-gen` to generate the CRDs. +Run the command `make manifests` to build the CSM Replication Custom Resource Definitions (CRDs). This command invokes `controller-gen` to generate the CRDs. The API code is annotated with `kubebuilder` tags which are used by the `controller-gen` generators. The generated definitions are present in the form of a _kustomize_ recipe in the `config/crd` folder. ### Binaries +To build all the binaries associated with CSM Replication, run `make build`. -For building the CSM Replication sidecar, _dell-csi-replicator_, run `make sidecar-manager`. - -For building the CSM Replication Controller, _dell-replication-controller_, run `make controller-manager`. +To compile individual binaries run: +- `make build-controller-manager` to build the CSM Replication Controller, _dell-replication-controller_. +- `make build-sidecar-manager` to build the CSM Replication sidecar, _dell-csi-replicator_. +- `make build-sidecar-migrator` to build the CSM Replication sidecar, _dell-csi-migrator_. +- `make build-sidecar-node-rescanner` to build the CSM Replication sidecar, _dell-csi-node-rescanner_. -For building the repctl binary, run `cd repctl && make build`. +#### Repctl +To build the repctl binary, run `cd repctl && make build`. ### Static manifests diff --git a/controllers/csi-replicator/dellcsireplicationgroup_controller.go b/controllers/csi-replicator/dellcsireplicationgroup_controller.go index 9312153a..43a2c030 100644 --- a/controllers/csi-replicator/dellcsireplicationgroup_controller.go +++ b/controllers/csi-replicator/dellcsireplicationgroup_controller.go @@ -170,7 +170,7 @@ func getActionResultFromActionAnnotation(ctx context.Context, actionAnnotation A finalError := false if actionAnnotation.FinalError != "" { log.V(common.InfoLevel).Info("There is final error", "actionAnnotation.FinalError", actionAnnotation.FinalError) - finalErr = fmt.Errorf(actionAnnotation.FinalError) + finalErr = fmt.Errorf("%s", actionAnnotation.FinalError) finalError = true } diff --git a/controllers/csi-replicator/dellcsireplicationgroup_controller_test.go b/controllers/csi-replicator/dellcsireplicationgroup_controller_test.go index 1b765ade..a3f3d1e0 100644 --- a/controllers/csi-replicator/dellcsireplicationgroup_controller_test.go +++ b/controllers/csi-replicator/dellcsireplicationgroup_controller_test.go @@ -395,7 +395,7 @@ func (suite *RGControllerTestSuite) TestDeleteWithErrors() { // Inject temporary error errorMsg := fmt.Sprintf("error during delete") - suite.repClient.InjectErrorClearAfterN(fmt.Errorf(errorMsg), 5) + suite.repClient.InjectErrorClearAfterN(fmt.Errorf("%s", errorMsg), 5) for i := 0; i < 5; i++ { _, err := suite.rgReconcile.Reconcile(context.Background(), req) @@ -429,7 +429,7 @@ func (suite *RGControllerTestSuite) TestDeleteWithPersistentError() { // Inject error which doesn't clear errorMsg := fmt.Sprintf("error during delete") - suite.repClient.InjectError(fmt.Errorf(errorMsg)) + suite.repClient.InjectError(fmt.Errorf("%s", errorMsg)) defer suite.repClient.ClearErrorAndCondition(true) // Reconcile a few times @@ -459,7 +459,7 @@ func (suite *RGControllerTestSuite) TestDeleteWithFinalError() { // Inject temporary error errorMsg := fmt.Sprintf("error during delete") - suite.repClient.InjectErrorAutoClear(fmt.Errorf(errorMsg)) + suite.repClient.InjectErrorAutoClear(fmt.Errorf("%s", errorMsg)) _, err = suite.rgReconcile.Reconcile(context.Background(), req) suite.EqualError(err, errorMsg, "error should match injected error") diff --git a/controllers/csi-replicator/persistentvolume_controller_test.go b/controllers/csi-replicator/persistentvolume_controller_test.go index 1a701bea..a198eebf 100644 --- a/controllers/csi-replicator/persistentvolume_controller_test.go +++ b/controllers/csi-replicator/persistentvolume_controller_test.go @@ -129,7 +129,7 @@ func (suite *PersistentVolumeControllerTestSuite) TestPVReconcileWithTransientEr // Inject temporary error errorMsg := "failed to create storage protection group" - suite.repClient.InjectErrorAutoClear(fmt.Errorf(errorMsg)) + suite.repClient.InjectErrorAutoClear(fmt.Errorf("%s", errorMsg)) _, err = suite.reconciler.Reconcile(context.Background(), req) suite.EqualError(err, errorMsg) diff --git a/go.mod b/go.mod index fd98a721..0e85a5cb 100644 --- a/go.mod +++ b/go.mod @@ -29,8 +29,6 @@ require ( k8s.io/apimachinery v0.26.4 k8s.io/client-go v0.26.4 sigs.k8s.io/controller-runtime v0.14.6 - sigs.k8s.io/controller-tools v0.9.2 - sigs.k8s.io/kustomize/kustomize/v3 v3.10.0 ) require ( diff --git a/pkg/tools/tools.go b/pkg/tools/tools.go deleted file mode 100644 index 39fb8466..00000000 --- a/pkg/tools/tools.go +++ /dev/null @@ -1,23 +0,0 @@ -//go:build tools -// +build tools - -/* - Copyright © 2021-2022 Dell Inc. or its subsidiaries. All Rights Reserved. - - 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. -*/ - -package tools - -import ( - _ "sigs.k8s.io/controller-tools/cmd/controller-gen" - _ "sigs.k8s.io/kustomize/kustomize/v3" -) diff --git a/test/mock-server/server/server.go b/test/mock-server/server/server.go index 55283124..d019ebcb 100644 --- a/test/mock-server/server/server.go +++ b/test/mock-server/server/server.go @@ -188,7 +188,7 @@ func FindStub(service, method string, in, out interface{}) error { if resp.StatusCode != http.StatusOK { body, _ := io.ReadAll(resp.Body) - return fmt.Errorf(string(body)) + return fmt.Errorf("%s", string(body)) } respRPC := new(response) @@ -198,7 +198,7 @@ func FindStub(service, method string, in, out interface{}) error { } if respRPC.Error != "" { - return fmt.Errorf(respRPC.Error) + return fmt.Errorf("%s", respRPC.Error) } data, _ := json.Marshal(respRPC.Data) diff --git a/test/mock-server/stub/storage.go b/test/mock-server/stub/storage.go index a4f8b016..4db695ea 100644 --- a/test/mock-server/stub/storage.go +++ b/test/mock-server/stub/storage.go @@ -117,7 +117,7 @@ func stubNotFoundError(stub *findStubPayload, closestMatches []closeMatch) error template += expectString if len(closestMatches) == 0 { - return fmt.Errorf(template) + return fmt.Errorf("%s", template) } highestRank := struct { @@ -144,7 +144,7 @@ func stubNotFoundError(stub *findStubPayload, closestMatches []closeMatch) error closestMatchString := renderFieldAsString(closestMatch.expect) template += fmt.Sprintf("\n\nClosest Match \n\n%s:%s", closestMatch.rule, closestMatchString) - return fmt.Errorf(template) + return fmt.Errorf("%s", template) } // we made our own simple ranking logic