From 1df430255abb463b9a41ec271e6b929b7a79d9b0 Mon Sep 17 00:00:00 2001 From: monopole Date: Mon, 8 Feb 2021 14:39:25 -0800 Subject: [PATCH] Fix prefix bug in copier. --- cmd/k8scopy/internal/copier.go | 6 ++--- cmd/k8scopy/main.go | 6 ++--- kyaml/Makefile | 40 ++++++++++++++++++------------- kyaml/yaml/internal/k8sgen/doc.go | 2 +- scripts/kyaml-pre-commit.sh | 2 ++ 5 files changed, 32 insertions(+), 24 deletions(-) diff --git a/cmd/k8scopy/internal/copier.go b/cmd/k8scopy/internal/copier.go index 9f422d3fd..6baa26ec4 100644 --- a/cmd/k8scopy/internal/copier.go +++ b/cmd/k8scopy/internal/copier.go @@ -32,7 +32,7 @@ func (c Copier) subPath() string { return filepath.Join("internal", c.pgmName) } -func (c Copier) print() { +func (c Copier) Print() { fmt.Printf(" apiMachineryModule: %s\n", c.spec.Module) fmt.Printf(" replacementPath: %s\n", c.replacementPath()) fmt.Printf(" goModCache: %s\n", c.goModCache) @@ -44,14 +44,14 @@ func (c Copier) print() { fmt.Printf(" pwd: %s\n", os.Getenv("PWD")) } -func NewCopier(s *ModuleSpec) Copier { +func NewCopier(s *ModuleSpec, prefix string) Copier { tmp := Copier{ spec: s, pgmName: os.Getenv("GOPACKAGE"), goModCache: RunGetOutputCommand("go", "env", "GOMODCACHE"), } goMod := RunGetOutputCommand("go", "env", "GOMOD") - topPackage := filepath.Join(goMod[:len(goMod)-len("go.mod")-1], "yaml") + topPackage := filepath.Join(goMod[:len(goMod)-len("go.mod")-1], prefix) k := strings.Index(topPackage, sigsK8sIo) if k < 1 { log.Fatalf("cannot find %s in %s", sigsK8sIo, topPackage) diff --git a/cmd/k8scopy/main.go b/cmd/k8scopy/main.go index 25d0faeac..83faca30d 100644 --- a/cmd/k8scopy/main.go +++ b/cmd/k8scopy/main.go @@ -34,11 +34,11 @@ import ( ) func main() { - if len(os.Args) < 2 { - log.Fatal("Need name of yaml file containing module specs.") + if len(os.Args) < 3 { + log.Fatal("Need name of yaml file containing module specs and prefix.") } spec := internal.ReadSpec(os.Args[1]) - c := internal.NewCopier(spec) + c := internal.NewCopier(spec, os.Args[2]) internal.RunNoOutputCommand("go", "get", spec.Name()) for _, p := range spec.Packages { for _, n := range p.Files { diff --git a/kyaml/Makefile b/kyaml/Makefile index b1a8a1713..49665c233 100644 --- a/kyaml/Makefile +++ b/kyaml/Makefile @@ -5,13 +5,6 @@ MYGOBIN := $(shell go env GOPATH)/bin export PATH := $(MYGOBIN):$(PATH) .PHONY: generate license fix vet fmt test lint tidy clean -all: license fix vet fmt test lint tidy - -fix: - go fix ./... - -fmt: - go fmt ./... $(MYGOBIN)/addlicense: go get github.com/google/addlicense @@ -25,25 +18,38 @@ $(MYGOBIN)/k8scopy: $(MYGOBIN)/stringer: go get golang.org/x/tools/cmd/stringer +all: license fix vet fmt test lint tidy + +k8sGenDir := yaml/internal/k8sgen/pkg + generate: $(MYGOBIN)/stringer $(MYGOBIN)/k8scopy go generate ./... clean: - rm -rf yaml/internal/k8sgen/pkg + rm -rf $(k8sGenDir) + +lint: $(MYGOBIN)/golangci-lint + $(MYGOBIN)/golangci-lint \ + --skip-dirs $(k8sGenDir) \ + run ./... license: $(MYGOBIN)/addlicense - $(MYGOBIN)/addlicense -c "The Kubernetes Authors." -f LICENSE_TEMPLATE . + $(MYGOBIN)/addlicense \ + -y 2021 \ + -c "The Kubernetes Authors." \ + -f LICENSE_TEMPLATE . + +test: generate + go test -cover ./... + +fix: + go fix ./... + +fmt: + go fmt ./... tidy: go mod tidy -lint: $(MYGOBIN)/golangci-lint - $(MYGOBIN)/golangci-lint \ - --skip-dirs yaml/internal/k8sgen/pkg \ - run ./... - -test: - go test -cover ./... - vet: go vet ./... diff --git a/kyaml/yaml/internal/k8sgen/doc.go b/kyaml/yaml/internal/k8sgen/doc.go index bc0eebd63..2093c9c18 100644 --- a/kyaml/yaml/internal/k8sgen/doc.go +++ b/kyaml/yaml/internal/k8sgen/doc.go @@ -3,5 +3,5 @@ // All code below this directory is generated. // See {repo}/cmd/k8scopy/main.go for more info. -//go:generate k8scopy k8scopy.yaml +//go:generate k8scopy k8scopy.yaml yaml package k8sgen diff --git a/scripts/kyaml-pre-commit.sh b/scripts/kyaml-pre-commit.sh index 583d4b78c..5c87dee72 100755 --- a/scripts/kyaml-pre-commit.sh +++ b/scripts/kyaml-pre-commit.sh @@ -21,6 +21,8 @@ functions/examples/application-cr export KUSTOMIZE_DOCKER_E2E=${KUSTOMIZE_DOCKER_E2E:-"false"} for target in $targets; do + echo " " + echo " " echo "----- Making $target -----" pushd . cd $target