-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
170 lines (136 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
MAKEFLAGS += --warn-undefined-variables
SHELL := bash
.SHELLFLAGS := -eu -o pipefail -c
.DELETE_ON_ERROR:
.SUFFIXES:
.ONESHELL:
# The version which will be reported by the --version argument of each binary
# and which will be used as the Docker image tag
VERSION ?= master
# The Docker repository name, overridden in CI.
DOCKER_REGISTRY ?= ghcr.io
DOCKER_IMAGE_NAME ?= nhgs64/atlas-cert-manager
# Image URL to use all building/pushing image targets
IMG ?= ${DOCKER_REGISTRY}/${DOCKER_IMAGE_NAME}:${VERSION}
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd:trivialVersions=true"
# BIN is the directory where tools will be installed
export BIN ?= ${CURDIR}/bin
OS := $(shell go env GOOS)
ARCH := $(shell go env GOARCH)
# Kind
KIND_VERSION := 0.12.0
KIND := ${BIN}/kind-${KIND_VERSION}
K8S_CLUSTER_NAME := atlas-issuer-e2e
# cert-manager
CERT_MANAGER_VERSION ?= 1.11.0
# Controller tools
CONTROLLER_GEN_VERSION := 0.5.0
CONTROLLER_GEN := ${BIN}/controller-gen-${CONTROLLER_GEN_VERSION}
INSTALL_YAML ?= build/install.yaml
.PHONY: all
all: manager
# Run tests
.PHONY: test
test: generate fmt vet manifests
go test ./... -coverprofile cover.out
# Build manager binary
.PHONY: manager
manager: generate fmt vet
go build -o bin/manager main.go
# Run against the configured Kubernetes cluster in ~/.kube/config
.PHONY: run
run: generate fmt vet manifests
go run ./main.go
# Install CRDs into a cluster
.PHONY: install
install: manifests
kustomize build config/crd | kubectl apply -f -
# Uninstall CRDs from a cluster
.PHONY: uninstall
uninstall: manifests
kustomize build config/crd | kubectl delete -f -
# Regenerate the install.yaml
.PHONY: ${INSTALL_YAML}
${INSTALL_YAML}:
mkdir -p $(dir $@)
rm -rf build/kustomize
mkdir -p build/kustomize
cd build/kustomize
kustomize create --resources ../../config/default
kustomize edit set image controller=${IMG}
cd ${CURDIR}
kustomize build build/kustomize > $@
# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
.PHONY: deploy
deploy: ${INSTALL_YAML}
kubectl apply -f ${INSTALL_YAML}
# Generate manifests e.g. CRD, RBAC etc.
.PHONY: manifests
manifests: ${CONTROLLER_GEN}
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
# Run go fmt against code
.PHONY: fmt
fmt:
go fmt ./...
# Run go vet against code
.PHONY: vet
vet:
go vet ./...
# Generate code
generate: ${CONTROLLER_GEN}
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
# Build the docker image
.PHONY: docker-build
docker-build:
docker build \
--build-arg VERSION=$(VERSION) \
--tag ${IMG} \
--file Dockerfile \
${CURDIR}
# Push the docker image
.PHONY: docker-push
docker-push:
docker push ${IMG}
${CONTROLLER_GEN}: | ${BIN}
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d)
# trap "rm -rf $${CONTROLLER_GEN_TMP_DIR}" EXIT
cd $${CONTROLLER_GEN_TMP_DIR}
go mod init tmp
go install sigs.k8s.io/controller-tools/cmd/controller-gen@v${CONTROLLER_GEN_VERSION}
mv ${GOPATH}/bin/controller-gen ${CONTROLLER_GEN}
# ==================================
# E2E testing
# ==================================
.PHONY: kind-cluster
kind-cluster: ## Use Kind to create a Kubernetes cluster for E2E tests
kind-cluster: ${KIND}
${KIND} get clusters | grep ${K8S_CLUSTER_NAME} || ${KIND} create cluster --name ${K8S_CLUSTER_NAME}
.PHONY: kind-load
kind-load: ## Load all the Docker images into Kind
${KIND} load docker-image --name ${K8S_CLUSTER_NAME} ${IMG}
.PHONY: kind-export-logs
kind-export-logs:
${KIND} export logs --name ${K8S_CLUSTER_NAME} ${E2E_ARTIFACTS_DIRECTORY}
.PHONY: deploy-cert-manager
deploy-cert-manager: ## Deploy cert-manager in the configured Kubernetes cluster in ~/.kube/config
kubectl apply --filename=https://github.com/cert-manager/cert-manager/releases/download/v${CERT_MANAGER_VERSION}/cert-manager.yaml
kubectl wait --for=condition=Available --timeout=300s apiservice v1.cert-manager.io
.PHONY: e2e
e2e:
kubectl apply --filename config/samples
kubectl wait --for=condition=Ready --timeout=5s issuers.hvca.globalsign.com issuer-sample
kubectl wait --for=condition=Ready --timeout=5s certificaterequests.cert-manager.io issuer-sample
kubectl wait --for=condition=Ready --timeout=5s certificates.cert-manager.io certificate-by-issuer
kubectl wait --for=condition=Ready --timeout=5s clusterissuers.hvca.globalsign.com clusterissuer-sample
kubectl wait --for=condition=Ready --timeout=5s certificaterequests.cert-manager.io clusterissuer-sample
kubectl wait --for=condition=Ready --timeout=5s certificates.cert-manager.io certificate-by-clusterissuer
kubectl delete --filename config/samples
# ==================================
# Download: tools in ${BIN}
# ==================================
${BIN}:
mkdir -p ${BIN}
${KIND}: ${BIN}
curl -fsSL -o ${KIND} https://github.com/kubernetes-sigs/kind/releases/download/v${KIND_VERSION}/kind-${OS}-${ARCH}
chmod +x ${KIND}