Makefile cleanup

This commit is contained in:
Katrina Verey
2022-03-31 18:29:33 -04:00
parent 672c751715
commit 2a9adbeb1e
10 changed files with 281 additions and 275 deletions

301
Makefile
View File

@@ -3,6 +3,9 @@
# #
# Makefile for kustomize CLI and API. # Makefile for kustomize CLI and API.
MODULES := '"cmd/config" "api/" "kustomize/" "kyaml/"'
LATEST_V4_RELEASE=v4.5.4
SHELL := /usr/bin/env bash SHELL := /usr/bin/env bash
GOOS = $(shell go env GOOS) GOOS = $(shell go env GOOS)
GOARCH = $(shell go env GOARCH) GOARCH = $(shell go env GOARCH)
@@ -11,8 +14,6 @@ ifeq ($(MYGOBIN),)
MYGOBIN = $(shell go env GOPATH)/bin MYGOBIN = $(shell go env GOPATH)/bin
endif endif
export PATH := $(MYGOBIN):$(PATH) export PATH := $(MYGOBIN):$(PATH)
MODULES := '"cmd/config" "api/" "kustomize/" "kyaml/"'
LATEST_V4_RELEASE=v4.5.4
# Provide defaults for REPO_OWNER and REPO_NAME if not present. # Provide defaults for REPO_OWNER and REPO_NAME if not present.
# Typically these values would be provided by Prow. # Typically these values would be provided by Prow.
@@ -24,48 +25,39 @@ ifndef REPO_NAME
REPO_NAME := "kustomize" REPO_NAME := "kustomize"
endif endif
.PHONY: all .PHONY: all
all: install-tools verify-kustomize all: install-tools verify-kustomize
.PHONY: verify-kustomize
verify-kustomize: \
lint-kustomize \
test-unit-kustomize-all \
test-examples-kustomize-against-HEAD \
test-examples-kustomize-against-v4-release
# The following target referenced by a file in # --- Plugins ---
# https://github.com/kubernetes/test-infra/tree/master/config/jobs/kubernetes-sigs/kustomize include Makefile-plugins.mk
.PHONY: prow-presubmit-check
prow-presubmit-check: \
install-tools \
lint-kustomize \
test-unit-kustomize-all \
test-unit-cmd-all \
test-go-mod \
test-examples-kustomize-against-HEAD \
test-examples-kustomize-against-v4-release
.PHONY: verify-kustomize-e2e
verify-kustomize-e2e: test-examples-e2e-kustomize
# Other builds in this repo might want a different linter version. # --- Tool management ---
# Without one Makefile to rule them all, the different makes include Makefile-tools.mk
# cannot assume that golanci-lint is at the version they want.
# This installs what kustomize wants to use.
$(MYGOBIN)/golangci-lint-kustomize:
rm -f $(CURDIR)/hack/golangci-lint
GOBIN=$(CURDIR)/hack go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.2
mv $(CURDIR)/hack/golangci-lint $(MYGOBIN)/golangci-lint-kustomize
$(MYGOBIN)/mdrip: .PHONY: install-tools
go install github.com/monopole/mdrip@v1.0.2 install-tools: \
install-local-tools \
install-out-of-tree-tools
$(MYGOBIN)/stringer: .PHONY: uninstall-tools
go install golang.org/x/tools/cmd/stringer@latest uninstall-tools: \
uninstall-local-tools \
uninstall-out-of-tree-tools
$(MYGOBIN)/goimports: .PHONY: install-local-tools
go install golang.org/x/tools/cmd/goimports@latest install-local-tools: \
$(MYGOBIN)/gorepomod \
$(MYGOBIN)/k8scopy \
$(MYGOBIN)/pluginator
.PHONY: uninstall-local-tools
uninstall-local-tools:
rm -f $(MYGOBIN)/gorepomod
rm -f $(MYGOBIN)/k8scopy
rm -f $(MYGOBIN)/pluginator
# Build from local source. # Build from local source.
$(MYGOBIN)/gorepomod: $(MYGOBIN)/gorepomod:
@@ -82,126 +74,61 @@ $(MYGOBIN)/pluginator:
cd cmd/pluginator; \ cd cmd/pluginator; \
go install . go install .
# --- Build targets ---
# Build from local source. # Build from local source.
$(MYGOBIN)/kustomize: build-kustomize-api $(MYGOBIN)/kustomize: build-kustomize-api
cd kustomize; \ cd kustomize; \
go install . go install .
.PHONY: install-tools kustomize: $(MYGOBIN)/kustomize
install-tools: \
$(MYGOBIN)/goimports \
$(MYGOBIN)/golangci-lint-kustomize \
$(MYGOBIN)/gorepomod \
$(MYGOBIN)/helmV3 \
$(MYGOBIN)/k8scopy \
$(MYGOBIN)/mdrip \
$(MYGOBIN)/pluginator \
$(MYGOBIN)/stringer
### Begin kustomize plugin rules. # Used to add non-default compilation flags when experimenting with
# # plugin-to-api compatibility checks.
# The rules to deal with builtin plugins are a bit .PHONY: build-kustomize-api
# complicated because build-kustomize-api: $(builtinplugins)
# cd api; go build ./...
# - Every builtin plugin is a Go plugin -
# meaning it gets its own module directory
# (outside of the api module) with Go
# code in a 'main' package per Go plugin rules.
# - kustomize locates plugins using the
# 'apiVersion' and 'kind' fields from the
# plugin config file.
# - k8s wants CamelCase in 'kind' fields.
# - The module name (the last name in the path)
# must be the lowercased 'kind' of the
# plugin because Go and related tools
# demand lowercase in import paths, but
# allow CamelCase in file names.
# - the generated code must live in the api
# module (it's linked into the api).
# Where all generated builtin plugin code should go. .PHONY: generate-kustomize-api
pGen=api/internal/builtins generate-kustomize-api: $(MYGOBIN)/k8scopy
# Where the builtin Go plugin modules live. cd api; go generate ./...
pSrc=plugin/builtin
_builtinplugins = \
AnnotationsTransformer.go \
ConfigMapGenerator.go \
IAMPolicyGenerator.go \
HashTransformer.go \
ImageTagTransformer.go \
LabelTransformer.go \
LegacyOrderTransformer.go \
NamespaceTransformer.go \
PatchJson6902Transformer.go \
PatchStrategicMergeTransformer.go \
PatchTransformer.go \
PrefixTransformer.go \
SuffixTransformer.go \
ReplacementTransformer.go \
ReplicaCountTransformer.go \
SecretGenerator.go \
ValueAddTransformer.go \
HelmChartInflationGenerator.go
# Maintaining this explicit list of generated files, and # --- Verification targets ---
# adding it as a dependency to a few targets, to assure .PHONY: verify-kustomize
# they get recreated if deleted. The rules below on how verify-kustomize: \
# to make them don't, by themselves, assure they will be lint \
# recreated if deleted. license \
builtinplugins = $(patsubst %,$(pGen)/%,$(_builtinplugins)) test-unit-kustomize-all \
test-unit-cmd-all \
test-go-mod \
test-examples-kustomize-against-HEAD \
test-examples-kustomize-against-v4-release
# These rules are verbose, but assure that if a source file # The following target referenced by a file in
# is modified, the corresponding generated file, and only # https://github.com/kubernetes/test-infra/tree/master/config/jobs/kubernetes-sigs/kustomize
# that file, will be recreated. .PHONY: prow-presubmit-check
$(pGen)/AnnotationsTransformer.go: $(pSrc)/annotationstransformer/AnnotationsTransformer.go prow-presubmit-check: \
$(pGen)/ConfigMapGenerator.go: $(pSrc)/configmapgenerator/ConfigMapGenerator.go all
$(pGen)/GkeSaGenerator.go: $(pSrc)/gkesagenerator/GkeSaGenerator.go
$(pGen)/HashTransformer.go: $(pSrc)/hashtransformer/HashTransformer.go
$(pGen)/ImageTagTransformer.go: $(pSrc)/imagetagtransformer/ImageTagTransformer.go
$(pGen)/LabelTransformer.go: $(pSrc)/labeltransformer/LabelTransformer.go
$(pGen)/LegacyOrderTransformer.go: $(pSrc)/legacyordertransformer/LegacyOrderTransformer.go
$(pGen)/NamespaceTransformer.go: $(pSrc)/namespacetransformer/NamespaceTransformer.go
$(pGen)/PatchJson6902Transformer.go: $(pSrc)/patchjson6902transformer/PatchJson6902Transformer.go
$(pGen)/PatchStrategicMergeTransformer.go: $(pSrc)/patchstrategicmergetransformer/PatchStrategicMergeTransformer.go
$(pGen)/PatchTransformer.go: $(pSrc)/patchtransformer/PatchTransformer.go
$(pGen)/PrefixTransformer.go: $(pSrc)/prefixtransformer/PrefixTransformer.go
$(pGen)/SuffixTransformer.go: $(pSrc)/suffixtransformer/SuffixTransformer.go
$(pGen)/ReplacementTransformer.go: $(pSrc)/replacementtransformer/ReplacementTransformer.go
$(pGen)/ReplicaCountTransformer.go: $(pSrc)/replicacounttransformer/ReplicaCountTransformer.go
$(pGen)/SecretGenerator.go: $(pSrc)/secretgenerator/SecretGenerator.go
$(pGen)/ValueAddTransformer.go: $(pSrc)/valueaddtransformer/ValueAddTransformer.go
$(pGen)/HelmChartInflationGenerator.go: $(pSrc)/helmchartinflationgenerator/HelmChartInflationGenerator.go
# The (verbose but portable) Makefile way to convert to lowercase. .PHONY: license
toLowerCase = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$1)))))))))))))))))))))))))) license: $(MYGOBIN)/addlicense
$(MYGOBIN)/addlicense \
-y 2022 \
-c "The Kubernetes Authors." \
-f LICENSE_TEMPLATE \
-ignore "kyaml/internal/forked/github.com/**/*" \
-ignore "site/**/*" \
-ignore "**/*.md" \
-ignore "**/*.json" \
-ignore "**/*.yml" \
-ignore "**/*.yaml" \
-v \
.
$(pGen)/%.go: $(MYGOBIN)/pluginator .PHONY: lint
@echo "generating $*" lint: $(MYGOBIN)/golangci-lint $(builtinplugins)
( \
set -e; \
cd $(pSrc)/$(call toLowerCase,$*); \
go generate .; \
cd ../../../$(pGen); \
$(MYGOBIN)/goimports -w $*.go \
)
# Target is for debugging.
.PHONY: generate-kustomize-builtin-plugins
generate-kustomize-builtin-plugins: $(builtinplugins)
.PHONY: build-kustomize-external-go-plugin
build-kustomize-external-go-plugin:
./hack/buildExternalGoPlugins.sh ./plugin
.PHONY: clean-kustomize-external-go-plugin
clean-kustomize-external-go-plugin:
./hack/buildExternalGoPlugins.sh ./plugin clean
### End kustomize plugin rules.
.PHONY: lint-kustomize
lint-kustomize: $(MYGOBIN)/golangci-lint-kustomize $(builtinplugins)
cd api; $(MYGOBIN)/golangci-lint-kustomize \ cd api; $(MYGOBIN)/golangci-lint-kustomize \
-c ../.golangci.yml \ -c ../.golangci.yml \
--path-prefix api \ --path-prefix api \
@@ -215,16 +142,6 @@ lint-kustomize: $(MYGOBIN)/golangci-lint-kustomize $(builtinplugins)
--path-prefix cmd/pluginator \ --path-prefix cmd/pluginator \
run ./... run ./...
# Used to add non-default compilation flags when experimenting with
# plugin-to-api compatibility checks.
.PHONY: build-kustomize-api
build-kustomize-api: $(builtinplugins)
cd api; go build ./...
.PHONY: generate-kustomize-api
generate-kustomize-api: $(MYGOBIN)/k8scopy
cd api; go generate ./...
.PHONY: test-unit-kustomize-api .PHONY: test-unit-kustomize-api
test-unit-kustomize-api: build-kustomize-api test-unit-kustomize-api: build-kustomize-api
cd api; go test ./... -ldflags "-X sigs.k8s.io/kustomize/api/provenance.version=v444.333.222" cd api; go test ./... -ldflags "-X sigs.k8s.io/kustomize/api/provenance.version=v444.333.222"
@@ -251,7 +168,7 @@ test-go-mod:
./hack/check-go-mod.sh ./hack/check-go-mod.sh
.PHONY: .PHONY:
test-examples-e2e-kustomize: $(MYGOBIN)/mdrip $(MYGOBIN)/kind verify-kustomize-e2e: $(MYGOBIN)/mdrip $(MYGOBIN)/kind
( \ ( \
set -e; \ set -e; \
/bin/rm -f $(MYGOBIN)/kustomize; \ /bin/rm -f $(MYGOBIN)/kustomize; \
@@ -268,85 +185,13 @@ test-examples-kustomize-against-HEAD: $(MYGOBIN)/kustomize $(MYGOBIN)/mdrip
test-examples-kustomize-against-v4-release: $(MYGOBIN)/mdrip test-examples-kustomize-against-v4-release: $(MYGOBIN)/mdrip
./hack/testExamplesAgainstKustomize.sh v4@$(LATEST_V4_RELEASE) ./hack/testExamplesAgainstKustomize.sh v4@$(LATEST_V4_RELEASE)
# linux only.
# This is for testing an example plugin that
# uses kubeval for validation.
# Don't want to add a hard dependence in go.mod file
# to github.com/instrumenta/kubeval.
# Instead, download the binary.
$(MYGOBIN)/kubeval:
( \
set -e; \
d=$(shell mktemp -d); cd $$d; \
wget https://github.com/instrumenta/kubeval/releases/latest/download/kubeval-$(GOOS)-$(GOARCH).tar.gz; \
tar xf kubeval-$(GOOS)-$(GOARCH).tar.gz; \
mv kubeval $(MYGOBIN); \
rm -rf $$d; \
)
# linux only.
# This is for testing an example plugin that uses helm to inflate a chart
# for subsequent kustomization.
# Don't want to add a hard dependence in go.mod file to helm.
# Instead, download the binaries.
$(MYGOBIN)/helmV2:
( \
set -e; \
d=$(shell mktemp -d); cd $$d; \
tgzFile=helm-v2.13.1-$(GOOS)-$(GOARCH).tar.gz; \
wget https://storage.googleapis.com/kubernetes-helm/$$tgzFile; \
tar -xvzf $$tgzFile; \
mv $(GOOS)-$(GOARCH)/helm $(MYGOBIN)/helmV2; \
rm -rf $$d \
)
# Helm V3 differs from helm V2; downloading it to provide coverage for the
# chart inflator plugin under helm v3.
$(MYGOBIN)/helmV3:
( \
set -e; \
d=$(shell mktemp -d); cd $$d; \
tgzFile=helm-v3.6.3-$(GOOS)-$(GOARCH).tar.gz; \
wget https://get.helm.sh/$$tgzFile; \
tar -xvzf $$tgzFile; \
mv $(GOOS)-$(GOARCH)/helm $(MYGOBIN)/helmV3; \
rm -rf $$d \
)
$(MYGOBIN)/kind:
( \
set -e; \
d=$(shell mktemp -d); cd $$d; \
wget -O ./kind https://github.com/kubernetes-sigs/kind/releases/download/v0.7.0/kind-$(GOOS)-$(GOARCH); \
chmod +x ./kind; \
mv ./kind $(MYGOBIN); \
rm -rf $$d; \
)
# linux only.
$(MYGOBIN)/gh:
( \
set -e; \
d=$(shell mktemp -d); cd $$d; \
tgzFile=gh_1.0.0_$(GOOS)_$(GOARCH).tar.gz; \
wget https://github.com/cli/cli/releases/download/v1.0.0/$$tgzFile; \
tar -xvzf $$tgzFile; \
mv gh_1.0.0_$(GOOS)_$(GOARCH)/bin/gh $(MYGOBIN)/gh; \
rm -rf $$d \
)
# --- Cleanup targets ---
.PHONY: clean .PHONY: clean
clean: clean-kustomize-external-go-plugin clean: clean-kustomize-external-go-plugin uninstall-tools
go clean --cache go clean --cache
rm -f $(builtinplugins) rm -f $(builtinplugins)
rm -f $(MYGOBIN)/goimports
rm -f $(MYGOBIN)/golangci-lint-kustomize
rm -f $(MYGOBIN)/kustomize rm -f $(MYGOBIN)/kustomize
rm -f $(MYGOBIN)/mdrip
rm -f $(MYGOBIN)/stringer
# Handle pluginator manually.
# rm -f $(MYGOBIN)/pluginator
# Nuke the site from orbit. It's the only way to be sure. # Nuke the site from orbit. It's the only way to be sure.
.PHONY: nuke .PHONY: nuke

102
Makefile-plugins.mk Normal file
View File

@@ -0,0 +1,102 @@
# Copyright 2022 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
### Kustomize plugin rules.
#
# The rules to deal with builtin plugins are a bit
# complicated because
#
# - Every builtin plugin is a Go plugin -
# meaning it gets its own module directory
# (outside of the api module) with Go
# code in a 'main' package per Go plugin rules.
# - kustomize locates plugins using the
# 'apiVersion' and 'kind' fields from the
# plugin config file.
# - k8s wants CamelCase in 'kind' fields.
# - The module name (the last name in the path)
# must be the lowercased 'kind' of the
# plugin because Go and related tools
# demand lowercase in import paths, but
# allow CamelCase in file names.
# - the generated code must live in the api
# module (it's linked into the api).
# Where all generated builtin plugin code should go.
pGen=api/internal/builtins
# Where the builtin Go plugin modules live.
pSrc=plugin/builtin
_builtinplugins = \
AnnotationsTransformer.go \
ConfigMapGenerator.go \
IAMPolicyGenerator.go \
HashTransformer.go \
ImageTagTransformer.go \
LabelTransformer.go \
LegacyOrderTransformer.go \
NamespaceTransformer.go \
PatchJson6902Transformer.go \
PatchStrategicMergeTransformer.go \
PatchTransformer.go \
PrefixTransformer.go \
SuffixTransformer.go \
ReplacementTransformer.go \
ReplicaCountTransformer.go \
SecretGenerator.go \
ValueAddTransformer.go \
HelmChartInflationGenerator.go
# Maintaining this explicit list of generated files, and
# adding it as a dependency to a few targets, to assure
# they get recreated if deleted. The rules below on how
# to make them don't, by themselves, assure they will be
# recreated if deleted.
builtinplugins = $(patsubst %,$(pGen)/%,$(_builtinplugins))
# These rules are verbose, but assure that if a source file
# is modified, the corresponding generated file, and only
# that file, will be recreated.
$(pGen)/AnnotationsTransformer.go: $(pSrc)/annotationstransformer/AnnotationsTransformer.go
$(pGen)/ConfigMapGenerator.go: $(pSrc)/configmapgenerator/ConfigMapGenerator.go
$(pGen)/GkeSaGenerator.go: $(pSrc)/gkesagenerator/GkeSaGenerator.go
$(pGen)/HashTransformer.go: $(pSrc)/hashtransformer/HashTransformer.go
$(pGen)/ImageTagTransformer.go: $(pSrc)/imagetagtransformer/ImageTagTransformer.go
$(pGen)/LabelTransformer.go: $(pSrc)/labeltransformer/LabelTransformer.go
$(pGen)/LegacyOrderTransformer.go: $(pSrc)/legacyordertransformer/LegacyOrderTransformer.go
$(pGen)/NamespaceTransformer.go: $(pSrc)/namespacetransformer/NamespaceTransformer.go
$(pGen)/PatchJson6902Transformer.go: $(pSrc)/patchjson6902transformer/PatchJson6902Transformer.go
$(pGen)/PatchStrategicMergeTransformer.go: $(pSrc)/patchstrategicmergetransformer/PatchStrategicMergeTransformer.go
$(pGen)/PatchTransformer.go: $(pSrc)/patchtransformer/PatchTransformer.go
$(pGen)/PrefixTransformer.go: $(pSrc)/prefixtransformer/PrefixTransformer.go
$(pGen)/SuffixTransformer.go: $(pSrc)/suffixtransformer/SuffixTransformer.go
$(pGen)/ReplacementTransformer.go: $(pSrc)/replacementtransformer/ReplacementTransformer.go
$(pGen)/ReplicaCountTransformer.go: $(pSrc)/replicacounttransformer/ReplicaCountTransformer.go
$(pGen)/SecretGenerator.go: $(pSrc)/secretgenerator/SecretGenerator.go
$(pGen)/ValueAddTransformer.go: $(pSrc)/valueaddtransformer/ValueAddTransformer.go
$(pGen)/HelmChartInflationGenerator.go: $(pSrc)/helmchartinflationgenerator/HelmChartInflationGenerator.go
# The (verbose but portable) Makefile way to convert to lowercase.
toLowerCase = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$1))))))))))))))))))))))))))
$(pGen)/%.go: $(MYGOBIN)/pluginator
@echo "generating $*"
( \
set -e; \
cd $(pSrc)/$(call toLowerCase,$*); \
go generate .; \
cd ../../../$(pGen); \
$(MYGOBIN)/goimports -w $*.go \
)
# Target is for debugging.
.PHONY: generate-kustomize-builtin-plugins
generate-kustomize-builtin-plugins: $(builtinplugins)
.PHONY: build-kustomize-external-go-plugin
build-kustomize-external-go-plugin:
./hack/buildExternalGoPlugins.sh ./plugin
.PHONY: clean-kustomize-external-go-plugin
clean-kustomize-external-go-plugin:
./hack/buildExternalGoPlugins.sh ./plugin clean

88
Makefile-tools.mk Normal file
View File

@@ -0,0 +1,88 @@
# Copyright 2022 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0
.PHONY: install-out-of-tree-tools
install-out-of-tree-tools: \
$(MYGOBIN)/goimports \
$(MYGOBIN)/golangci-lint \
$(MYGOBIN)/helmV3 \
$(MYGOBIN)/mdrip \
$(MYGOBIN)/stringer \
$(MYGOBIN)/goimports
.PHONY: uninstall-out-of-tree-tools
uninstall-out-of-tree-tools:
rm -f $(MYGOBIN)/goimports
rm -f $(MYGOBIN)/golangci-lint
rm -f $(MYGOBIN)/helmV3
rm -f $(MYGOBIN)/mdrip
rm -f $(MYGOBIN)/stringer
$(MYGOBIN)/golangci-lint:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.2
$(MYGOBIN)/mdrip:
go install github.com/monopole/mdrip@v1.0.2
$(MYGOBIN)/stringer:
go install golang.org/x/tools/cmd/stringer@latest
$(MYGOBIN)/goimports:
go install golang.org/x/tools/cmd/goimports@latest
$(MYGOBIN)/mdtogo:
go install sigs.k8s.io/kustomize/cmd/mdtogo
$(MYGOBIN)/addlicense:
go install github.com/google/addlicense
$(MYGOBIN)/kind:
( \
set -e; \
d=$(shell mktemp -d); cd $$d; \
wget -O ./kind https://github.com/kubernetes-sigs/kind/releases/download/v0.7.0/kind-$(GOOS)-$(GOARCH); \
chmod +x ./kind; \
mv ./kind $(MYGOBIN); \
rm -rf $$d; \
)
# linux only.
$(MYGOBIN)/gh:
( \
set -e; \
d=$(shell mktemp -d); cd $$d; \
tgzFile=gh_1.0.0_$(GOOS)_$(GOARCH).tar.gz; \
wget https://github.com/cli/cli/releases/download/v1.0.0/$$tgzFile; \
tar -xvzf $$tgzFile; \
mv gh_1.0.0_$(GOOS)_$(GOARCH)/bin/gh $(MYGOBIN)/gh; \
rm -rf $$d \
)
# linux only.
# This is for testing an example plugin that
# uses kubeval for validation.
# Don't want to add a hard dependence in go.mod file
# to github.com/instrumenta/kubeval.
# Instead, download the binary.
$(MYGOBIN)/kubeval:
( \
set -e; \
d=$(shell mktemp -d); cd $$d; \
wget https://github.com/instrumenta/kubeval/releases/latest/download/kubeval-$(GOOS)-$(GOARCH).tar.gz; \
tar xf kubeval-$(GOOS)-$(GOARCH).tar.gz; \
mv kubeval $(MYGOBIN); \
rm -rf $$d; \
)
# Helm V3 differs from helm V2; downloading it to provide coverage for the
# chart inflator plugin under helm v3.
$(MYGOBIN)/helmV3:
( \
set -e; \
d=$(shell mktemp -d); cd $$d; \
tgzFile=helm-v3.6.3-$(GOOS)-$(GOARCH).tar.gz; \
wget https://get.helm.sh/$$tgzFile; \
tar -xvzf $$tgzFile; \
mv $(GOOS)-$(GOARCH)/helm $(MYGOBIN)/helmV3; \
rm -rf $$d \
)

