-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathMakefile
138 lines (111 loc) · 4.9 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#
ifndef DEFAULT_BUILDX_BUILDER
DEFAULT_BUILDX_BUILDER=default
endif
# Image URL to use all building/pushing image targets
DEFAULT_IMG_REGISTRY=us-docker.pkg.dev
DEFAULT_IMG_REPOSITORY=forgeops-public/images
ifndef DEFAULT_IMG_TAG
DEFAULT_IMG_TAG=latest
endif
IMG ?= controller:${DEFAULT_IMG_TAG}
# Uncomment below for deploying to a external cluster
# IMG=${DEFAULT_IMG_REGISTRY}/${DEFAULT_IMG_REPOSITORY}/controller:${DEFAULT_IMG_TAG}
VERSION=$(shell echo $(IMG) | awk -F ':' '{print $$2}')
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
#CRD_OPTIONS ?= "crd:trivialVersions=false"
# This will work on kube versions 1.16+. We want the CRD OpenAPI validation features in v1
CRD_OPTIONS ?= "crd:crdVersions=v1"
# if GOBIN isn't set find the path, otherwise use GOBIN
ifeq ($(GOBIN),)
GOBIN=$(shell go env GOPATH)/bin
endif
GO=$(shell go env GOROOT)/bin/go
# 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
all: manager
# Run unit and integration tests (backwards compatability)
citest: int-test
git config --global --add safe.directory /root/go/src/github.com/ForgeRock/secret-agent
git status --untracked-files=no --porcelain
if [ -n "$(shell git status --untracked-files=no --porcelain)" ]; then echo "There are uncommitted changes"; false; fi
echo "Test successful"
# Run unit tests
unit-test: setup-test generate fmt vet manifests
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; setup_envtest_env $(ENVTEST_ASSETS_DIR); $(GO) test ./... -coverprofile cover.html
# Run unit and integration tests
ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
setup-test: manifests generate fmt vet ## Run tests.
mkdir -p ${ENVTEST_ASSETS_DIR}
test -f ${ENVTEST_ASSETS_DIR}/setup-envtest.sh || curl -sSLo ${ENVTEST_ASSETS_DIR}/setup-envtest.sh https://raw.githubusercontent.com/kubernetes-sigs/controller-runtime/v0.8.3/hack/setup-envtest.sh
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; fetch_envtest_tools $(ENVTEST_ASSETS_DIR);
int-test: setup-test
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; setup_envtest_env $(ENVTEST_ASSETS_DIR); $(GO) test ./... -tags=intregration -coverprofile cover.out
# Run unit and integration and cloudprovider tests
cloud-test: set-test generate fmt vet manifests
source ${ENVTEST_ASSETS_DIR}/setup-envtest.sh; setup_envtest_env $(ENVTEST_ASSETS_DIR); $(GO) test ./... -tags=integration,cloudprovider -coverprofile cover.html
unit-test-local:
mkdir -p .coverage && \
go test ./... -timeout 30s -v -mod=readonly -race -coverprofile=.coverage/out -tags='!cloudprovider,!integration' > .coverage/test-out
show_coverage: unit-test-local
go tool cover -html=.coverage/out
# Build manager binary
manager: generate fmt vet
$(GO) build -o bin/manager main.go
# debug
debug: generate fmt vet manifests
dlv debug -- ./main.$(GO) --debug
# Run against the configured Kubernetes cluster in ~/.kube/config
run: generate fmt vet manifests
ENABLE_WEBHOOKS=false $(GO) run ./main.go
# Install CRDs into a cluster
install: manifests
kustomize build config/crd | kubectl apply -f -
# Uninstall CRDs from a cluster
uninstall: manifests
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 -
# Delete controller from the configured Kubernetes cluster in ~/.kube/config
clean: manifests
kustomize build config/default | kubectl delete -f -
# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
# Remove "caBuncle: Cg==" from the webhook config. controller-gen generates the manifests with a placeholder
awk '!/caBundle:/' config/webhook/manifests.yaml > t && mv t config/webhook/manifests.yaml
# Run $(GO) fmt against code
fmt:
$(GO) fmt ./...
# Run $(GO) vet against code
vet:
$(GO) version
$(GO) vet ./...
# Generate code
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
# Build the docker image
docker-build: int-test
docker build . -t ${IMG}
# Push the docker image
docker-push:
docker push ${IMG}
docker-buildx-bake:
REGISTRY=${DEFAULT_IMG_REGISTRY} REPOSITORY=${DEFAULT_IMG_REPOSITORY} BUILD_TAG=${DEFAULT_IMG_TAG} docker buildx bake --file=docker-bake.hcl --builder=${DEFAULT_BUILDX_BUILDER}
# find or download controller-gen
# download controller-gen if necessary
controller-gen:
ifeq (, $(shell which controller-gen))
@{ \
set -e ;\
$(GO) install sigs.k8s.io/controller-tools/cmd/[email protected] ;\
}
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif