-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ashish Amarnath <[email protected]>
- Loading branch information
1 parent
5118240
commit 8b269e1
Showing
30 changed files
with
1,689 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,111 @@ | ||
|
||
# Copyright 2020 The Kubernetes Authors. | ||
# | ||
# 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. | ||
|
||
.DEFAULT_GOAL:=help | ||
|
||
REGISTRY ?= gcr.io/$(shell gcloud config get-value project) | ||
IMAGE_NAME ?= executionhook-controller | ||
TAG ?= dev | ||
# Image URL to use all building/pushing image targets | ||
IMG ?= controller:latest | ||
CONTROLLER_IMAGE ?= $(REGISTRY)/$(IMAGE_NAME):$(TAG) | ||
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion) | ||
CRD_OPTIONS ?= "crd:trivialVersions=true" | ||
|
||
# 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 | ||
# Directories. | ||
TOOLS_DIR := hack/tools | ||
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin | ||
|
||
# Tool binaries. | ||
KUSTOMIZE := $(TOOLS_BIN_DIR)/kustomize | ||
CONTROLLER_GEN := $(TOOLS_BIN_DIR)/controller-gen | ||
|
||
$(CONTROLLER_GEN): $(TOOLS_DIR)/go.mod | ||
cd $(TOOLS_DIR); go build -tags=tools -o ./bin/controller-gen sigs.k8s.io/controller-tools/cmd/controller-gen | ||
|
||
$(KUSTOMIZE): $(TOOLS_DIR)/go.mod | ||
cd $(TOOLS_DIR); go build -tags=tools -o ./bin/kustomize sigs.k8s.io/kustomize/kustomize/v3 | ||
|
||
.PHONY: help | ||
help: ## Display this help | ||
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) | ||
|
||
.PHONY: clean-bin | ||
clean-bin: ## Remove all generated binaries | ||
rm -rf bin | ||
rm -rf hack/tools/bin | ||
|
||
.PHONY: all | ||
all: manager | ||
|
||
# Run tests | ||
test: generate fmt vet manifests | ||
go test ./... -coverprofile cover.out | ||
.PHONY: test | ||
test: generate fmt vet manifests ## Run tests | ||
go test -v ./... -coverprofile cover.out | ||
|
||
# Build manager binary | ||
manager: generate fmt vet | ||
.PHONY: manager | ||
manager: generate fmt vet test ## Build manager binary | ||
go build -o bin/manager main.go | ||
|
||
# Run against the configured Kubernetes cluster in ~/.kube/config | ||
run: generate fmt vet manifests | ||
go run ./main.go | ||
|
||
# Install CRDs into a cluster | ||
install: manifests | ||
kustomize build config/crd | kubectl apply -f - | ||
.PHONY: install | ||
install: manifests $(KUSTOMIZE) ## Install CRDs into a cluster in the current context at ~/.kube/config | ||
$(KUSTOMIZE) build config/crd | kubectl apply -f - | ||
|
||
# Uninstall CRDs from a cluster | ||
uninstall: manifests | ||
kustomize build config/crd | kubectl delete -f - | ||
.PHONY: uninstall | ||
uninstall: manifests $(KUSTOMIZE) ## Uninstall latest version of CRDs from a cluster in the current context at ~/.kube/config | ||
$(KUSTOMIZE) build config/crd | kubectl delete -f - | ||
|
||
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config | ||
deploy: manifests | ||
cd config/manager && kustomize edit set image controller=${IMG} | ||
kustomize build config/default | kubectl apply -f - | ||
.PHONY: deploy | ||
# hacky, works for now. TODO: ashish-amarnath make this better | ||
deploy: manifests $(KUSTOMIZE) ## Deploy controller in the configured Kubernetes cluster in ~/.kube/config | ||
cd config/manager && ../../$(KUSTOMIZE) edit set image controller=${CONTROLLER_IMAGE} | ||
$(KUSTOMIZE) build config/default | kubectl apply -f - | ||
|
||
# Generate manifests e.g. CRD, RBAC etc. | ||
manifests: controller-gen | ||
.PHONY: manifests | ||
manifests: $(CONTROLLER_GEN) ## Generate manifests e.g. CRD, RBAC etc. | ||
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases | ||
|
||
# Run go fmt against code | ||
fmt: | ||
fmt: ## Run go fmt against code | ||
go fmt ./... | ||
|
||
# Run go vet against code | ||
vet: | ||
vet: ## Run go vet against code | ||
go vet ./... | ||
|
||
# Generate code | ||
generate: controller-gen | ||
.PHONY: modules | ||
modules: ## Runs go mod to ensure modules are up-to-date. | ||
go mod tidy | ||
cd $(TOOLS_DIR); go mod tidy | ||
|
||
.PHONY: verify-modules | ||
verify-modules: modules | ||
@if !(git diff --quiet HEAD -- go.sum go.mod hack/tools/go.mod hack/tools/go.sum); then \ | ||
echo "go module files are out of date"; exit 1; \ | ||
fi | ||
|
||
generate: $(CONTROLLER_GEN) ## Generate code | ||
$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths="./..." | ||
|
||
# Build the docker image | ||
docker-build: test | ||
docker build . -t ${IMG} | ||
|
||
# Push the docker image | ||
docker-push: | ||
docker push ${IMG} | ||
|
||
# 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 get sigs.k8s.io/controller-tools/cmd/[email protected] ;\ | ||
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\ | ||
} | ||
CONTROLLER_GEN=$(GOBIN)/controller-gen | ||
else | ||
CONTROLLER_GEN=$(shell which controller-gen) | ||
endif | ||
|
||
.PHONY: verify-gen | ||
verify-gen: generate manifests | ||
@if !(git diff --quiet HEAD); then \ | ||
echo "generated code and manifest files are out of date, run make generate manifests"; exit 1; \ | ||
fi | ||
|
||
.PHONY: docker-build | ||
docker-build: test # Build the controller image | ||
docker build . -t ${CONTROLLER_IMAGE} | ||
|
||
.PHONY: docker-push | ||
docker-push: docker-build # Push the controller image | ||
docker push ${CONTROLLER_IMAGE} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.