This repository has been archived by the owner on Oct 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 192
/
Makefile
213 lines (176 loc) · 5.55 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
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
# Copyright 2021 VMware, Inc. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
include ./common.mk ./build.mk ./e2e.mk
.DEFAULT_GOAL:=help
SHELL := /usr/bin/env bash
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
CRD_OPTIONS ?= "crd"
ifeq ($(GOHOSTOS), linux)
XDG_DATA_HOME := ${HOME}/.local/share
endif
ifeq ($(GOHOSTOS), darwin)
XDG_DATA_HOME := "$${HOME}/Library/Application Support"
endif
# Directories
TOOLS_DIR := $(abspath hack/tools)
TOOLS_BIN_DIR := $(TOOLS_DIR)/bin
BIN_DIR := bin
GO_MODULES=$(shell find . -path "*/go.mod" | xargs -I _ dirname _)
ifndef IS_OFFICIAL_BUILD
IS_OFFICIAL_BUILD = ""
endif
# Package tooling related variables
PACKAGE_VERSION ?= ${BUILD_VERSION}
REPO_BUNDLE_VERSION ?= ${BUILD_VERSION}
# OCI registry for hosting tanzu framework components (containers and packages)
OCI_REGISTRY ?= projects.registry.vmware.com/tanzu_framework
export OCI_REGISTRY
##
## Install targets
##
.PHONY: install
# Install CRDs into a cluster
install: manifests tools
kubectl apply -f apis/core/config/crd/bases
.PHONY: uninstall
# Uninstall CRDs from a cluster
uninstall: manifests
kubectl delete -f apis/core/config/crd/bases
##
## Version
##
.PHONY: version
# Show generated build version
version:
@echo $(BUILD_VERSION)
##
## Testing, verification, formating and cleanup
##
.PHONY: lint-all
# Run linting and misspell checks
lint-all: tools go-lint doc-lint misspell yamllint
# Check licenses in shell scripts and Makefiles
hack/check-license.sh
.PHONY: misspell
misspell:
hack/check/misspell.sh
.PHONY: yamllint
yamllint:
hack/check/check-yaml.sh
# These are the modules that still contain issues reported by golangci-lint.
# Once a module is updated to be lint-free, remove from list to catch lint regressions.
MODULES_NEEDING_LINT_FIX= . ./apis/core
.PHONY: go-lint
# Run linting of go source
go-lint: tools
@for i in $(GO_MODULES); do \
echo "-- Linting $$i --"; \
pushd $${i} > /dev/null; \
if echo ${MODULES_NEEDING_LINT_FIX} | tr ' ' '\n' | grep -q -x $$i; then \
$(GOLANGCI_LINT) run -v --timeout=10m; \
if [ $$? -eq 0 ]; then \
echo "****** NOTE: $$i is now lint-free. Recommend it be excluded from MODULES_NEEDING_LINT_FIX in Makefile"; \
else \
echo; echo "****** WARNING: module $$i needs lint fixes"; echo; \
fi; \
else \
$(GOLANGCI_LINT) run -v --timeout=10m || exit 1; \
fi; \
popd > /dev/null; \
done
# Prevent use of deprecated ioutils module
@CHECK=$$(grep -r --include="*.go" --exclude="zz_generated*" ioutil .); \
if [ -n "$${CHECK}" ]; then \
echo "ioutil is deprecated, use io or os replacements"; \
echo "https://go.dev/doc/go1.16#ioutil"; \
echo "$${CHECK}"; \
exit 1; \
fi
.PHONY: doc-lint
# Run linting checks for docs
doc-lint: tools
$(VALE) --config=.vale/config.ini --glob='*.md' ./
# mdlint rules with possible errors and fixes can be found here:
# https://github.com/DavidAnson/markdownlint/blob/main/doc/Rules.md
# Additional configuration can be found in the .markdownlintrc file.
hack/check-mdlint.sh
.PHONY: modules
# Runs go mod tidy to ensure modules are up to date.
modules:
@for i in $(GO_MODULES); do \
echo "-- Tidying $$i --"; \
pushd $${i}; \
$(GO) mod tidy || exit 1; \
popd; \
done
.PHONY: verify
# Run all verification scripts
verify: tools modules
$(MAKE) smoke-build generate-go generate
./hack/verify-dirty.sh
.PHONY: smoke-build
# Do a quick test that all directories can be built
smoke-build:
@for i in $(GO_MODULES); do \
echo "-- Building $$i --"; \
pushd $${i}; \
$(GO) build ./... || exit 1; \
$(GO) clean -i ./... || exit 1; \
popd; \
done
##
## Code scaffolding targets
##
.PHONY: manifests
# Generate manifests e.g. CRD, RBAC etc.
manifests:
$(MAKE) -C apis/config generate-manifests
$(MAKE) -C apis/core generate-manifests
.PHONY: generate-go
# Generate code via go generate.
generate-go: $(COUNTERFEITER)
@for i in $(GO_MODULES); do \
echo "-- Running go generate ./... $$i --"; \
pushd $${i}; \
PATH=$(abspath hack/tools/bin):"$(PATH)" go generate ./...; \
popd; \
done
.PHONY: generate
# Generate code (legacy)
generate: tools generate-controller-code
.PHONY: generate-fakes
# Generate fakes for writing unit tests
generate-fakes:
$(GO) generate ./...
$(MAKE) fmt
.PHONY: clean-generated-conversions
# Remove files generated by conversion-gen from the mentioned dirs. Example SRC_DIRS="./api/core/v1alpha1"
clean-generated-conversions:
(IFS=','; for i in $(SRC_DIRS); do find $$i -type f -name 'zz_generated.conversion*' -exec rm -f {} \;; done)
.PHONY: generate-go-conversions
# Generate conversions go code
generate-go-conversions: $(CONVERSION_GEN)
$(CONVERSION_GEN) \
-v 3 --logtostderr \
--input-dirs="./apis/core/v1alpha1,./apis/core/v1alpha2" \
--build-tag=ignore_autogenerated_core \
--output-base ./ \
--output-file-base=zz_generated.conversion \
--go-header-file=./hack/boilerplate.go.txt
.PHONY: generate-package-secret
# Generate the default package values secret. Usage: make generate-package-secret PACKAGE=capabilities tkr=v1.23.3---vmware.1-tkg.1 iaas=vsphere
generate-package-secret:
@if [ -z "$(PACKAGE)" ]; then \
echo "PACKAGE argument required"; \
exit 1 ;\
fi
@if [ $(PACKAGE) == 'capabilities' ]; then \
./capabilities/hack/generate-package-secret.sh -v tkr=${tkr} --data-value-yaml 'rbac.podSecurityPolicyNames=[${psp}]';\
else \
echo "invalid PACKAGE: $(PACKAGE)" ;\
exit 1 ;\
fi
.PHONY: create-package
# Stub out new package directories and manifests. Usage: make create-package PACKAGE_NAME=foobar
create-package:
@hack/packages/scripts/create-package.sh $(PACKAGE_NAME)