...
1# Copyright 2019 The Kubernetes Authors.
2# SPDX-License-Identifier: Apache-2.0
3
4GOPATH := $(shell go env GOPATH)
5MYGOBIN := $(shell go env GOPATH)/bin
6SHELL := /bin/bash
7export PATH := $(MYGOBIN):$(PATH)
8
9.PHONY: all
10all: generate license fix vet fmt test lint tidy
11
12"$(MYGOBIN)/stringer":
13 go install golang.org/x/tools/cmd/stringer@v0.1.10
14
15"$(MYGOBIN)/addlicense":
16 go install github.com/google/addlicense@v1.0.0
17
18"$(MYGOBIN)/golangci-lint":
19 go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50.0
20
21"$(MYGOBIN)/deepcopy-gen":
22 go install k8s.io/code-generator/cmd/deepcopy-gen@v0.25.2
23
24"$(MYGOBIN)/ginkgo":
25 go install github.com/onsi/ginkgo/v2/ginkgo@v2.2.0
26
27"$(MYGOBIN)/mdrip":
28 go install github.com/monopole/mdrip@v1.0.2
29
30"$(MYGOBIN)/kind":
31 go install sigs.k8s.io/kind@v0.16.0
32
33# The following target intended for reference by a file in
34# https://github.com/kubernetes/test-infra/tree/master/config/jobs/kubernetes-sigs/cli-utils
35.PHONY: prow-presubmit-check
36prow-presubmit-check: \
37 test lint verify-license
38
39.PHONY: prow-presubmit-check-e2e
40prow-presubmit-check-e2e: \
41 install-column-apt test-e2e verify-kapply-e2e
42
43.PHONY: prow-presubmit-check-stress
44prow-presubmit-check-stress: \
45 test-stress
46
47.PHONY: fix
48fix:
49 go fix ./...
50
51.PHONY: fmt
52fmt:
53 go fmt ./...
54
55# Install column (required by verify-kapply-e2e)
56# Update is included because the kubekins-e2e container build strips out the package cache.
57# In newer versions of debian, column is in the bsdextrautils package,
58# but in buster (used by kubekins-e2e) it's in bsdmainutils.
59.PHONY: install-column-apt
60install-column-apt:
61 apt-get update
62 apt-get install -y bsdmainutils
63
64.PHONY: generate-deepcopy
65generate-deepcopy: "$(MYGOBIN)/deepcopy-gen"
66 hack/run-in-gopath.sh deepcopy-gen --input-dirs ./pkg/apis/... -O zz_generated.deepcopy --go-header-file ./LICENSE_TEMPLATE_GO
67
68.PHONY: generate
69generate: "$(MYGOBIN)/stringer" generate-deepcopy
70 go generate ./...
71
72.PHONY: license
73license: "$(MYGOBIN)/addlicense"
74 "$(MYGOBIN)/addlicense" -v -y 2021 -c "The Kubernetes Authors." -f LICENSE_TEMPLATE .
75
76.PHONY: verify-license
77verify-license: "$(MYGOBIN)/addlicense"
78 "$(MYGOBIN)/addlicense" -check .
79
80.PHONY: tidy
81tidy:
82 go mod tidy
83
84.PHONY: lint
85lint: "$(MYGOBIN)/golangci-lint"
86 "$(MYGOBIN)/golangci-lint" run ./...
87
88.PHONY: test
89test:
90 go test -race -cover ./cmd/... ./pkg/...
91
92.PHONY: test-e2e
93test-e2e: "$(MYGOBIN)/ginkgo" "$(MYGOBIN)/kind"
94 kind delete cluster --name=cli-utils-e2e && kind create cluster --name=cli-utils-e2e --wait 5m
95 "$(MYGOBIN)/ginkgo" -v ./test/e2e/... -- -v 3
96
97.PHONY: test-e2e-focus
98test-e2e-focus: "$(MYGOBIN)/ginkgo" "$(MYGOBIN)/kind"
99 kind delete cluster --name=cli-utils-e2e && kind create cluster --name=cli-utils-e2e --wait 5m
100 "$(MYGOBIN)"/ginkgo -v -focus ".*$(FOCUS).*" ./test/e2e/... -- -v 5
101
102.PHONY: test-stress
103test-stress: "$(MYGOBIN)/ginkgo" "$(MYGOBIN)/kind"
104 kind delete cluster --name=cli-utils-e2e && kind create cluster --name=cli-utils-e2e --wait 5m \
105 --config=./test/stress/kind-cluster.yaml
106 kubectl wait nodes --for=condition=ready --all --timeout=5m
107 "$(MYGOBIN)/ginkgo" -v ./test/stress/... -- -v 3
108
109.PHONY: vet
110vet:
111 go vet ./...
112
113.PHONY: build
114build:
115 go build -o bin/kapply sigs.k8s.io/cli-utils/cmd;
116 mv bin/kapply "$(MYGOBIN)"
117
118.PHONY: build-with-race-detector
119build-with-race-detector:
120 go build -race -o bin/kapply sigs.k8s.io/cli-utils/cmd;
121 mv bin/kapply "$(MYGOBIN)"
122
123.PHONY: verify-kapply-e2e
124verify-kapply-e2e: test-examples-e2e-kapply
125
126.PHONY: test-examples-e2e-kapply
127test-examples-e2e-kapply: "$(MYGOBIN)/mdrip" "$(MYGOBIN)/kind"
128 ( \
129 set -e; \
130 /bin/rm -f bin/kapply; \
131 /bin/rm -f "$(MYGOBIN)/kapply"; \
132 echo "Installing kapply from ."; \
133 make build-with-race-detector; \
134 ./hack/testExamplesE2EAgainstKapply.sh .; \
135 )
136
137.PHONY: nuke
138nuke:
139 sudo rm -rf "$(GOPATH)/pkg/mod/sigs.k8s.io"
View as plain text