Skip to content

Commit

Permalink
Makefile updates to install build tools (#154)
Browse files Browse the repository at this point in the history
Repo maintenance to update methods for installing build tools, controller-gen and kustomize as the former method is no longer supported.
  • Loading branch information
lukeatdell authored Aug 15, 2024
1 parent 8c78ebf commit 2dd4e81
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 55 deletions.
61 changes: 49 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
23 changes: 0 additions & 23 deletions pkg/tools/tools.go

This file was deleted.

4 changes: 2 additions & 2 deletions test/mock-server/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions test/mock-server/stub/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down

0 comments on commit 2dd4e81

Please sign in to comment.