Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use make targets to install binary dependencies #3477

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .envrc

This file was deleted.

69 changes: 35 additions & 34 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,47 @@ help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

##@ Development
BIN_PATH = $(shell pwd)/bin
export GOBIN = $(shell pwd)/bin
export PATH := $(shell pwd)/bin:$(PATH)

CONTROLLERS=controllers job-task-runner kpack-image-builder statefulset-runner
COMPONENTS=api $(CONTROLLERS)

manifests: install-controller-gen
$(CONTROLLER_GEN) \
manifests: bin/controller-gen
controller-gen \
paths="./model/..." \
crd \
output:crd:artifacts:config=helm/korifi/controllers/crds
@for comp in $(COMPONENTS); do make -C $$comp manifests; done

generate: install-controller-gen
$(CONTROLLER_GEN) object:headerFile="controllers/hack/boilerplate.go.txt" paths="./model/..."
generate: bin/controller-gen
controller-gen object:headerFile="controllers/hack/boilerplate.go.txt" paths="./model/..."
@for comp in $(CONTROLLERS); do make -C $$comp generate; done
go run ./scripts/helmdoc/main.go > README.helm.md

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
install-controller-gen:
GOBIN=$(shell pwd)/bin go install sigs.k8s.io/controller-tools/cmd/controller-gen
bin/controller-gen: bin
go install sigs.k8s.io/controller-tools/cmd/controller-gen

generate-fakes:
go generate ./...

fmt: install-gofumpt install-shfmt
$(GOFUMPT) -w .
$(SHFMT) -f . | grep -v '^tests/vendor' | xargs $(SHFMT) -w -i 2 -ci
fmt: bin/gofumpt bin/shfmt
gofumpt -w .
shfmt -f . | grep -v '^tests/vendor' | xargs shfmt -w -i 2 -ci

vet: ## Run go vet against code.
go vet ./...

lint: fmt vet gosec staticcheck golangci-lint

gosec: install-gosec
$(GOSEC) --exclude=G101,G304,G401,G404,G505 --exclude-dir=tests ./...
gosec: bin/gosec
gosec --exclude=G101,G304,G401,G404,G505 --exclude-dir=tests ./...

staticcheck: install-staticcheck
$(STATICCHECK) ./...
staticcheck: bin/staticcheck
staticcheck ./...

golangci-lint: install-golangci-lint
$(GOLANGCILINT) run
golangci-lint: bin/golangci-lint
golangci-lint run

test: lint
@for comp in $(COMPONENTS); do make -C $$comp test; done
Expand All @@ -87,37 +86,39 @@ build-dorifi:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -C tests/assets/dorifi-golang -o ../multi-process/dorifi .
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -C tests/assets/sample-broker-golang -o ../sample-broker/sample-broker .

GOFUMPT = $(shell go env GOPATH)/bin/gofumpt
install-gofumpt:
bin:
mkdir -p bin

bin/gofumpt:
go install mvdan.cc/gofumpt@latest

SHFMT = $(shell go env GOPATH)/bin/shfmt
install-shfmt:
bin/shfmt:
go install mvdan.cc/sh/v3/cmd/shfmt@latest

VENDIR = $(shell go env GOPATH)/bin/vendir
install-vendir:
bin/vendir:
go install carvel.dev/vendir/cmd/vendir@latest

GOSEC = $(shell go env GOPATH)/bin/gosec
install-gosec:
bin/gosec:
go install github.com/securego/gosec/v2/cmd/gosec@latest

STATICCHECK = $(shell go env GOPATH)/bin/staticcheck
install-staticcheck:
bin/staticcheck:
go install honnef.co/go/tools/cmd/staticcheck@latest

GOLANGCILINT = $(shell go env GOPATH)/bin/golangci-lint
install-golangci-lint:
bin/golangci-lint:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest

bin/cf:
mkdir -p $(BIN_PATH)
mkdir -p $(GOBIN)
curl -fsSL "https://packages.cloudfoundry.org/stable?release=linux64-binary&version=v8&source=github" \
| tar -zx cf8 \
&& mv cf8 $(BIN_PATH)/cf \
&& chmod +x $(BIN_PATH)/cf
&& mv cf8 $(GOBIN)/cf \
&& chmod +x $(GOBIN)/cf

bin/yq: bin
go install github.com/mikefarah/yq/v4@latest

bin/setup-envtest: bin
go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest

vendir-update-dependencies: install-vendir
$(VENDIR) sync --chdir tests
vendir-update-dependencies: bin/vendir
vendir sync --chdir tests
32 changes: 13 additions & 19 deletions api/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
# 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

# Use gsed on Mac, sed on linux
ifeq (,$(shell which gsed))
SED=sed
Expand Down Expand Up @@ -35,25 +28,26 @@ help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

