-
Notifications
You must be signed in to change notification settings - Fork 440
Expand file tree
/
Copy pathMakefile
More file actions
223 lines (186 loc) · 7.02 KB
/
Makefile
File metadata and controls
223 lines (186 loc) · 7.02 KB
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
default: bin/aws-iam-authenticator
.PHONY: help
help:
@echo "Available targets:"
@echo " bin Build binary for current OS/arch"
@echo " build-all-bins Build binaries for all platforms"
@echo " build-all-images Build Docker images for all Linux architectures"
@echo " image Build Docker image for current arch"
@echo " goreleaser Build a local snapshot release (requires goreleaser)"
@echo " test Run unit tests with coverage"
@echo " integration Run integration tests (requires AWS credentials)"
@echo " e2e Run end-to-end tests: make e2e RUNNER=[kops|kind]"
@echo " lint Run golangci-lint"
@echo " update Run all auto-fixers (gofmt, go mod tidy)"
@echo " verify Assert that 'make update' produces no diff (used in CI)"
@echo " format Check and fix Go formatting"
@echo " codegen Regenerate CRD client code"
@echo " start-dev Start local kind dev environment (requires ADMIN_ARN and AUTHENTICATOR_IMAGE)"
@echo " stop-dev Tear down dev environment (keep _output/dev/)"
@echo " start-dev-dynamicfile Start kind dev environment with DynamicFile backend (no env vars needed)"
@echo " stop-dev-dynamicfile Tear down DynamicFile dev environment (keep _output/dev/)"
@echo " kill-dev Tear down dev environment and remove generated config"
@echo " checksums Generate SHA256 checksums for all release binaries"
@echo " clean Remove build output directory"
PKG ?= sigs.k8s.io/aws-iam-authenticator
GORELEASER := $(shell command -v goreleaser 2> /dev/null)
VERSION ?= $(shell $(shell pwd)/hack/get-version.sh)
GOOS ?= $(shell go env GOOS)
GOARCH ?= $(shell go env GOARCH)
GOPROXY ?= $(shell go env GOPROXY)
GIT_COMMIT ?= $(shell git rev-parse HEAD)
BUILD_DATE ?= $(shell date -u +"%Y-%m-%dT%H:%M:%SZ")
BUILD_DATE_STRIPPED := $(subst -,,$(subst :,,$(BUILD_DATE)))
OUTPUT ?= $(shell pwd)/_output
CHECKSUM_FILE ?= $(OUTPUT)/bin/authenticator_$(VERSION)_checksums.txt
# Architectures for binary builds
BIN_ARCH_LINUX ?= amd64 arm64
BIN_ARCH_WINDOWS ?= amd64
BIN_ARCH_DARWIN ?= amd64 arm64
#CI is defined in test-infra https://github.com/kubernetes/test-infra/blob/2e3dd84399745eb49cef69afc3ed5bded8a6580c/prow/pod-utils/downwardapi/jobspec.go#L89
# and passed in when running on github prow
CI ?= false
RUNNER ?= kops
ALL_LINUX_BIN_TARGETS = $(foreach arch,$(BIN_ARCH_LINUX),$(OUTPUT)/bin/aws-iam-authenticator_$(VERSION)_linux_$(arch))
ALL_WINDOWS_BIN_TARGETS = $(foreach arch,$(BIN_ARCH_WINDOWS),$(OUTPUT)/bin/aws-iam-authenticator_$(VERSION)_windows_$(arch).exe)
ALL_DARWIN_BIN_TARGETS = $(foreach arch,$(BIN_ARCH_DARWIN),$(OUTPUT)/bin/aws-iam-authenticator_$(VERSION)_darwin_$(arch))
ALL_BIN_TARGETS = $(ALL_LINUX_BIN_TARGETS) $(ALL_WINDOWS_BIN_TARGETS) $(ALL_DARWIN_BIN_TARGETS)
.PHONY: bin
bin:
ifeq ($(GOOS),windows)
$(MAKE) $(OUTPUT)/bin/aws-iam-authenticator.exe
else
$(MAKE) $(OUTPUT)/bin/aws-iam-authenticator
endif
# Function checksum
# Parameters:
# 1: Target file on which to perform checksum
# 2: Checksum file to append the result
# Note: the blank line at the end of the function is required.
define checksum
sha256sum $(1) | sed 's|$(OUTPUT)/bin/||' >> $(2)
endef
.PHONY: checksums
checksums: $(CHECKSUM_FILE)
$(CHECKSUM_FILE): build-all-bins
rm -f $(CHECKSUM_FILE)
@echo $(ALL_BIN_TARGETS)
$(foreach target,$(ALL_BIN_TARGETS),$(call checksum,$(target),$(CHECKSUM_FILE)))
$(OUTPUT)/bin/%:
GO111MODULE=on \
CGO_ENABLED=0 \
GOOS=$(GOOS) \
GOARCH=$(GOARCH) \
GOPROXY=$(GOPROXY) \
go build \
-trimpath \
--tags "$(GOTAGS)" \
-o=$@ \
-ldflags="-w -s -X $(PKG)/pkg.Version=$(VERSION) -X $(PKG)/pkg.BuildDate=$(BUILD_DATE) -X $(PKG)/pkg.CommitID=$(GIT_COMMIT)" \
./cmd/aws-iam-authenticator/
# Function build-bin
# Parameters:
# 1: Target OS
# 2: Target architecture
# 3: Target file extension
# Note: the blank line at the end of the function is required.
define build-bin
$(MAKE) $(OUTPUT)/bin/aws-iam-authenticator_$(VERSION)_$(1)_$(2)$(3) GOOS=$(1) GOARCH=$(2)
endef
# Function build-image
# Parameters:
# 1: Target architecture
define build-image
$(MAKE) .image-linux-$(1)
endef
.PHONY: build-all-bins
build-all-bins:
$(foreach arch,$(BIN_ARCH_LINUX),$(call build-bin,linux,$(arch),))
$(foreach arch,$(BIN_ARCH_WINDOWS),$(call build-bin,windows,$(arch),.exe))
$(foreach arch,$(BIN_ARCH_DARWIN),$(call build-bin,darwin,$(arch),))
.PHONY: build-all-images
build-all-images:
$(foreach arch,$(BIN_ARCH_LINUX),$(call build-image,$(arch)))
.PHONY: image
image: .image-linux-$(GOARCH)
.PHONY: .image-linux-%
.image-linux-%:
docker buildx build --output=type=docker --platform linux/$* \
--build-arg golang_image=$(shell hack/setup-go.sh) \
--tag aws-iam-authenticator:$(VERSION)_$(GIT_COMMIT)_$(BUILD_DATE_STRIPPED)-linux_$* .
.PHONY: goreleaser
goreleaser:
ifndef GORELEASER
$(error "goreleaser not found (`go install github.com/goreleaser/goreleaser/v2@latest` to fix)")
endif
$(GORELEASER) release --skip=publish --clean --snapshot
.PHONY: test
test:
./hack/test-unit.sh
.PHONY: integration
integration:
./hack/test-integration.sh
.PHONY: e2e
e2e: bin
ifeq ($(RUNNER),kops)
CI=$(CI) ./hack/e2e/run.sh
else ifeq ($(RUNNER),kind)
./hack/start-dev-env-dynamicfile.sh
CI=$(CI) ./hack/e2e-dynamicfile.sh
./hack/stop-dev-env.sh
else
echo "make e2e RUNNER=[kops|kind]"
endif
.PHONY: lint
lint:
golangci-lint run
# update runs all auto-fixers. Run this before submitting a PR.
.PHONY: update
update:
gofmt -s -w .
go mod tidy
go mod tidy -C ./tests/e2e
go mod tidy -C ./tests/integration
# verify checks that update produces no diff (used in CI).
.PHONY: verify
verify: update
@git diff --exit-code || (echo "\nRun 'make update' and commit the results." && exit 1)
.PHONY: format
format:
test -z "$$(find . -path ./vendor -prune -type f -o -name '*.go' -exec gofmt -d {} + | tee /dev/stderr)" || \
test -z "$$(find . -path ./vendor -prune -type f -o -name '*.go' -exec gofmt -w {} + | tee /dev/stderr)"
.PHONY: codegen
codegen:
./hack/update-codegen.sh
.PHONY: clean
clean:
rm -rf $(shell pwd)/_output
.PHONY: clean-dev
clean-dev:
rm -rf $(shell pwd)/_output/dev
# Use make start-dev when you want to create a kind cluster for
# testing the authenticator. You must pass in the admin ARN and
# the image under test.
.PHONY: start-dev
start-dev: bin
./hack/start-dev-env.sh
.PHONY: stop-dev
stop-dev:
./hack/stop-dev-env.sh
.PHONY: start-dev-dynamicfile
start-dev-dynamicfile:
./hack/start-dev-env-dynamicfile.sh
.PHONY: stop-dev-dynamicfile
stop-dev-dynamicfile:
./hack/stop-dev-env.sh
# Use make kill-dev when you want to remove a dev environment
# and clean everything up in preparation for creating another
# in the future.
# This command will:
# 1. Delete the kind cluster created for testing.
# 2. Kill the authenticator container.
# 3. Delete the docker network created for our kind cluster.
# 4. Remove the _output/dev directory where all the generated
# config is stored.
.PHONY: kill-dev
kill-dev: stop-dev clean-dev