View File

@@ -1,51 +1,39 @@
# Copyright 2019 The Kubernetes Authors. # Copyright 2019 The Kubernetes Authors.
# SPDX-License-Identifier: Apache-2.0 # SPDX-License-Identifier: Apache-2.0
.PHONY: generate license fix vet fmt test build tidy clean .PHONY: generate fix vet fmt test build tidy clean
GOBIN = $(shell go env GOBIN) MYGOBIN = $(shell go env GOBIN)
ifeq ($(GOBIN),) ifeq ($(MYGOBIN),)
GOBIN = $(shell go env GOPATH)/bin MYGOBIN = $(shell go env GOPATH)/bin
endif endif
export PATH := $(MYGOBIN):$(PATH)
$(GOBIN)/addlicense: include ../../Makefile-tools.mk
go get github.com/google/addlicense
$(GOBIN)/golangci-lint: $(MYGOBIN)/k8scopy:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.2
$(GOBIN)/k8scopy:
( cd ../k8scopy; go install . ) ( cd ../k8scopy; go install . )
$(GOBIN)/mdtogo:
go get sigs.k8s.io/kustomize/cmd/mdtogo
build: build:
go build -v -o $(GOBIN)/kubectl-krm ./kubectl-krm go build -v -o $(MYGOBIN)/kubectl-krm ./kubectl-krm
all: build license fix vet fmt test lint tidy all: build fix vet fmt test lint tidy
k8sGenDir := internal/commands/internal/k8sgen/pkg k8sGenDir := internal/commands/internal/k8sgen/pkg
generate: $(GOBIN)/mdtogo $(GOBIN)/k8scopy generate: $(MYGOBIN)/mdtogo $(MYGOBIN)/k8scopy
GOBIN=$(GOBIN) go generate ./... GOBIN="${MYGOBIN}" go generate ./...
clean: clean:
rm -rf $(k8sGenDir) rm -rf $(k8sGenDir)
lint: $(GOBIN)/golangci-lint lint: $(MYGOBIN)/golangci-lint
$(GOBIN)/golangci-lint \ $(MYGOBIN)/golangci-lint \
--skip-dirs $(k8sGenDir) \ --skip-dirs $(k8sGenDir) \
run ./... \ run ./... \
--path-prefix=cmd/config \ --path-prefix=cmd/config \
-c ../../.golangci.yml -c ../../.golangci.yml
license: $(GOBIN)/addlicense
$(GOBIN)/addlicense \
-y 2022 \
-c "The Kubernetes Authors." \
-f LICENSE_TEMPLATE .
test: test:
go test -v -timeout 45m -cover ./... go test -v -timeout 45m -cover ./...