##@ Development
export GOBIN = $(shell pwd)/bin
export PATH := $(shell pwd)/bin:$(PATH)

manifests: install-controller-gen install-yq
$(CONTROLLER_GEN) \
manifests: bin/controller-gen bin/yq
controller-gen \
paths=./... \
output:rbac:artifacts:config=../helm/korifi/api \
rbac:roleName=korifi-api-system-role

$(YQ) -i 'with(.metadata | select(.namespace == "ROOT_NAMESPACE"); .namespace="{{ .Values.rootNamespace }}")' ../helm/korifi/api/role.yaml
yq -i 'with(.metadata | select(.namespace == "ROOT_NAMESPACE"); .namespace="{{ .Values.rootNamespace }}")' ../helm/korifi/api/role.yaml


test: install-ginkgo
test:
../scripts/run-tests.sh --skip-package=test

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
install-controller-gen:
GOBIN=$(shell pwd)/bin go install sigs.k8s.io/controller-tools/cmd/controller-gen
bin:
mkdir -p bin

install-ginkgo:
go install github.com/onsi/ginkgo/v2/ginkgo
bin/controller-gen: bin
go install sigs.k8s.io/controller-tools/cmd/controller-gen

YQ = $(shell pwd)/bin/yq
install-yq:
GOBIN=$(shell pwd)/bin go install github.com/mikefarah/yq/v4@latest
bin/yq: bin
go install github.com/mikefarah/yq/v4@latest
42 changes: 18 additions & 24 deletions controllers/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ ifdef GINKGO_NODES
CONTROLLERS_GINKGO_NODES = $(GINKGO_NODES)
endif

# 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

# Setting SHELL to bash allows bash commands to be executed by recipes.
# This is a requirement for 'setup-envtest.sh' in the test target.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
Expand All @@ -35,10 +28,12 @@ help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

##@ Development
export GOBIN = $(shell pwd)/bin
export PATH := $(shell pwd)/bin:$(PATH)

webhooks-file = ../helm/korifi/controllers/manifests.yaml
manifests: install-controller-gen install-yq
$(CONTROLLER_GEN) \
manifests: bin/controller-gen bin/yq
controller-gen \
paths="./..." \
crd \
rbac:roleName=korifi-controllers-manager-role \
Expand All @@ -47,24 +42,23 @@ manifests: install-controller-gen install-yq
output:rbac:artifacts:config=../helm/korifi/controllers \
output:webhook:artifacts:config=../helm/korifi/controllers

$(YQ) -i 'with(.metadata; .annotations["cert-manager.io/inject-ca-from"]="{{ .Release.Namespace }}/korifi-controllers-serving-cert")' $(webhooks-file)
$(YQ) -i 'with(.metadata; .name="korifi-controllers-" + .name)' $(webhooks-file)
$(YQ) -i 'with(.webhooks[]; .clientConfig.service.namespace="{{ .Release.Namespace }}")' $(webhooks-file)
$(YQ) -i 'with(.webhooks[]; .clientConfig.service.name="korifi-controllers-" + .clientConfig.service.name)' $(webhooks-file)
yq -i 'with(.metadata; .annotations["cert-manager.io/inject-ca-from"]="{{ .Release.Namespace }}/korifi-controllers-serving-cert")' $(webhooks-file)
yq -i 'with(.metadata; .name="korifi-controllers-" + .name)' $(webhooks-file)
yq -i 'with(.webhooks[]; .clientConfig.service.namespace="{{ .Release.Namespace }}")' $(webhooks-file)
yq -i 'with(.webhooks[]; .clientConfig.service.name="korifi-controllers-" + .clientConfig.service.name)' $(webhooks-file)

generate: install-controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
generate: bin/controller-gen
controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."

test: install-ginkgo manifests generate ## Run tests.
test: manifests generate
GINKGO_NODES=$(CONTROLLERS_GINKGO_NODES) ../scripts/run-tests.sh

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
install-controller-gen:
GOBIN=$(shell pwd)/bin go install sigs.k8s.io/controller-tools/cmd/controller-gen
bin:
mkdir -p bin

bin/controller-gen: bin
go install sigs.k8s.io/controller-tools/cmd/controller-gen

install-ginkgo:
go install github.com/onsi/ginkgo/v2/ginkgo
bin/yq: bin
go install github.com/mikefarah/yq/v4@latest

YQ = $(shell pwd)/bin/yq
install-yq:
GOBIN=$(shell pwd)/bin go install github.com/mikefarah/yq/v4@latest
33 changes: 12 additions & 21 deletions job-task-runner/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,12 @@ IMG_JTR ?= cloudfoundry/korifi-job-task-runner:latest
ENVTEST_K8S_VERSION = 1.24.1
CLUSTER_NAME ?= "e2e"

# 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

