-
Notifications
You must be signed in to change notification settings - Fork 51
/
Makefile
164 lines (135 loc) · 5.91 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
# For all targets except `help` and default target (which is also `help`), export environment variables
ifneq (,$(filter-out help,$(MAKECMDGOALS)))
export KUBEBUILDER_ASSETS ?= ${HOME}/.kubebuilder/bin
export CLUSTER_NAME ?= $(shell kubectl config view --minify -o jsonpath='{.clusters[].name}' | rev | cut -d"/" -f1 | rev | cut -d"." -f1)
export CLUSTER_VPC_ID ?= $(shell aws eks describe-cluster --name $(CLUSTER_NAME) | jq -r ".cluster.resourcesVpcConfig.vpcId")
export AWS_ACCOUNT_ID ?= $(shell aws sts get-caller-identity --query Account --output text)
export REGION ?= $(shell aws configure get region)
endif
# Image URL to use all building/pushing image targets
IMG ?= controller:latest
VERSION ?= $(if $(RELEASE_VERSION),$(RELEASE_VERSION),$(shell git tag --sort=v:refname | tail -1))
ECRIMAGES ?=public.ecr.aws/aws-application-networking-k8s/aws-gateway-controller:${VERSION}
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.
ENVTEST_K8S_VERSION = 1.22
# 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
##@ General
# The help target prints out all targets with their descriptions organized
# beneath their categories. The categories are represented by '##@' and the
# target descriptions by '##'. The awk commands is responsible for reading the
# entire set of makefiles included in this invocation, looking for lines of the
# file as xyz: ## something, and then pretty-format the target and help. Then,
# if there's a line with ##@ something, that gets pretty-printed as a category.
# More info on the usage of ANSI control characters for terminal formatting:
# https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
# More info on the awk command:
# http://linuxcommand.org/lc3_adv_awk.php
.PHONY: help
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)
##@ Local Development
.PHONY: run
run: ## Run in development mode
DEV_MODE=1 LOG_LEVEL=debug go run cmd/aws-application-networking-k8s/main.go
.PHONY: presubmit
presubmit: vet manifest lint test ## Run all commands before submitting code
.PHONY: vet
vet: ## Vet the code and dependencies
go mod tidy
go generate ./...
go vet ./...
go fmt ./...
@git diff --quiet ||\
{ echo "New file modification detected in the Git working tree. Please check in before commit."; git --no-pager diff --name-only | uniq | awk '{print " - " $$0}'; \
if [ "${CI}" = true ]; then\
exit 1;\
fi;}
cd test && go mod tidy && go vet ./...
.PHONY: lint
lint: ## Run the golangci-lint only in local machine
if command -v golangci-lint &> /dev/null; then \
echo "Running golangci-lint"; \
golangci-lint run; \
else \
echo "Error: golangci-lint is not installed. Please run the 'make toolchain'"; \
exit 1; \
fi \
.PHONY: test
test: ## Run tests.
go test ./pkg/... -coverprofile coverage.out
.PHONY: toolchain
toolchain: ## Install developer toolchain
./hack/toolchain.sh
##@ Deployment
.PHONY: docker-build
docker-build: test ## Build docker image with the manager.
sudo docker build -t ${IMG} .
.PHONY: docker-push
docker-push: ## Push docker image with the manager.
docker push ${IMG}
# also generates a placeholder cert for the webhook - this cert is not intended to be valid
.PHONY: build-deploy
build-deploy: ## Create a deployment file that can be applied with `kubectl apply -f deploy.yaml`
cd config/manager && kustomize edit set image controller=${ECRIMAGES}
kustomize build config/default > deploy.yaml
.PHONY: manifest
manifest: ## Generate CRD manifest
go run sigs.k8s.io/controller-tools/cmd/[email protected] object paths=./pkg/apis/...
go run sigs.k8s.io/controller-tools/cmd/[email protected] crd paths=./pkg/apis/... output:crd:artifacts:config=config/crds/bases
go run k8s.io/code-generator/cmd/[email protected] --logtostderr ./pkg/apis/applicationnetworking/v1alpha1 --go-header-file hack/boilerplate.go.txt
cp config/crds/bases/application-networking.k8s.aws* helm/crds
e2e-test-namespace := "e2e-test"
.PHONY: e2e-test
e2e-test: ## Run e2e tests against cluster pointed to by ~/.kube/config
@kubectl create namespace $(e2e-test-namespace) > /dev/null 2>&1 || true # ignore already exists error
LOG_LEVEL=debug
cd test && go test \
-p 1 \
-count 1 \
-timeout 90m \
-v \
./suites/integration/... \
--ginkgo.focus="${FOCUS}" \
--ginkgo.skip="${SKIP}" \
--ginkgo.v
.SILENT:
.PHONY: e2e-clean
e2e-clean: ## Delete eks resources created in the e2e test namespace
@echo -n "Cleaning up e2e tests... "
-@kubectl delete namespace $(e2e-test-namespace)
@kubectl create namespace $(e2e-test-namespace)
@echo "Done!"
.PHONY: api-reference
api-reference: ## Update documentation in docs/api-reference.md
@cd docgen && \
gen-crd-api-reference-docs -config config.json -api-dir "../pkg/apis/applicationnetworking/v1alpha1/" -out-file docs.html && \
cat api-reference-base.md docs.html > ../docs/api-reference.md
.PHONY: docs
docs:
mkdir -p site
mkdocs build
e2e-webhook-namespace := "webhook-e2e-test"
# NB webhook tests can only run if the controller is deployed to the cluster
.PHONY: webhook-e2e-test
webhook-e2e-test:
@kubectl create namespace $(e2e-webhook-namespace) > /dev/null 2>&1 || true # ignore already exists error
LOG_LEVEL=debug
cd test && go test \
-p 1 \
-count 1 \
-timeout 10m \
-v \
./suites/webhook/... \
--ginkgo.focus="${FOCUS}" \
--ginkgo.skip="${SKIP}" \
--ginkgo.v