forked from virtual-kubelet/azure-aci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
171 lines (140 loc) · 5.58 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
171
TOOLS_DIR := hack/tools
TOOLS_BIN_DIR := $(abspath $(TOOLS_DIR)/bin)
GOLANGCI_LINT_VER := v1.51.0
GOLANGCI_LINT_BIN := golangci-lint
GOLANGCI_LINT := $(abspath $(TOOLS_BIN_DIR)/$(GOLANGCI_LINT_BIN)-$(GOLANGCI_LINT_VER))
GOIMPORTS_VER := latest
GOIMPORTS_BIN := goimports
GOIMPORTS := $(abspath $(TOOLS_BIN_DIR)/$(GOIMPORTS_BIN)-$(GOIMPORTS_VER))
# Scripts
GO_INSTALL := ./hack/go-install.sh
AKS_E2E_SCRIPT := ./hack/e2e/aks.sh
AKS_ADDON_E2E_SCRIPT := ./hack/e2e/aks-addon.sh
GO111MODULE := on
export GO111MODULE
TEST_CREDENTIALS_DIR ?= $(abspath .azure)
TEST_AKS_CREDENTIALS_JSON ?= $(TEST_CREDENTIALS_DIR)/aks_credentials.json
TEST_CREDENTIALS_JSON ?= $(TEST_CREDENTIALS_DIR)/credentials.json
TEST_LOGANALYTICS_JSON ?= $(TEST_CREDENTIALS_DIR)/loganalytics.json
export TEST_CREDENTIALS_JSON TEST_LOGANALYTICS_JSON TEST_AKS_CREDENTIALS_JSON
VERSION ?= v1.6.2
REGISTRY ?= ghcr.io
IMG_NAME ?= virtual-kubelet
INIT_IMG_NAME ?= init-validation
IMAGE ?= $(REGISTRY)/$(IMG_NAME)
INIT_IMAGE ?= $(REGISTRY)/$(INIT_IMG_NAME)
LOCATION := $(E2E_REGION)
E2E_CLUSTER_NAME := $(CLUSTER_NAME)
OUTPUT_TYPE ?= type=docker
BUILDPLATFORM ?= linux/amd64
IMG_TAG ?= $(subst v,,$(VERSION))
INIT_IMG_TAG ?= 0.3.0
BUILD_DATE ?= $(shell date '+%Y-%m-%dT%H:%M:%S')
VERSION_FLAGS := "-ldflags=-X main.buildVersion=$(IMG_TAG) -X main.buildTime=$(BUILD_DATE)"
## --------------------------------------
## Tooling Binaries
## --------------------------------------
$(GOLANGCI_LINT):
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) github.com/golangci/golangci-lint/cmd/golangci-lint $(GOLANGCI_LINT_BIN) $(GOLANGCI_LINT_VER)
# GOIMPORTS
$(GOIMPORTS):
GOBIN=$(TOOLS_BIN_DIR) $(GO_INSTALL) golang.org/x/tools/cmd/goimports $(GOIMPORTS_BIN) $(GOIMPORTS_VER)
BUILDX_BUILDER_NAME ?= img-builder
QEMU_VERSION ?= 7.2.0-1
.PHONY: docker-buildx-builder
docker-buildx-builder:
@if ! docker buildx ls | grep $(BUILDX_BUILDER_NAME); then \
docker run --rm --privileged mcr.microsoft.com/mirror/docker/multiarch/qemu-user-static:$(QEMU_VERSION) --reset -p yes; \
docker buildx create --name $(BUILDX_BUILDER_NAME) --use; \
docker buildx inspect $(BUILDX_BUILDER_NAME) --bootstrap; \
fi
.PHONY: docker-build-image
docker-build-image: docker-buildx-builder
docker buildx build \
--file docker/virtual-kubelet/Dockerfile \
--build-arg VERSION_FLAGS=$(VERSION_FLAGS) \
--output=$(OUTPUT_TYPE) \
--platform="$(BUILDPLATFORM)" \
--pull \
--tag $(IMAGE):$(IMG_TAG) .
.PHONY: docker-build-init-image
docker-build-init-image: docker-buildx-builder
docker buildx build \
--file docker/init-container/Dockerfile \
--output=$(OUTPUT_TYPE) \
--platform="$(BUILDPLATFORM)" \
--pull \
--tag $(INIT_IMAGE):$(INIT_IMG_TAG) .
.PHONY: clean
clean: files := bin/virtual-kubelet bin/virtual-kubelet.tgz
clean:
@rm -f $(files) &>/dev/null || exit 0
## --------------------------------------
## Tests
## --------------------------------------
.PHONY: unit-tests
unit-tests: testauth
@echo running tests
LOCATION=$(LOCATION) AKS_CREDENTIAL_LOCATION=$(TEST_AKS_CREDENTIALS_JSON) \
AZURE_AUTH_LOCATION=$(TEST_CREDENTIALS_JSON) \
LOG_ANALYTICS_AUTH_LOCATION=$(TEST_LOGANALYTICS_JSON) \
go test -v $(shell go list ./... | grep -v /e2e) -race -coverprofile=coverage.txt -covermode=atomic fmt
go tool cover -func=coverage.txt
.PHONY: e2e-test
e2e-test:
PR_RAND=$(PR_COMMIT_SHA) E2E_TARGET=$(E2E_TARGET) \
IMG_URL=$(REGISTRY) IMG_REPO=$(IMG_NAME) IMG_TAG=$(IMG_TAG) \
INIT_IMG_REPO=$(INIT_IMG_NAME) INIT_IMG_TAG=$(INIT_IMG_TAG) \
LOCATION=$(LOCATION) RESOURCE_GROUP=$(E2E_CLUSTER_NAME) \
$(AKS_E2E_SCRIPT) go test -timeout 90m -v ./e2e
.PHONY: aks-addon-e2e-test
aks-addon-e2e-test:
PR_RAND=$(PR_COMMIT_SHA) E2E_TARGET=$(E2E_TARGET) \
IMG_URL=$(REGISTRY) IMG_REPO=$(IMG_NAME) IMG_TAG=$(IMG_TAG) \
INIT_IMG_REPO=$(INIT_IMG_NAME) INIT_IMG_TAG=$(INIT_IMG_TAG) \
LOCATION=$(LOCATION) RESOURCE_GROUP=$(E2E_CLUSTER_NAME) \
$(AKS_ADDON_E2E_SCRIPT) go test -timeout 90m -v ./e2e
.PHONY: vet
vet:
@go vet ./... #$(packages)
## --------------------------------------
## Linting
## --------------------------------------
.PHONY: lint
lint: $(GOLANGCI_LINT)
$(GOLANGCI_LINT) run -v
.PHONY: lint-full
lint-full: $(GOLANGCI_LINT) ## Run slower linters to detect possible issues
$(GOLANGCI_LINT) run -v --fast=false
.PHONY: mod
mod:
@go mod tidy
.PHONY: fmt
fmt: $(GOIMPORTS) ## Run go fmt against code.
go fmt ./...
$(GOIMPORTS) -w $$(go list -f {{.Dir}} ./...)
.PHONY: testauth
testauth: test-cred-json test-aks-cred-json test-loganalytics-json
test-cred-json:
@echo Building test credentials
chmod a+x hack/ci/create_credentials.sh
hack/ci/create_credentials.sh
test-aks-cred-json:
@echo Building test AKS credentials
chmod a+x hack/ci/create_aks_credentials.sh
hack/ci/create_aks_credentials.sh
test-loganalytics-json:
@echo Building log analytics credentials
chmod a+x hack/ci/create_loganalytics_auth.sh
hack/ci/create_loganalytics_auth.sh
.PHONY: release-manifest
release-manifest:
@sed -i -e 's/^VERSION ?= .*/VERSION ?= ${VERSION}/' ./Makefile
@sed -i -e 's/^INIT_IMG_TAG ?= .*/INIT_IMG_TAG ?= ${INIT_IMG_TAG}/' ./Makefile
@sed -i -e "s/version: .*/version: ${IMG_TAG}/" ./charts/virtual-kubelet/Chart.yaml
@sed -i -e "s/tag: .*/tag: ${IMG_TAG}/" ./charts/virtual-kubelet/values.yaml
@sed -i -e "s/initTag: .*/initTag: ${INIT_IMG_TAG}/" ./charts/virtual-kubelet/values.yaml
@sed -i -e 's/RELEASE_TAG=.*/RELEASE_TAG=${IMG_TAG}/' ./charts/virtual-kubelet/README.md
@sed -i -e 's/RELEASE_TAG=.*/RELEASE_TAG=${IMG_TAG}/' ./docs/UPGRADE-README.md
@sed -i -e 's/INIT_IMG_TAG=.*/INIT_IMG_TAG=${INIT_IMG_TAG}/' ./docs/UPGRADE-README.md
@sed -i -e 's/RELEASE_TAG=.*/RELEASE_TAG=${IMG_TAG}/' README.md