# Setting SHELL to bash allows bash commands to be executed by recipes.
# This is a requirement for 'setup-envtest.sh' in the test target.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

.PHONY: all
all: build

##@ General

# The help target prints out all targets with their descriptions organized
Expand All @@ -39,26 +29,27 @@ help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

##@ Development
export GOBIN = $(shell pwd)/bin
export PATH := $(shell pwd)/bin:$(PATH)

.PHONY: manifests
manifests: install-controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) \
manifests: bin/controller-gen
controller-gen \
paths="./..." \
rbac:roleName=korifi-job-task-runner-taskworkload-manager-role \
output:rbac:artifacts:config=../helm/korifi/job-task-runner

.PHONY: generate
generate: install-controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
generate: bin/controller-gen
controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."

.PHONY: test
test: install-ginkgo manifests generate ## Run tests.
test: manifests generate
../scripts/run-tests.sh

##@ Build Dependencies
.PHONY: install-controller-gen
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
install-controller-gen:
GOBIN=$(shell pwd)/bin go install sigs.k8s.io/controller-tools/cmd/controller-gen
bin:
mkdir -p bin

install-ginkgo:
go install github.com/onsi/ginkgo/v2/ginkgo
bin/controller-gen: bin
go install sigs.k8s.io/controller-tools/cmd/controller-gen
47 changes: 18 additions & 29 deletions kpack-image-builder/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,12 @@ IMG_KIB ?= cloudfoundry/korifi-kpack-image-builder:latest
ENVTEST_K8S_VERSION = 1.23
CLUSTER_NAME ?= "e2e"

# 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

# Setting SHELL to bash allows bash commands to be executed by recipes.
# This is a requirement for 'setup-envtest.sh' in the test target.
# Options are set to exit when a recipe line exits non-zero or a piped command fails.
SHELL = /usr/bin/env bash -o pipefail
.SHELLFLAGS = -ec

.PHONY: all
all: build

##@ General

# The help target prints out all targets with their descriptions organized
Expand All @@ -38,42 +28,41 @@ help: ## Display this help.
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)

##@ Development
export GOBIN = $(shell pwd)/bin
export PATH := $(shell pwd)/bin:$(PATH)

.PHONY: manifests
manifests: install-controller-gen install-yq
manifests: bin/controller-gen bin/yq
webhooks-file = ../helm/korifi/kpack-image-builder/manifests.yaml
manifests: install-controller-gen
$(CONTROLLER_GEN) \
manifests: bin/controller-gen
controller-gen \
paths="./..." \
rbac:roleName=korifi-kpack-build-manager-role \
webhook \
output:rbac:artifacts:config=../helm/korifi/kpack-image-builder \
output:webhook:artifacts:config=../helm/korifi/kpack-image-builder

$(YQ) -i 'with(.metadata; .annotations["cert-manager.io/inject-ca-from"]="{{ .Release.Namespace }}/korifi-controllers-serving-cert")' $(webhooks-file)
$(YQ) -i 'with(.metadata; .name="korifi-kpack-image-builder-" + .name)' $(webhooks-file)
$(YQ) -i 'with(.webhooks[]; .clientConfig.service.namespace="{{ .Release.Namespace }}")' $(webhooks-file)
$(YQ) -i 'with(.webhooks[]; .clientConfig.service.name="korifi-controllers-" + .clientConfig.service.name)' $(webhooks-file)
yq -i 'with(.metadata; .annotations["cert-manager.io/inject-ca-from"]="{{ .Release.Namespace }}/korifi-controllers-serving-cert")' $(webhooks-file)
yq -i 'with(.metadata; .name="korifi-kpack-image-builder-" + .name)' $(webhooks-file)
yq -i 'with(.webhooks[]; .clientConfig.service.namespace="{{ .Release.Namespace }}")' $(webhooks-file)
yq -i 'with(.webhooks[]; .clientConfig.service.name="korifi-controllers-" + .clientConfig.service.name)' $(webhooks-file)




.PHONY: generate
generate: install-controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
generate: bin/controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."

.PHONY: test
test: install-ginkgo manifests generate ## Run tests.
test: manifests generate
../scripts/run-tests.sh

.PHONY: install-controller-gen
CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
install-controller-gen:
GOBIN=$(shell pwd)/bin go install sigs.k8s.io/controller-tools/cmd/controller-gen
bin:
mkdir -p bin

install-ginkgo:
go install github.com/onsi/ginkgo/v2/ginkgo
bin/controller-gen: bin
go install sigs.k8s.io/controller-tools/cmd/controller-gen

YQ = $(shell pwd)/bin/yq
install-yq:
GOBIN=$(shell pwd)/bin go install github.com/mikefarah/yq/v4@latest
bin/yq: bin
go install github.com/mikefarah/yq/v4@latest
Loading
Loading