View File

@@ -3,6 +3,8 @@ ifeq ($(MYGOBIN),)
MYGOBIN = $(shell go env GOPATH)/bin MYGOBIN = $(shell go env GOPATH)/bin
endif endif
include ../../Makefile-tools.mk
$(MYGOBIN)/gorepomod: usage.go $(MYGOBIN)/gorepomod: usage.go
go install . go install .
@@ -13,6 +15,3 @@ test: $(MYGOBIN)/gorepomod
usage.go: README.md $(MYGOBIN)/goimports usage.go: README.md $(MYGOBIN)/goimports
go generate . \ go generate . \
$(MYGOBIN)/goimports -w usage.go $(MYGOBIN)/goimports -w usage.go
$(MYGOBIN)/goimports:
go install golang.org/x/tools/cmd/goimports

View File

@@ -52,9 +52,7 @@ function scanDir {
if onLinuxAndNotOnRemoteCI; then if onLinuxAndNotOnRemoteCI; then
# Some of these tests have special deps. # Some of these tests have special deps.
make $MYGOBIN/helmV2
make $MYGOBIN/helmV3 make $MYGOBIN/helmV3
make $MYGOBIN/helm
make $MYGOBIN/kubeval make $MYGOBIN/kubeval
fi fi

View File

@@ -1,2 +0,0 @@
Copyright {{.Year}} {{.Holder}}
SPDX-License-Identifier: Apache-2.0

View File

@@ -7,21 +7,14 @@ MYGOBIN = $(shell go env GOPATH)/bin
endif endif
export PATH := $(MYGOBIN):$(PATH) export PATH := $(MYGOBIN):$(PATH)
.PHONY: generate license fix vet fmt test lint tidy clean include ../Makefile-tools.mk
$(MYGOBIN)/addlicense: .PHONY: generate fix vet fmt test lint tidy clean
go get github.com/google/addlicense
$(MYGOBIN)/golangci-lint:
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.2
$(MYGOBIN)/k8scopy: $(MYGOBIN)/k8scopy:
( cd ../cmd/k8scopy; go install . ) ( cd ../cmd/k8scopy; go install . )
$(MYGOBIN)/stringer: all: generate fix vet fmt test lint tidy
go get golang.org/x/tools/cmd/stringer
all: license fix vet fmt test lint tidy
k8sGenDir := yaml/internal/k8sgen/pkg k8sGenDir := yaml/internal/k8sgen/pkg
@@ -39,10 +32,6 @@ lint: $(MYGOBIN)/golangci-lint
--skip-dirs yaml/internal/k8sgen/pkg \ --skip-dirs yaml/internal/k8sgen/pkg \
--skip-dirs internal/forked --skip-dirs internal/forked
license: $(MYGOBIN)/addlicense
( find . -type f -not -path "*/internal/forked/github.com/go-yaml*" -exec bash -c "$(MYGOBIN)/addlicense -y 2022 -c 'The Kubernetes Authors.' -f LICENSE_TEMPLATE {}" ";" )
test: test:
go test -cover ./... go test -cover ./...

View File

@@ -27,7 +27,6 @@ import (
"strings" "strings"
"log" "log"
"sigs.k8s.io/kustomize/kyaml/yaml/internal/k8sgen/pkg/selection" "sigs.k8s.io/kustomize/kyaml/yaml/internal/k8sgen/pkg/selection"
"sigs.k8s.io/kustomize/kyaml/yaml/internal/k8sgen/pkg/util/sets" "sigs.k8s.io/kustomize/kyaml/yaml/internal/k8sgen/pkg/util/sets"
"sigs.k8s.io/kustomize/kyaml/yaml/internal/k8sgen/pkg/util/validation" "sigs.k8s.io/kustomize/kyaml/yaml/internal/k8sgen/pkg/util/validation"