diff --git a/Makefile b/Makefile index 02ff9d6419..be52a318c1 100644 --- a/Makefile +++ b/Makefile @@ -15,39 +15,7 @@ SHELL := bash .SHELLFLAGS := -exc -GOLANG_VERSION := 1.26.3 -GOLANGCI_LINT_VERSION := 2.11.4 - -GORELEASER_CONFIG = release/tag/goreleaser.yaml -GORELEASER_IMAGE := ghcr.io/goreleaser/goreleaser-cross:v$(GOLANG_VERSION) - -YEAR_GEN := $(shell date '+%Y') - -.PHONY: docs fix vet fmt lint test build tidy release release-ci - -GOBIN := $(shell go env GOPATH)/bin -GIT_COMMIT := $(shell git rev-parse --short HEAD) - -export KPT_FN_WASM_RUNTIME ?= nodejs - -LDFLAGS := -ldflags "-X github.com/kptdev/kpt/run.version=${GIT_COMMIT} -ifeq ($(OS),Windows_NT) - # Do nothing -else - UNAME := $(shell uname -s) - ifeq ($(UNAME),Linux) - LDFLAGS += -extldflags '-z noexecstack' - endif -endif -LDFLAGS += " - -# T refers to an e2e test case matcher. This enables running e2e tests -# selectively. For example, -# To invoke e2e tests related to fnconfig, run: -# make test-fn-render T=fnconfig -# make test-fn-eval T=fnconfig -# By default, make test-fn-render/test-fn-eval will run all tests. -T ?= ".*" +include ./make/info.mk all: fix vet fmt lint test build tidy @@ -78,33 +46,33 @@ install-swagger: install-mdtogo: go install ./mdtogo -fix: +fix: fix-api go fix ./... -fmt: +fmt: fmt-api go fmt ./... schema: install-swagger GOBIN=$(GOBIN) scripts/generate-schema.sh -generate: install-mdtogo +generate: install-mdtogo generate-api rm -rf internal/docs/generated mkdir internal/docs/generated GOBIN=$(GOBIN) YEAR_GEN=$(YEAR_GEN) go generate ./... go fmt ./internal/docs/generated/... -tidy: +tidy: tidy-api go mod tidy # if the local version of golangci-lint matches the one we want, we can use that without overhead -lint: +lint: lint-api @if [[ `command -v golangci-lint` && `golangci-lint version --short` == $(GOLANGCI_LINT_VERSION) ]]; then \ golangci-lint run -v ./...; \ else \ go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v$(GOLANGCI_LINT_VERSION) run -v ./...; \ fi -test: +test: test-api go test -cover ${LDFLAGS} ./... # This target is used to run Go tests that require docker runtime. @@ -131,7 +99,7 @@ test-fn-eval: build test-live-apply: build PATH="$(GOBIN):$(PATH)" go test -v -timeout=20m --tags=kind -p 2 --run=TestLiveApply/testdata/live-apply/$(T) ./e2e/ -vet: +vet: vet-api go vet ./... docker: @@ -185,3 +153,29 @@ release-ci: vulncheck: build # Scan the source GOFLAGS= go run golang.org/x/vuln/cmd/govulncheck@latest ./... + +.PHONY: fix-api fmt-api generate-api tidy-api lint-api test-api vet-api api + +fix-api: + make -C api fix + +fmt-api: + make -C api fmt + +generate-api: + make -C api generate + +tidy-api: + make -C api tidy + +lint-api: + make -C api lint + +test-api: + make -C api test + +vet-api: + make -C api vet + +api: + make -C api all diff --git a/api/Makefile b/api/Makefile new file mode 100644 index 0000000000..2bdeaa46a1 --- /dev/null +++ b/api/Makefile @@ -0,0 +1,54 @@ +# Copyright 2026 The kpt Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +SHELL := bash +.SHELLFLAGS := -exc + +include ../make/info.mk + +.PHONY: all +all: fix vet fmt lint test tidy + +.PHONY: fix +fix: + go fix ./... + +.PHONY: fmt +fmt: + go fmt ./... + +.PHONY: generate +generate: + GOBIN=$(GOBIN) YEAR_GEN=$(YEAR_GEN) go generate ./... + +.PHONY: tidy +tidy: + go mod tidy + +# if the local version of golangci-lint matches the one we want, we can use that without overhead +.PHONY: lint +lint: + @if [[ `command -v golangci-lint` && `golangci-lint version --short` == $(GOLANGCI_LINT_VERSION) ]]; then \ + golangci-lint run -v ./...; \ + else \ + go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v$(GOLANGCI_LINT_VERSION) run -v ./...; \ + fi + +.PHONY: test +test: + go test -cover ${LDFLAGS} ./... + +.PHONY: vet +vet: + go vet ./... diff --git a/pkg/api/fnresult/v1/types.go b/api/fnresult/v1/types.go similarity index 97% rename from pkg/api/fnresult/v1/types.go rename to api/fnresult/v1/types.go index 7bd1a26102..a666177354 100644 --- a/pkg/api/fnresult/v1/types.go +++ b/api/fnresult/v1/types.go @@ -1,4 +1,4 @@ -// Copyright 2021 The kpt Authors +// Copyright 2021,2026 The kpt Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -25,7 +25,7 @@ import ( "sigs.k8s.io/kustomize/kyaml/yaml" ) -//go:generate go run sigs.k8s.io/controller-tools/cmd/controller-gen@v0.21.0 object:headerFile="../../../../hack/boilerplate.go.txt",year=$YEAR_GEN +//go:generate go run sigs.k8s.io/controller-tools/cmd/controller-gen@v0.21.0 object:headerFile="../../../hack/boilerplate.go.txt",year=$YEAR_GEN // Result contains the structured result from an individual function type Result struct { @@ -136,7 +136,7 @@ func (i *ResultItem) String() string { if i.Severity == "" { severity = framework.Info } - list := []interface{}{severity} + list := []any{severity} if len(idStringList) > 0 { formatString += " %s" list = append(list, strings.Join(idStringList, "/")) diff --git a/pkg/api/fnresult/v1/zz_generated.deepcopy.go b/api/fnresult/v1/zz_generated.deepcopy.go similarity index 100% rename from pkg/api/fnresult/v1/zz_generated.deepcopy.go rename to api/fnresult/v1/zz_generated.deepcopy.go diff --git a/api/go.mod b/api/go.mod new file mode 100644 index 0000000000..de109d4bef --- /dev/null +++ b/api/go.mod @@ -0,0 +1,32 @@ +module github.com/kptdev/kpt/api + +go 1.24.0 + +require ( + github.com/stretchr/testify v1.11.1 + k8s.io/apimachinery v0.34.8 // intentionally outdated to have a lower go version + sigs.k8s.io/kustomize/kyaml v0.21.1 +) + +require ( + github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect + github.com/go-errors/errors v1.4.2 // indirect + github.com/go-openapi/jsonpointer v0.21.0 // indirect + github.com/go-openapi/jsonreference v0.20.2 // indirect + github.com/go-openapi/swag v0.23.0 // indirect + github.com/gogo/protobuf v1.3.2 // indirect + github.com/google/gnostic-models v0.7.0 // indirect + github.com/josharian/intern v1.0.0 // indirect + github.com/mailru/easyjson v0.7.7 // indirect + github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect + github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect + github.com/xlab/treeprint v1.2.0 // indirect + go.yaml.in/yaml/v2 v2.4.3 // indirect + go.yaml.in/yaml/v3 v3.0.4 // indirect + golang.org/x/sys v0.40.0 // indirect + google.golang.org/protobuf v1.36.12-0.20260120151049-f2248ac996af // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect + k8s.io/kube-openapi v0.0.0-20260317180543-43fb72c5454a // indirect + k8s.io/utils v0.0.0-20260210185600-b8788abfbbc2 // indirect + sigs.k8s.io/yaml v1.6.0 // indirect +) diff --git a/api/go.sum b/api/go.sum new file mode 100644 index 0000000000..2e1847a571 --- /dev/null +++ b/api/go.sum @@ -0,0 +1,119 @@ +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA= +github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og= +github.com/go-openapi/jsonpointer v0.19.6/go.mod h1:osyAmYz/mB/C3I+WsTTSgw1ONzaLJoLCyoi6/zppojs= +github.com/go-openapi/jsonpointer v0.21.0 h1:YgdVicSA9vH5RiHs9TZW5oyafXZFc6+2Vc1rr/O9oNQ= +github.com/go-openapi/jsonpointer v0.21.0/go.mod h1:IUyH9l/+uyhIYQ/PXVA41Rexl+kOkAPDdXEYns6fzUY= +github.com/go-openapi/jsonreference v0.20.2 h1:3sVjiK66+uXK/6oQ8xgcRKcFgQ5KXa2KvnJRumpMGbE= +github.com/go-openapi/jsonreference v0.20.2/go.mod h1:Bl1zwGIM8/wsvqjsOQLJ/SH+En5Ap4rVB5KVcIDZG2k= +github.com/go-openapi/swag v0.22.3/go.mod h1:UzaqsxGiab7freDnrUUra0MwWfN/q7tE4j+VcZ0yl14= +github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE= +github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ= +github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= +github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= +github.com/google/gnostic-models v0.7.0 h1:qwTtogB15McXDaNqTZdzPJRHvaVJlAl+HVQnLmJEJxo= +github.com/google/gnostic-models v0.7.0/go.mod h1:whL5G0m6dmc5cPxKc5bdKdEN3UjI7OUGxBlw57miDrQ= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= +github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= +github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= +github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= +github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc= +github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 h1:n6/2gBQ3RWajuToeY6ZtZTIKv2v7ThUy5KKusIT0yc0= +github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00/go.mod h1:Pm3mSP3c5uWn86xMLZ5Sa7JB9GsEZySvHYXCTK4E9q4= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= +github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= +github.com/sergi/go-diff v1.4.0 h1:n/SP9D5ad1fORl+llWyN+D6qoUETXNZARKjyY2/KVCw= +github.com/sergi/go-diff v1.4.0/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= +github.com/spf13/cobra v1.9.1 h1:CXSaggrXdbHK9CF+8ywj8Amf7PBRmPCOJugH954Nnlo= +github.com/spf13/cobra v1.9.1/go.mod h1:nDyEzZ8ogv936Cinf6g1RU9MRY64Ir93oCnqb9wxYW0= +github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o= +github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= +github.com/xlab/treeprint v1.2.0 h1:HzHnuAF1plUN2zGlAFHbSQP2qJ0ZAD3XF5XD7OesXRQ= +github.com/xlab/treeprint v1.2.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0= +github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0= +go.yaml.in/yaml/v2 v2.4.3/go.mod h1:zSxWcmIDjOzPXpjlTTbAsKokqkDNAVtZO0WOMiT90s8= +go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc= +go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.40.0 h1:DBZZqJ2Rkml6QMQsZywtnjnnGvHza6BTfYFWY9kjEWQ= +golang.org/x/sys v0.40.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= +golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v1.36.12-0.20260120151049-f2248ac996af h1:+5/Sw3GsDNlEmu7TfklWKPdQ0Ykja5VEmq2i817+jbI= +google.golang.org/protobuf v1.36.12-0.20260120151049-f2248ac996af/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +k8s.io/apimachinery v0.34.8 h1:Vjyd/TdakksL0g7ikxyaAk3s3qgqRRYz9vj0AudwNzc= +k8s.io/apimachinery v0.34.8/go.mod h1:z7dd12Xd400CXIycE8nmn32xZhApV9zskHs0A5xeU/Q= +k8s.io/kube-openapi v0.0.0-20260317180543-43fb72c5454a h1:xCeOEAOoGYl2jnJoHkC3hkbPJgdATINPMAxaynU2Ovg= +k8s.io/kube-openapi v0.0.0-20260317180543-43fb72c5454a/go.mod h1:uGBT7iTA6c6MvqUvSXIaYZo9ukscABYi2btjhvgKGZ0= +k8s.io/utils v0.0.0-20260210185600-b8788abfbbc2 h1:AZYQSJemyQB5eRxqcPky+/7EdBj0xi3g0ZcxxJ7vbWU= +k8s.io/utils v0.0.0-20260210185600-b8788abfbbc2/go.mod h1:xDxuJ0whA3d0I4mf/C4ppKHxXynQ+fxnkmQH0vTHnuk= +sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 h1:gBQPwqORJ8d8/YNZWEjoZs7npUVDpVXUUOFfW6CgAqE= +sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8/go.mod h1:mdzfpAEoE6DHQEN0uh9ZbOCuHbLK5wOm7dK4ctXE9Tg= +sigs.k8s.io/kustomize/kyaml v0.21.1 h1:IVlbmhC076nf6foyL6Taw4BkrLuEsXUXNpsE+ScX7fI= +sigs.k8s.io/kustomize/kyaml v0.21.1/go.mod h1:hmxADesM3yUN2vbA5z1/YTBnzLJ1dajdqpQonwBL1FQ= +sigs.k8s.io/randfill v1.0.0 h1:JfjMILfT8A6RbawdsK2JXGBR5AQVfd+9TbzrlneTyrU= +sigs.k8s.io/randfill v1.0.0/go.mod h1:XeLlZ/jmk4i1HRopwe7/aU3H5n1zNUcX6TM94b3QxOY= +sigs.k8s.io/yaml v1.6.0 h1:G8fkbMSAFqgEFgh4b1wmtzDnioxFCUgTZhlbj5P9QYs= +sigs.k8s.io/yaml v1.6.0/go.mod h1:796bPqUfzR/0jLAl6XjHl3Ck7MiyVv8dbTdyT3/pMf4= diff --git a/pkg/lib/types/types.go b/api/kptfile/v1/path.go similarity index 94% rename from pkg/lib/types/types.go rename to api/kptfile/v1/path.go index 1666305881..90c837212f 100644 --- a/pkg/lib/types/types.go +++ b/api/kptfile/v1/path.go @@ -1,4 +1,4 @@ -// Copyright 2021 The kpt Authors +// Copyright 2021,2026 The kpt Authors // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -12,8 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package types defines the basic types used by the kpt codebase. -package types +package v1 import ( "os" diff --git a/pkg/api/kptfile/v1/types.go b/api/kptfile/v1/types.go similarity index 99% rename from pkg/api/kptfile/v1/types.go rename to api/kptfile/v1/types.go index 5ad77be005..696299f7ff 100644 --- a/pkg/api/kptfile/v1/types.go +++ b/api/kptfile/v1/types.go @@ -22,12 +22,12 @@ import ( "fmt" "strings" - fnresultv1 "github.com/kptdev/kpt/pkg/api/fnresult/v1" + fnresultv1 "github.com/kptdev/kpt/api/fnresult/v1" "k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/kustomize/kyaml/yaml" ) -//go:generate go run sigs.k8s.io/controller-tools/cmd/controller-gen@v0.21.0 object:headerFile="../../../../hack/boilerplate.go.txt",year=$YEAR_GEN +//go:generate go run sigs.k8s.io/controller-tools/cmd/controller-gen@v0.21.0 object:headerFile="../../../hack/boilerplate.go.txt",year=$YEAR_GEN const ( KptFileName = "Kptfile" diff --git a/pkg/api/kptfile/v1/validation.go b/api/kptfile/v1/validation.go similarity index 92% rename from pkg/api/kptfile/v1/validation.go rename to api/kptfile/v1/validation.go index 033cf6acba..2b11c4a4af 100644 --- a/pkg/api/kptfile/v1/validation.go +++ b/api/kptfile/v1/validation.go @@ -21,9 +21,6 @@ import ( "slices" "strings" - "github.com/kptdev/kpt/pkg/lib/types" - "sigs.k8s.io/kustomize/api/konfig" - kustomizetypes "sigs.k8s.io/kustomize/api/types" "sigs.k8s.io/kustomize/kyaml/filesys" "sigs.k8s.io/kustomize/kyaml/kio" "sigs.k8s.io/kustomize/kyaml/kio/kioutil" @@ -33,9 +30,10 @@ import ( const ( // constants related to kustomize kustomizationAPIGroup = "kustomize.config.k8s.io" + kustomizationKind = "Kustomization" ) -func (kf *KptFile) Validate(fsys filesys.FileSystem, pkgPath types.UniquePath) error { +func (kf *KptFile) Validate(fsys filesys.FileSystem, pkgPath UniquePath) error { if err := kf.Pipeline.validate(fsys, pkgPath); err != nil { return fmt.Errorf("invalid pipeline: %w", err) } @@ -46,7 +44,7 @@ func (kf *KptFile) Validate(fsys filesys.FileSystem, pkgPath types.UniquePath) e // validate will validate all fields in the Pipeline // 'mutators' and 'validators' share same schema and // they are valid if all functions in them are ALL valid. -func (p *Pipeline) validate(fsys filesys.FileSystem, pkgPath types.UniquePath) error { +func (p *Pipeline) validate(fsys filesys.FileSystem, pkgPath UniquePath) error { if p == nil { return nil } @@ -67,7 +65,7 @@ func (p *Pipeline) validate(fsys filesys.FileSystem, pkgPath types.UniquePath) e return nil } -func (f *Function) validate(fsys filesys.FileSystem, fnType string, idx int, pkgPath types.UniquePath) error { +func (f *Function) validate(fsys filesys.FileSystem, fnType string, idx int, pkgPath UniquePath) error { if f.Image == "" && f.Exec == "" { return &ValidateError{ Field: fmt.Sprintf("pipeline.%s[%d]", fnType, idx), @@ -173,7 +171,7 @@ func validateFnConfigPathSyntax(p string) error { // GetValidatedFnConfigFromPath validates the functionConfig at the path specified by // the package path (pkgPath) and configPath, returning the functionConfig as an // RNode if the validation is successful. -func GetValidatedFnConfigFromPath(fsys filesys.FileSystem, pkgPath types.UniquePath, configPath string) (*yaml.RNode, error) { +func GetValidatedFnConfigFromPath(fsys filesys.FileSystem, pkgPath UniquePath, configPath string) (*yaml.RNode, error) { path := filepath.Join(string(pkgPath), configPath) file, err := fsys.Open(path) if err != nil { @@ -238,7 +236,7 @@ func isKustomization(n *yaml.RNode) bool { // read the file path of the resource resourceFile := filepath.Base(resourcePath) - if slices.Contains(konfig.RecognizedKustomizationFileNames(), resourceFile) { + if slices.Contains(RecognizedKustomizationFileNames(), resourceFile) { return true } } @@ -251,7 +249,7 @@ func isKustomization(n *yaml.RNode) bool { return true } - if meta.APIVersion == "" && meta.Kind == kustomizetypes.KustomizationKind { + if meta.APIVersion == "" && meta.Kind == kustomizationKind { return true } @@ -277,3 +275,13 @@ func (e *ValidateError) Error() string { fmt.Fprintf(&sb, "Reason: %s\n", e.Reason) return sb.String() } + +// RecognizedKustomizationFileNames taken from sigs.k8s.io/kustomize/api@v0.21.1/konfig/general.go +// to avoid dependency. +func RecognizedKustomizationFileNames() []string { + return []string{ + "kustomization.yaml", + "kustomization.yml", + "Kustomization", + } +} diff --git a/pkg/api/kptfile/v1/validation_test.go b/api/kptfile/v1/validation_test.go similarity index 99% rename from pkg/api/kptfile/v1/validation_test.go rename to api/kptfile/v1/validation_test.go index 08c5e23d1e..4246b0caeb 100644 --- a/pkg/api/kptfile/v1/validation_test.go +++ b/api/kptfile/v1/validation_test.go @@ -18,7 +18,6 @@ import ( "path/filepath" "testing" - "github.com/kptdev/kpt/pkg/lib/types" "github.com/stretchr/testify/assert" "sigs.k8s.io/kustomize/kyaml/filesys" "sigs.k8s.io/kustomize/kyaml/yaml" @@ -502,7 +501,7 @@ metadata: d := t.TempDir() err := os.WriteFile(filepath.Join(d, "f1.yaml"), []byte(tc.input), 0700) assert.NoError(t, err) - got, err := GetValidatedFnConfigFromPath(filesys.FileSystemOrOnDisk{}, types.UniquePath(d), "f1.yaml") + got, err := GetValidatedFnConfigFromPath(filesys.FileSystemOrOnDisk{}, UniquePath(d), "f1.yaml") if tc.errMsg != "" { assert.Error(t, err) assert.Equal(t, tc.errMsg, err.Error()) diff --git a/pkg/api/kptfile/v1/zz_generated.deepcopy.go b/api/kptfile/v1/zz_generated.deepcopy.go similarity index 99% rename from pkg/api/kptfile/v1/zz_generated.deepcopy.go rename to api/kptfile/v1/zz_generated.deepcopy.go index 9930e7bd0c..01631de11e 100644 --- a/pkg/api/kptfile/v1/zz_generated.deepcopy.go +++ b/api/kptfile/v1/zz_generated.deepcopy.go @@ -19,7 +19,7 @@ package v1 import ( - fnresultv1 "github.com/kptdev/kpt/pkg/api/fnresult/v1" + fnresultv1 "github.com/kptdev/kpt/api/fnresult/v1" ) // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. diff --git a/pkg/api/resourcegroup/v1alpha1/types.go b/api/resourcegroup/v1alpha1/types.go similarity index 95% rename from pkg/api/resourcegroup/v1alpha1/types.go rename to api/resourcegroup/v1alpha1/types.go index a07055b9fb..3aa8c4da24 100644 --- a/pkg/api/resourcegroup/v1alpha1/types.go +++ b/api/resourcegroup/v1alpha1/types.go @@ -19,14 +19,13 @@ package v1alpha1 import ( "k8s.io/apimachinery/pkg/runtime/schema" - "sigs.k8s.io/cli-utils/pkg/common" "sigs.k8s.io/kustomize/kyaml/yaml" ) const ( RGFileName = "resourcegroup.yaml" // RGInventoryIDLabel is the label name used for storing an inventory ID. - RGInventoryIDLabel = common.InventoryLabel + RGInventoryIDLabel = "cli-utils.sigs.k8s.io/inventory-id" // Deprecated: prefer ResourceGroupGVK RGFileKind = "ResourceGroup" diff --git a/commands/live/apply/cmdapply_test.go b/commands/live/apply/cmdapply_test.go index 5d77201d79..a6eb85d311 100644 --- a/commands/live/apply/cmdapply_test.go +++ b/commands/live/apply/cmdapply_test.go @@ -18,8 +18,8 @@ import ( "path/filepath" "testing" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/internal/testutil" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "github.com/kptdev/kpt/pkg/printer/fake" "github.com/stretchr/testify/assert" diff --git a/commands/live/destroy/cmddestroy_test.go b/commands/live/destroy/cmddestroy_test.go index 1d04a3e444..1056d50c4c 100644 --- a/commands/live/destroy/cmddestroy_test.go +++ b/commands/live/destroy/cmddestroy_test.go @@ -18,8 +18,8 @@ import ( "path/filepath" "testing" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/internal/testutil" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "github.com/kptdev/kpt/pkg/printer/fake" "github.com/stretchr/testify/assert" diff --git a/commands/live/init/cmdliveinit.go b/commands/live/init/cmdliveinit.go index 90d44f2c95..e62eaba014 100644 --- a/commands/live/init/cmdliveinit.go +++ b/commands/live/init/cmdliveinit.go @@ -25,13 +25,12 @@ import ( "strings" "time" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" + rgfilev1alpha1 "github.com/kptdev/kpt/api/resourcegroup/v1alpha1" "github.com/kptdev/kpt/internal/docs/generated/livedocs" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" - rgfilev1alpha1 "github.com/kptdev/kpt/pkg/api/resourcegroup/v1alpha1" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "github.com/kptdev/kpt/pkg/lib/errors" "github.com/kptdev/kpt/pkg/lib/pkg" - "github.com/kptdev/kpt/pkg/lib/types" "github.com/kptdev/kpt/pkg/lib/util/attribution" pathutil "github.com/kptdev/kpt/pkg/lib/util/path" "github.com/kptdev/kpt/pkg/printer" @@ -291,13 +290,13 @@ func writeRGFile(dir string, rg *rgfilev1alpha1.ResourceGroup, filename string) return err } if _, err := os.Stat(filepath.Join(dir, filename)); err != nil && !goerrors.Is(err, os.ErrNotExist) { - return errors.E(op, errors.IO, types.UniquePath(dir), err) + return errors.E(op, errors.IO, kptfilev1.UniquePath(dir), err) } // fyi: perm is ignored if the file already exists err = os.WriteFile(filepath.Join(dir, filename), b, 0600) if err != nil { - return errors.E(op, errors.IO, types.UniquePath(dir), err) + return errors.E(op, errors.IO, kptfilev1.UniquePath(dir), err) } return nil } diff --git a/commands/live/init/cmdliveinit_test.go b/commands/live/init/cmdliveinit_test.go index 7d79a68af7..d3d3571e19 100644 --- a/commands/live/init/cmdliveinit_test.go +++ b/commands/live/init/cmdliveinit_test.go @@ -21,9 +21,9 @@ import ( "testing" "time" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" + rgfilev1alpha1 "github.com/kptdev/kpt/api/resourcegroup/v1alpha1" "github.com/kptdev/kpt/internal/testutil" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" - rgfilev1alpha1 "github.com/kptdev/kpt/pkg/api/resourcegroup/v1alpha1" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "github.com/kptdev/kpt/pkg/lib/pkg" "github.com/kptdev/kpt/pkg/printer/fake" diff --git a/commands/live/migrate/migratecmd.go b/commands/live/migrate/migratecmd.go index 03f5f1a44d..ef116e6da2 100644 --- a/commands/live/migrate/migratecmd.go +++ b/commands/live/migrate/migratecmd.go @@ -23,13 +23,13 @@ import ( "os" "path/filepath" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" + rgfilev1alpha1 "github.com/kptdev/kpt/api/resourcegroup/v1alpha1" initialization "github.com/kptdev/kpt/commands/live/init" "github.com/kptdev/kpt/internal/docs/generated/livedocs" - rgfilev1alpha1 "github.com/kptdev/kpt/pkg/api/resourcegroup/v1alpha1" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "github.com/kptdev/kpt/pkg/lib/errors" "github.com/kptdev/kpt/pkg/lib/pkg" - "github.com/kptdev/kpt/pkg/lib/types" argsutil "github.com/kptdev/kpt/pkg/lib/util/args" pathutil "github.com/kptdev/kpt/pkg/lib/util/path" "github.com/kptdev/kpt/pkg/live" @@ -385,9 +385,9 @@ func (mr *Runner) migrateKptfileToRG(args []string) error { _, rgFileErr := os.Stat(filepath.Join(dir, mr.rgFile)) switch { case rgFileErr == nil: - return errors.E(op, errors.IO, types.UniquePath(dir), "the resourcegroup file already exists and inventory information cannot be migrated") + return errors.E(op, errors.IO, kptfilev1.UniquePath(dir), "the resourcegroup file already exists and inventory information cannot be migrated") case err != nil && !goerrors.Is(err, os.ErrNotExist): - return errors.E(op, errors.IO, types.UniquePath(dir), err) + return errors.E(op, errors.IO, kptfilev1.UniquePath(dir), err) } err = (&initialization.ConfigureInventoryInfo{ diff --git a/commands/live/migrate/migratecmd_test.go b/commands/live/migrate/migratecmd_test.go index 1448beaeed..c16cdbd211 100644 --- a/commands/live/migrate/migratecmd_test.go +++ b/commands/live/migrate/migratecmd_test.go @@ -20,7 +20,7 @@ import ( "strings" "testing" - rgfilev1alpha1 "github.com/kptdev/kpt/pkg/api/resourcegroup/v1alpha1" + rgfilev1alpha1 "github.com/kptdev/kpt/api/resourcegroup/v1alpha1" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "github.com/kptdev/kpt/pkg/lib/pkg" "github.com/kptdev/kpt/pkg/printer/fake" diff --git a/commands/live/status/cmdstatus_test.go b/commands/live/status/cmdstatus_test.go index 5d90cc8dc4..7e02339236 100644 --- a/commands/live/status/cmdstatus_test.go +++ b/commands/live/status/cmdstatus_test.go @@ -22,8 +22,8 @@ import ( "testing" "time" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/internal/testutil" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "github.com/kptdev/kpt/pkg/printer/fake" "github.com/stretchr/testify/assert" diff --git a/commands/pkg/get/cmdget.go b/commands/pkg/get/cmdget.go index d3b3e61a02..be51172ce7 100644 --- a/commands/pkg/get/cmdget.go +++ b/commands/pkg/get/cmdget.go @@ -20,11 +20,10 @@ import ( "path/filepath" "strings" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" docs "github.com/kptdev/kpt/internal/docs/generated/pkgdocs" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" "github.com/kptdev/kpt/pkg/lib/errors" "github.com/kptdev/kpt/pkg/lib/pkg" - "github.com/kptdev/kpt/pkg/lib/types" argsutil "github.com/kptdev/kpt/pkg/lib/util/args" "github.com/kptdev/kpt/pkg/lib/util/cmdutil" "github.com/kptdev/kpt/pkg/lib/util/get" @@ -104,7 +103,7 @@ func (r *Runner) preRunE(_ *cobra.Command, args []string) error { p, err := pkg.New(filesys.FileSystemOrOnDisk{}, absDestPath) if err != nil { - return errors.E(op, types.UniquePath(t.Destination), err) + return errors.E(op, kptfilev1.UniquePath(t.Destination), err) } r.Get.Destination = string(p.UniquePath) @@ -120,7 +119,7 @@ func (r *Runner) preRunE(_ *cobra.Command, args []string) error { func (r *Runner) runE(_ *cobra.Command, _ []string) error { const op errors.Op = "cmdget.runE" if err := r.Get.Run(r.ctx); err != nil { - return errors.E(op, types.UniquePath(r.Get.Destination), err) + return errors.E(op, kptfilev1.UniquePath(r.Get.Destination), err) } return nil diff --git a/commands/pkg/get/cmdget_test.go b/commands/pkg/get/cmdget_test.go index ee0234b0b9..8c00610c3c 100644 --- a/commands/pkg/get/cmdget_test.go +++ b/commands/pkg/get/cmdget_test.go @@ -23,9 +23,9 @@ import ( "runtime" "testing" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/commands/pkg/get" "github.com/kptdev/kpt/internal/testutil" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" "github.com/kptdev/kpt/pkg/printer/fake" "github.com/spf13/cobra" "github.com/stretchr/testify/assert" diff --git a/commands/pkg/update/cmdupdate.go b/commands/pkg/update/cmdupdate.go index 63939b7409..faa810063f 100644 --- a/commands/pkg/update/cmdupdate.go +++ b/commands/pkg/update/cmdupdate.go @@ -21,11 +21,10 @@ import ( "path/filepath" "strings" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" docs "github.com/kptdev/kpt/internal/docs/generated/pkgdocs" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" "github.com/kptdev/kpt/pkg/lib/errors" "github.com/kptdev/kpt/pkg/lib/pkg" - "github.com/kptdev/kpt/pkg/lib/types" "github.com/kptdev/kpt/pkg/lib/update" argsutil "github.com/kptdev/kpt/pkg/lib/util/args" "github.com/kptdev/kpt/pkg/lib/util/cmdutil" @@ -131,7 +130,7 @@ func (r *Runner) runE(_ *cobra.Command, _ []string) error { return nil } -func resolveRelPath(path types.UniquePath) (string, error) { +func resolveRelPath(path kptfilev1.UniquePath) (string, error) { const op errors.Op = "cmdupdate.resolveRelPath" cwd, err := os.Getwd() if err != nil { diff --git a/commands/pkg/update/cmdupdate_test.go b/commands/pkg/update/cmdupdate_test.go index 4909799d65..cfcef01854 100644 --- a/commands/pkg/update/cmdupdate_test.go +++ b/commands/pkg/update/cmdupdate_test.go @@ -24,12 +24,12 @@ import ( "testing" "text/template" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/commands/pkg/get" "github.com/kptdev/kpt/commands/pkg/update" internalgitutil "github.com/kptdev/kpt/internal/gitutil" "github.com/kptdev/kpt/internal/testutil" "github.com/kptdev/kpt/internal/testutil/pkgbuilder" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" "github.com/kptdev/kpt/pkg/printer/fake" "github.com/spf13/cobra" "github.com/stretchr/testify/assert" diff --git a/go.mod b/go.mod index b0a42ca557..d21afafca3 100644 --- a/go.mod +++ b/go.mod @@ -2,6 +2,8 @@ module github.com/kptdev/kpt go 1.26.3 +replace github.com/kptdev/kpt/api => ./api + require ( github.com/Masterminds/semver/v3 v3.5.0 github.com/bytecodealliance/wasmtime-go v1.0.0 @@ -11,7 +13,8 @@ require ( github.com/google/go-cmp v0.7.0 github.com/google/go-containerregistry v0.21.6 github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 - github.com/kptdev/krm-functions-sdk/go/fn v1.0.2 + github.com/kptdev/kpt/api v0.0.0-00010101000000-000000000000 + github.com/kptdev/krm-functions-sdk/go/fn v1.0.3-0.20260505063812-7c8f2ffba470 github.com/otiai10/copy v1.14.1 github.com/philopon/go-toposort v0.0.0-20170620085441-9be86dbd762f github.com/pkg/errors v0.9.1 @@ -36,7 +39,6 @@ require ( k8s.io/kubectl v0.36.1 sigs.k8s.io/cli-utils v0.37.2 sigs.k8s.io/controller-runtime v0.24.1 - sigs.k8s.io/kustomize/api v0.21.1 sigs.k8s.io/kustomize/kyaml v0.21.1 sigs.k8s.io/yaml v1.6.0 ) @@ -122,6 +124,7 @@ require ( k8s.io/component-helpers v0.36.1 // indirect k8s.io/utils v0.0.0-20260507154919-ff6756f316d2 // indirect sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect + sigs.k8s.io/kustomize/api v0.21.1 // indirect sigs.k8s.io/randfill v1.0.0 // indirect sigs.k8s.io/structured-merge-diff/v6 v6.4.0 // indirect ) diff --git a/go.sum b/go.sum index 8b32c380e9..96859c9d46 100644 --- a/go.sum +++ b/go.sum @@ -110,8 +110,6 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/klauspost/compress v1.18.6 h1:2jupLlAwFm95+YDR+NwD2MEfFO9d4z4Prjl1XXDjuao= github.com/klauspost/compress v1.18.6/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ= -github.com/kptdev/krm-functions-sdk/go/fn v1.0.2 h1:g9N6SW5axEXMagUbHliH14XpfvvvwkAVDLcN3ApVh2M= -github.com/kptdev/krm-functions-sdk/go/fn v1.0.2/go.mod h1:NSfdmtQ9AwNg5wdS9gE/H9SQs7Vomzq7E7N9hyEju1U= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= @@ -275,6 +273,8 @@ k8s.io/component-base v0.36.1 h1:iG6GsELftXqTNG9HG6kiVjatSgAw1sf5pJ6R5a6N0kA= k8s.io/component-base v0.36.1/go.mod h1:nf9XPlntRdqO6WMeEWAA5F93Y4ICZQdeT9GeqLDB3JI= k8s.io/component-helpers v0.36.1 h1:BTrr5fzNSm8TkQfXrKT3N9ioWwiC4n2FTIwGTUo/ccg= k8s.io/component-helpers v0.36.1/go.mod h1:s38HnzKQRurbUnhI5IV8GwyL/a3lVuNCYZMTd+rITMM= +github.com/kptdev/krm-functions-sdk/go/fn v1.0.3-0.20260505063812-7c8f2ffba470 h1:nmoDNbcNlkV86DyJ5cJidd9c44OtCdUaEczvf+G+lw0= +github.com/kptdev/krm-functions-sdk/go/fn v1.0.3-0.20260505063812-7c8f2ffba470/go.mod h1:/VpAcouerwL7ffwirMmmDoWLewnzqtYCrjD0Nl53wPI= k8s.io/klog/v2 v2.140.0 h1:Tf+J3AH7xnUzZyVVXhTgGhEKnFqye14aadWv7bzXdzc= k8s.io/klog/v2 v2.140.0/go.mod h1:o+/RWfJ6PwpnFn7OyAG3QnO47BFsymfEfrz6XyYSSp0= k8s.io/kube-openapi v0.0.0-20260520065146-aa012df4f4af h1:zLXA2Irn14q2/06WMkxViyr7YCPUO2lJ0QYE9Juy5vA= diff --git a/internal/docs/generated/pkgdocs/docs.go b/internal/docs/generated/pkgdocs/docs.go index ce23f2c2b0..5ee997b44d 100644 --- a/internal/docs/generated/pkgdocs/docs.go +++ b/internal/docs/generated/pkgdocs/docs.go @@ -7,27 +7,22 @@ The ` + "`" + `pkg` + "`" + ` command group contains subcommands for fetching, u from git repositories. ` -var CatShort = `Print the contents of a package` +var CatShort = `Print the resources in a file/directory` var CatLong = ` kpt pkg cat [FILE | DIR] Args: FILE | DIR: - Path to a file or a directory containing a kpt package. Displays all - package files: KRM resources (YAML/JSON) are formatted by default, - and non-KRM text files (e.g., README.md) are shown as raw content. - Binary files are skipped. Defaults to the current directory. + Path to a directory either a directory containing files with KRM resources, or + a file with KRM resource(s). Defaults to the current directory. ` var CatExamples = ` - # Print all package contents from current directory. - $ kpt pkg cat - - # Print a single resource file. + # Print resource from a file. $ kpt pkg cat path/to/deployment.yaml - # Print a non-KRM file. - $ kpt pkg cat path/to/README.md + # Print resources from current directory. + $ kpt pkg cat ` var DiffShort = `Show differences between a local package and upstream.` diff --git a/internal/testutil/pkgbuilder/builder.go b/internal/testutil/pkgbuilder/builder.go index 2d72cf8939..b0caf04728 100644 --- a/internal/testutil/pkgbuilder/builder.go +++ b/internal/testutil/pkgbuilder/builder.go @@ -22,8 +22,8 @@ import ( "strconv" "testing" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" - rgfilev1alpha1 "github.com/kptdev/kpt/pkg/api/resourcegroup/v1alpha1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" + rgfilev1alpha1 "github.com/kptdev/kpt/api/resourcegroup/v1alpha1" "github.com/stretchr/testify/assert" "sigs.k8s.io/kustomize/kyaml/yaml" ) diff --git a/internal/testutil/setup_manager.go b/internal/testutil/setup_manager.go index febfdfe304..98c18f417a 100644 --- a/internal/testutil/setup_manager.go +++ b/internal/testutil/setup_manager.go @@ -20,9 +20,9 @@ import ( "path/filepath" "testing" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" internalgitutil "github.com/kptdev/kpt/internal/gitutil" "github.com/kptdev/kpt/internal/testutil/pkgbuilder" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" "github.com/kptdev/kpt/pkg/lib/util/get" "github.com/kptdev/kpt/pkg/printer/fake" "github.com/stretchr/testify/assert" diff --git a/internal/testutil/testutil.go b/internal/testutil/testutil.go index cba750f7b0..d0198d27be 100644 --- a/internal/testutil/testutil.go +++ b/internal/testutil/testutil.go @@ -25,8 +25,8 @@ import ( "strings" "testing" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" internalgitutil "github.com/kptdev/kpt/internal/gitutil" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "github.com/kptdev/kpt/pkg/lib/pkg" "github.com/kptdev/kpt/pkg/lib/util/addmergecomment" diff --git a/make/info.mk b/make/info.mk new file mode 100644 index 0000000000..7c95b9d6ba --- /dev/null +++ b/make/info.mk @@ -0,0 +1,45 @@ +# Copyright 2026 The kpt Authors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +GOLANG_VERSION := 1.26.3 +GOLANGCI_LINT_VERSION := 2.11.4 + +GORELEASER_CONFIG = release/tag/goreleaser.yaml +GORELEASER_IMAGE := ghcr.io/goreleaser/goreleaser-cross:v$(GOLANG_VERSION) + +YEAR_GEN := $(shell date '+%Y') + +GOBIN := $(shell go env GOPATH)/bin +GIT_COMMIT := $(shell git rev-parse --short HEAD) + +export KPT_FN_WASM_RUNTIME ?= nodejs + +LDFLAGS := -ldflags "-X github.com/kptdev/kpt/run.version=${GIT_COMMIT} +ifeq ($(OS),Windows_NT) + # Do nothing +else + UNAME := $(shell uname -s) + ifeq ($(UNAME),Linux) + LDFLAGS += -extldflags '-z noexecstack' + endif +endif +LDFLAGS += " + +# T refers to an e2e test case matcher. This enables running e2e tests +# selectively. For example, +# To invoke e2e tests related to fnconfig, run: +# make test-fn-render T=fnconfig +# make test-fn-eval T=fnconfig +# By default, make test-fn-render/test-fn-eval will run all tests. +T ?= ".*" diff --git a/pkg/fn/eval.go b/pkg/fn/eval.go index af5c159bd8..c88a5b7c18 100644 --- a/pkg/fn/eval.go +++ b/pkg/fn/eval.go @@ -19,7 +19,7 @@ import ( "fmt" "io" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" ) // FunctionRunner knows how to run a function. diff --git a/pkg/fn/eval_test.go b/pkg/fn/eval_test.go index 18e0ad7178..42af5e8fda 100644 --- a/pkg/fn/eval_test.go +++ b/pkg/fn/eval_test.go @@ -19,7 +19,7 @@ import ( "testing" "github.com/google/go-cmp/cmp" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" ) func TestNotFound(t *testing.T) { diff --git a/pkg/fn/multiruntime.go b/pkg/fn/multiruntime.go index 60bb207b83..ee9c48a02a 100644 --- a/pkg/fn/multiruntime.go +++ b/pkg/fn/multiruntime.go @@ -18,7 +18,7 @@ import ( "context" "errors" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" ) // MultiRuntime is a compound FunctionRuntime that will use the first available runner. diff --git a/pkg/fn/render.go b/pkg/fn/render.go index bfb772f7b1..ca6cb0902a 100644 --- a/pkg/fn/render.go +++ b/pkg/fn/render.go @@ -17,7 +17,7 @@ package fn import ( "context" - fnresult "github.com/kptdev/kpt/pkg/api/fnresult/v1" + fnresultv1 "github.com/kptdev/kpt/api/fnresult/v1" "sigs.k8s.io/kustomize/kyaml/filesys" ) @@ -31,5 +31,5 @@ type RenderOptions struct { } type Renderer interface { - Render(ctx context.Context, pkg filesys.FileSystem, opts RenderOptions) (*fnresult.ResultList, error) + Render(ctx context.Context, pkg filesys.FileSystem, opts RenderOptions) (*fnresultv1.ResultList, error) } diff --git a/pkg/fn/runtime/container.go b/pkg/fn/runtime/container.go index d1adbac946..9878ad9b0c 100644 --- a/pkg/fn/runtime/container.go +++ b/pkg/fn/runtime/container.go @@ -28,7 +28,7 @@ import ( "sync" "time" - fnresult "github.com/kptdev/kpt/pkg/api/fnresult/v1" + fnresultv1 "github.com/kptdev/kpt/api/fnresult/v1" "github.com/kptdev/kpt/pkg/lib/runneroptions" "github.com/kptdev/kpt/pkg/printer" "golang.org/x/mod/semver" @@ -95,7 +95,7 @@ type ContainerFn struct { Env []string // FnResult is used to store the information about the result from // the function. - FnResult *fnresult.Result + FnResult *fnresultv1.Result } func (r ContainerRuntime) GetBin() string { diff --git a/pkg/fn/runtime/container_test.go b/pkg/fn/runtime/container_test.go index ad523cfdd6..c606515566 100644 --- a/pkg/fn/runtime/container_test.go +++ b/pkg/fn/runtime/container_test.go @@ -19,12 +19,14 @@ package runtime import ( "bytes" "context" + "fmt" "testing" - fnresult "github.com/kptdev/kpt/pkg/api/fnresult/v1" + fnresultv1 "github.com/kptdev/kpt/api/fnresult/v1" "github.com/kptdev/kpt/pkg/printer" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "sigs.k8s.io/kustomize/kyaml/kio" ) func TestContainerFn(t *testing.T) { @@ -38,7 +40,8 @@ func TestContainerFn(t *testing.T) { { name: "no-op function", image: "ghcr.io/kptdev/krm-functions-catalog/no-op:latest", - output: "apiVersion: v1\nkind: ResourceList\nmetadata:\n name: output\nitems: []\n", + input: fmt.Sprintf("apiVersion: %s\nkind: %s\n", kio.ResourceListAPIVersion, kio.ResourceListKind), // TODO: remove when SDK is fixed + output: fmt.Sprintf("apiVersion: %s\nkind: %s\n", kio.ResourceListAPIVersion, kio.ResourceListKind), }, { name: "non-existing image", @@ -54,7 +57,7 @@ func TestContainerFn(t *testing.T) { instance := ContainerFn{ Ctx: printer.WithContext(ctx, printer.New(nil, errBuff)), Image: tt.image, - FnResult: &fnresult.Result{ + FnResult: &fnresultv1.Result{ Image: tt.image, }, } diff --git a/pkg/fn/runtime/exec.go b/pkg/fn/runtime/exec.go index c3a5e2205f..e5bdf881a3 100644 --- a/pkg/fn/runtime/exec.go +++ b/pkg/fn/runtime/exec.go @@ -23,7 +23,7 @@ import ( "os/exec" "time" - fnresult "github.com/kptdev/kpt/pkg/api/fnresult/v1" + fnresultv1 "github.com/kptdev/kpt/api/fnresult/v1" "github.com/kptdev/kpt/pkg/printer" ) @@ -40,7 +40,7 @@ type ExecFn struct { Timeout time.Duration // FnResult is used to store the information about the result from // the function. - FnResult *fnresult.Result + FnResult *fnresultv1.Result } // Run runs the executable file which reads the input from r and diff --git a/pkg/fn/runtime/nodejs.go b/pkg/fn/runtime/nodejs.go index 420f843098..ed0d9f56b0 100644 --- a/pkg/fn/runtime/nodejs.go +++ b/pkg/fn/runtime/nodejs.go @@ -20,7 +20,7 @@ import ( "os" "path/filepath" - fnresult "github.com/kptdev/kpt/pkg/api/fnresult/v1" + fnresultv1 "github.com/kptdev/kpt/api/fnresult/v1" ) const ( @@ -59,7 +59,7 @@ func NewNodejsFn(loader WasmLoader) (*WasmNodejsFn, error) { Env: map[string]string{ WasmPathEnv: wasmFile, }, - FnResult: &fnresult.Result{}, + FnResult: &fnresultv1.Result{}, }, loader: loader, } diff --git a/pkg/fn/runtime/runner.go b/pkg/fn/runtime/runner.go index d0713575cb..26c3517e03 100644 --- a/pkg/fn/runtime/runner.go +++ b/pkg/fn/runtime/runner.go @@ -26,14 +26,13 @@ import ( "time" "github.com/google/shlex" - fnresultv1 "github.com/kptdev/kpt/pkg/api/fnresult/v1" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + fnresultv1 "github.com/kptdev/kpt/api/fnresult/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/pkg/fn" "github.com/kptdev/kpt/pkg/lib/builtins" "github.com/kptdev/kpt/pkg/lib/errors" "github.com/kptdev/kpt/pkg/lib/pkg" "github.com/kptdev/kpt/pkg/lib/runneroptions" - "github.com/kptdev/kpt/pkg/lib/types" "github.com/kptdev/kpt/pkg/printer" "github.com/regclient/regclient" "sigs.k8s.io/kustomize/kyaml/filesys" @@ -48,7 +47,7 @@ func NewRunner( ctx context.Context, fsys filesys.FileSystem, f *kptfilev1.Function, - pkgPath types.UniquePath, + pkgPath kptfilev1.UniquePath, fnResults *fnresultv1.ResultList, opts runneroptions.RunnerOptions, runtime fn.FunctionRuntime, @@ -188,7 +187,7 @@ func NewRunner( // and it's config. func NewFunctionRunner(ctx context.Context, fltr *runtimeutil.FunctionFilter, - pkgPath types.UniquePath, + pkgPath kptfilev1.UniquePath, fnResult *fnresultv1.Result, fnResults *fnresultv1.ResultList, opts runneroptions.RunnerOptions) (*FunctionRunner, error) { @@ -216,7 +215,7 @@ func NewFunctionRunner(ctx context.Context, type FunctionRunner struct { ctx context.Context name string - pkgPath types.UniquePath + pkgPath kptfilev1.UniquePath disableCLIOutput bool filter *runtimeutil.FunctionFilter fnResult *fnresultv1.Result @@ -316,7 +315,7 @@ func (fr *FunctionRunner) do(input []*yaml.RNode) (output []*yaml.RNode, err err return output, nil } -func setPkgPathAnnotationIfNotExist(resources []*yaml.RNode, pkgPath types.UniquePath) error { +func setPkgPathAnnotationIfNotExist(resources []*yaml.RNode, pkgPath kptfilev1.UniquePath) error { for _, r := range resources { currPkgPath, err := pkg.GetPkgPathAnnotation(r) if err != nil { @@ -506,7 +505,7 @@ func enforcePathInvariants(nodes []*yaml.RNode) error { return nil } -func newFnConfig(fsys filesys.FileSystem, f *kptfilev1.Function, pkgPath types.UniquePath) (*yaml.RNode, error) { +func newFnConfig(fsys filesys.FileSystem, f *kptfilev1.Function, pkgPath kptfilev1.UniquePath) (*yaml.RNode, error) { const op errors.Op = "fn.readConfig" fn := errors.Fn(f.Image) diff --git a/pkg/fn/runtime/runner_test.go b/pkg/fn/runtime/runner_test.go index b8d76acbfa..4d28f76d69 100644 --- a/pkg/fn/runtime/runner_test.go +++ b/pkg/fn/runtime/runner_test.go @@ -24,10 +24,9 @@ import ( "strings" "testing" - fnresultv1 "github.com/kptdev/kpt/pkg/api/fnresult/v1" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + fnresultv1 "github.com/kptdev/kpt/api/fnresult/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/pkg/lib/runneroptions" - "github.com/kptdev/kpt/pkg/lib/types" "github.com/kptdev/kpt/pkg/printer" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -92,7 +91,7 @@ data: {foo: bar} c.fn.ConfigPath = path.Base(tmp.Name()) } fsys := filesys.MakeFsOnDisk() - cn, err := newFnConfig(fsys, &c.fn, types.UniquePath(os.TempDir())) + cn, err := newFnConfig(fsys, &c.fn, kptfilev1.UniquePath(os.TempDir())) assert.NoError(t, err, "unexpected error") actual, err := cn.String() assert.NoError(t, err, "unexpected error") diff --git a/pkg/fn/runtime/utils.go b/pkg/fn/runtime/utils.go index d182b60e1d..f1a48125aa 100644 --- a/pkg/fn/runtime/utils.go +++ b/pkg/fn/runtime/utils.go @@ -19,9 +19,8 @@ import ( "fmt" "path/filepath" - fnresult "github.com/kptdev/kpt/pkg/api/fnresult/v1" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" - "github.com/kptdev/kpt/pkg/lib/types" + fnresultv1 "github.com/kptdev/kpt/api/fnresult/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "sigs.k8s.io/kustomize/kyaml/filesys" "sigs.k8s.io/kustomize/kyaml/yaml" ) @@ -32,7 +31,7 @@ import ( const ResourceIDAnnotation = "internal.config.k8s.io/kpt-resource-id" // SaveResults saves results gathered from running the pipeline at specified dir in the input FileSystem. -func SaveResults(fsys filesys.FileSystem, resultsDir string, fnResults *fnresult.ResultList) (string, error) { +func SaveResults(fsys filesys.FileSystem, resultsDir string, fnResults *fnresultv1.ResultList) (string, error) { if resultsDir == "" { return "", nil } @@ -136,7 +135,7 @@ func DeleteResourceIDs(input []*yaml.RNode) error { } type SelectionContext struct { - RootPackagePath types.UniquePath + RootPackagePath kptfilev1.UniquePath } // SelectInput returns the selected resources based on criteria in selectors diff --git a/pkg/fn/runtime/utils_test.go b/pkg/fn/runtime/utils_test.go index ff6bd0b241..58765cf475 100644 --- a/pkg/fn/runtime/utils_test.go +++ b/pkg/fn/runtime/utils_test.go @@ -17,7 +17,7 @@ package runtime import ( "testing" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/stretchr/testify/assert" "sigs.k8s.io/kustomize/kyaml/yaml" ) diff --git a/pkg/kptfile/kptfileutil/util.go b/pkg/kptfile/kptfileutil/util.go index d9e2216e90..44eabca70a 100644 --- a/pkg/kptfile/kptfileutil/util.go +++ b/pkg/kptfile/kptfileutil/util.go @@ -24,9 +24,8 @@ import ( "slices" "strings" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/pkg/lib/errors" - "github.com/kptdev/kpt/pkg/lib/types" gitutil "github.com/kptdev/kpt/pkg/lib/util/git" "k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/kustomize/kyaml/filesys" @@ -46,7 +45,7 @@ var SupportedKptfileVersions = []schema.GroupVersionKind{ // KptfileError records errors regarding reading or parsing of a Kptfile. type KptfileError struct { - Path types.UniquePath + Path kptfilev1.UniquePath Err error } @@ -83,13 +82,13 @@ func WriteFile(dir string, k any) error { return err } if _, err := os.Stat(filepath.Join(dir, kptfilev1.KptFileName)); err != nil && !goerrors.Is(err, os.ErrNotExist) { - return errors.E(op, errors.IO, types.UniquePath(dir), err) + return errors.E(op, errors.IO, kptfilev1.UniquePath(dir), err) } // fyi: perm is ignored if the file already exists err = os.WriteFile(filepath.Join(dir, kptfilev1.KptFileName), b, 0600) if err != nil { - return errors.E(op, errors.IO, types.UniquePath(dir), err) + return errors.E(op, errors.IO, kptfilev1.UniquePath(dir), err) } return nil } @@ -103,7 +102,7 @@ func WriteKptfileToFS(fs filesys.FileSystem, dir string, k any) error { } err = fs.WriteFile(filepath.Join(dir, kptfilev1.KptFileName), b) if err != nil { - return errors.E(op, errors.IO, types.UniquePath(dir), err) + return errors.E(op, errors.IO, kptfilev1.UniquePath(dir), err) } return nil } @@ -181,7 +180,7 @@ func UpdateKptfileWithoutOrigin(localPath, updatedPath string, updateUpstream bo localKf, err := ReadKptfile(filesys.FileSystemOrOnDisk{}, localPath) if err != nil { if !goerrors.Is(err, os.ErrNotExist) { - return errors.E(op, types.UniquePath(localPath), err) + return errors.E(op, kptfilev1.UniquePath(localPath), err) } localKf = &kptfilev1.KptFile{} } @@ -189,7 +188,7 @@ func UpdateKptfileWithoutOrigin(localPath, updatedPath string, updateUpstream bo updatedKf, err := ReadKptfile(filesys.FileSystemOrOnDisk{}, updatedPath) if err != nil { if !goerrors.Is(err, os.ErrNotExist) { - return errors.E(op, types.UniquePath(updatedPath), err) + return errors.E(op, kptfilev1.UniquePath(updatedPath), err) } updatedKf = &kptfilev1.KptFile{} } @@ -205,7 +204,7 @@ func UpdateKptfileWithoutOrigin(localPath, updatedPath string, updateUpstream bo err = WriteFile(localPath, localKf) if err != nil { - return errors.E(op, types.UniquePath(localPath), err) + return errors.E(op, kptfilev1.UniquePath(localPath), err) } return nil } @@ -220,7 +219,7 @@ func UpdateKptfile(localPath, updatedPath, originPath string, updateUpstream boo localKf, err := ReadKptfile(filesys.FileSystemOrOnDisk{}, localPath) if err != nil { if !goerrors.Is(err, os.ErrNotExist) { - return errors.E(op, types.UniquePath(localPath), err) + return errors.E(op, kptfilev1.UniquePath(localPath), err) } localKf = &kptfilev1.KptFile{} } @@ -228,7 +227,7 @@ func UpdateKptfile(localPath, updatedPath, originPath string, updateUpstream boo updatedKf, err := ReadKptfile(filesys.FileSystemOrOnDisk{}, updatedPath) if err != nil { if !goerrors.Is(err, os.ErrNotExist) { - return errors.E(op, types.UniquePath(localPath), err) + return errors.E(op, kptfilev1.UniquePath(localPath), err) } updatedKf = &kptfilev1.KptFile{} } @@ -236,7 +235,7 @@ func UpdateKptfile(localPath, updatedPath, originPath string, updateUpstream boo originKf, err := ReadKptfile(filesys.FileSystemOrOnDisk{}, originPath) if err != nil { if !goerrors.Is(err, os.ErrNotExist) { - return errors.E(op, types.UniquePath(localPath), err) + return errors.E(op, kptfilev1.UniquePath(localPath), err) } originKf = &kptfilev1.KptFile{} } @@ -252,7 +251,7 @@ func UpdateKptfile(localPath, updatedPath, originPath string, updateUpstream boo err = WriteFile(localPath, localKf) if err != nil { - return errors.E(op, types.UniquePath(localPath), err) + return errors.E(op, kptfilev1.UniquePath(localPath), err) } return nil } @@ -266,7 +265,7 @@ func UpdateUpstreamLockFromGit(path string, spec *gitutil.RepoSpec) error { // read KptFile cloned with the package if it exists kpgfile, err := ReadKptfile(filesys.FileSystemOrOnDisk{}, path) if err != nil { - return errors.E(op, types.UniquePath(path), err) + return errors.E(op, kptfilev1.UniquePath(path), err) } // populate the cloneFrom values so we know where the package came from @@ -281,7 +280,7 @@ func UpdateUpstreamLockFromGit(path string, spec *gitutil.RepoSpec) error { } err = WriteFile(path, kpgfile) if err != nil { - return errors.E(op, types.UniquePath(path), err) + return errors.E(op, kptfilev1.UniquePath(path), err) } return nil } @@ -296,7 +295,7 @@ func ReadKptfile(fs filesys.FileSystem, p string) (*kptfilev1.KptFile, error) { f, err := fs.Open(filepath.Join(p, kptfilev1.KptFileName)) if err != nil { return nil, &KptfileError{ - Path: types.UniquePath(p), + Path: kptfilev1.UniquePath(p), Err: err, } } @@ -305,7 +304,7 @@ func ReadKptfile(fs filesys.FileSystem, p string) (*kptfilev1.KptFile, error) { kf, err := DecodeKptfile(f) if err != nil { return nil, &KptfileError{ - Path: types.UniquePath(p), + Path: kptfilev1.UniquePath(p), Err: err, } } diff --git a/pkg/kptfile/kptfileutil/util_test.go b/pkg/kptfile/kptfileutil/util_test.go index 9d31b348cf..b2961e6e9f 100644 --- a/pkg/kptfile/kptfileutil/util_test.go +++ b/pkg/kptfile/kptfileutil/util_test.go @@ -20,7 +20,7 @@ import ( "strings" "testing" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/stretchr/testify/assert" "sigs.k8s.io/kustomize/kyaml/yaml" ) diff --git a/pkg/kptpkg/init.go b/pkg/kptpkg/init.go index e4a4c41f7c..f4834d4ea4 100644 --- a/pkg/kptpkg/init.go +++ b/pkg/kptpkg/init.go @@ -21,7 +21,7 @@ import ( "path/filepath" "strings" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/pkg/lib/builtins" "github.com/kptdev/kpt/pkg/lib/builtins/builtintypes" "github.com/kptdev/kpt/pkg/lib/pkg" diff --git a/pkg/lib/builtins/pkg_context.go b/pkg/lib/builtins/pkg_context.go index 3f0680d3af..8b8450d969 100644 --- a/pkg/lib/builtins/pkg_context.go +++ b/pkg/lib/builtins/pkg_context.go @@ -25,7 +25,7 @@ import ( "sigs.k8s.io/kustomize/kyaml/resid" "sigs.k8s.io/kustomize/kyaml/yaml" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/pkg/lib/builtins/builtintypes" ) diff --git a/pkg/lib/errors/errors.go b/pkg/lib/errors/errors.go index 9feff62de4..6d25a5177b 100644 --- a/pkg/lib/errors/errors.go +++ b/pkg/lib/errors/errors.go @@ -22,7 +22,7 @@ import ( goerrors "errors" kyaml_errors "github.com/go-errors/errors" - "github.com/kptdev/kpt/pkg/lib/types" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" ) // Error is the type that implements error interface used in the kpt codebase. @@ -35,7 +35,7 @@ import ( // from how it is surfaced to the end users. type Error struct { // Path is the path of the object (pkg, file) involved in kpt operation. - Path types.UniquePath + Path kptfilev1.UniquePath // Op is the operation being performed, for ex. pkg.get, fn.render Op Op @@ -176,7 +176,7 @@ func E(args ...any) error { e := &Error{} for _, arg := range args { switch a := arg.(type) { - case types.UniquePath: + case kptfilev1.UniquePath: e.Path = a case Op: e.Op = a diff --git a/pkg/lib/errors/errors_test.go b/pkg/lib/errors/errors_test.go index 75dd492c4c..6048896c72 100644 --- a/pkg/lib/errors/errors_test.go +++ b/pkg/lib/errors/errors_test.go @@ -19,7 +19,7 @@ import ( "strings" "testing" - "github.com/kptdev/kpt/pkg/lib/types" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" ) func TestErrorFormatting(t *testing.T) { @@ -27,7 +27,7 @@ func TestErrorFormatting(t *testing.T) { e := &Error{ Op: "pkg.get", - Path: types.UniquePath("/workspace/my-pkg"), + Path: kptfilev1.UniquePath("/workspace/my-pkg"), Fn: "my-fn", Repo: "github.com/example/repo", Class: InvalidParam, diff --git a/pkg/lib/errors/resolver/pkg.go b/pkg/lib/errors/resolver/pkg.go index 35eeaa0f68..af0e7edf28 100644 --- a/pkg/lib/errors/resolver/pkg.go +++ b/pkg/lib/errors/resolver/pkg.go @@ -18,7 +18,7 @@ import ( "fmt" "os" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "github.com/kptdev/kpt/pkg/lib/errors" "github.com/kptdev/kpt/pkg/lib/pkg" diff --git a/pkg/lib/kptops/clone.go b/pkg/lib/kptops/clone.go index 0cd51c402b..2e61f19593 100644 --- a/pkg/lib/kptops/clone.go +++ b/pkg/lib/kptops/clone.go @@ -19,7 +19,7 @@ import ( "fmt" "strings" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "sigs.k8s.io/kustomize/kyaml/yaml" ) diff --git a/pkg/lib/kptops/clone_test.go b/pkg/lib/kptops/clone_test.go index d2123bbfbc..0a54916ec6 100644 --- a/pkg/lib/kptops/clone_test.go +++ b/pkg/lib/kptops/clone_test.go @@ -17,7 +17,7 @@ package kptops import ( "testing" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" ) const exampleRepoURL = "https://github.com/example/repo.git" diff --git a/pkg/lib/kptops/helpers_test.go b/pkg/lib/kptops/helpers_test.go index 45331567f7..af9dfbb9ab 100644 --- a/pkg/lib/kptops/helpers_test.go +++ b/pkg/lib/kptops/helpers_test.go @@ -25,7 +25,7 @@ import ( "io" "maps" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/pkg/fn" "sigs.k8s.io/kustomize/kyaml/fn/framework" "sigs.k8s.io/kustomize/kyaml/kio" diff --git a/pkg/lib/kptops/hook_executor.go b/pkg/lib/kptops/hook_executor.go index e01dcadb86..71a45afd0a 100644 --- a/pkg/lib/kptops/hook_executor.go +++ b/pkg/lib/kptops/hook_executor.go @@ -19,13 +19,12 @@ import ( "fmt" "io" - fnresult "github.com/kptdev/kpt/pkg/api/fnresult/v1" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + fnresultv1 "github.com/kptdev/kpt/api/fnresult/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/pkg/fn" fnruntime "github.com/kptdev/kpt/pkg/fn/runtime" "github.com/kptdev/kpt/pkg/lib/pkg" "github.com/kptdev/kpt/pkg/lib/runneroptions" - "github.com/kptdev/kpt/pkg/lib/types" "sigs.k8s.io/kustomize/kyaml/filesys" "sigs.k8s.io/kustomize/kyaml/kio" ) @@ -49,12 +48,12 @@ type Executor struct { // fnResults stores function results gathered // during pipeline execution. - fnResults *fnresult.ResultList + fnResults *fnresultv1.ResultList } // Execute executes given hook. func (e *Executor) Execute(ctx context.Context, hook []kptfilev1.Function) error { - e.fnResults = fnresult.NewResultList() + e.fnResults = fnresultv1.NewResultList() pkgReaderWriter := &kio.LocalPackageReadWriter{ PackagePath: e.PkgPath, @@ -91,7 +90,7 @@ func (e *Executor) fnChain(ctx context.Context, fns []kptfilev1.Function) ([]kio runner, err = fnruntime.NewRunner(ctx, e.FileSystem, &fn, - types.UniquePath(e.PkgPath), + kptfilev1.UniquePath(e.PkgPath), e.fnResults, opts, e.Runtime) diff --git a/pkg/lib/kptops/pkgupdate.go b/pkg/lib/kptops/pkgupdate.go index 9f8aa18aec..6cf238bf25 100644 --- a/pkg/lib/kptops/pkgupdate.go +++ b/pkg/lib/kptops/pkgupdate.go @@ -20,7 +20,7 @@ import ( "os" "path/filepath" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "github.com/kptdev/kpt/pkg/lib/update" "github.com/kptdev/kpt/pkg/lib/update/updatetypes" diff --git a/pkg/lib/kptops/render.go b/pkg/lib/kptops/render.go index 260c619c8a..6c7dd2dc75 100644 --- a/pkg/lib/kptops/render.go +++ b/pkg/lib/kptops/render.go @@ -20,7 +20,7 @@ import ( "io" "os" - fnresult "github.com/kptdev/kpt/pkg/api/fnresult/v1" + fnresultv1 "github.com/kptdev/kpt/api/fnresult/v1" "github.com/kptdev/kpt/pkg/fn" "github.com/kptdev/kpt/pkg/lib/pkg" "github.com/kptdev/kpt/pkg/lib/runneroptions" @@ -39,7 +39,7 @@ type renderer struct { var _ fn.Renderer = &renderer{} -func (r *renderer) Render(ctx context.Context, pkg filesys.FileSystem, opts fn.RenderOptions) (*fnresult.ResultList, error) { +func (r *renderer) Render(ctx context.Context, pkg filesys.FileSystem, opts fn.RenderOptions) (*fnresultv1.ResultList, error) { rr := Renderer{ PkgPath: opts.PkgPath, Runtime: opts.Runtime, diff --git a/pkg/lib/kptops/render_executor.go b/pkg/lib/kptops/render_executor.go index 0c3e574be1..ce7189acff 100644 --- a/pkg/lib/kptops/render_executor.go +++ b/pkg/lib/kptops/render_executor.go @@ -23,15 +23,14 @@ import ( "slices" "strings" - fnresult "github.com/kptdev/kpt/pkg/api/fnresult/v1" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + fnresultv1 "github.com/kptdev/kpt/api/fnresult/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/pkg/fn" fnruntime "github.com/kptdev/kpt/pkg/fn/runtime" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "github.com/kptdev/kpt/pkg/lib/errors" "github.com/kptdev/kpt/pkg/lib/pkg" "github.com/kptdev/kpt/pkg/lib/runneroptions" - "github.com/kptdev/kpt/pkg/lib/types" "github.com/kptdev/kpt/pkg/lib/util/attribution" "github.com/kptdev/kpt/pkg/printer" "k8s.io/klog/v2" @@ -57,7 +56,7 @@ type Renderer struct { ResultsDirPath string // fnResultsList is the list of results from the pipeline execution - fnResultsList *fnresult.ResultList + fnResultsList *fnresultv1.ResultList // Output is the writer to which the output resources are written Output io.Writer @@ -73,22 +72,22 @@ type Renderer struct { } // Execute runs a pipeline. -func (e *Renderer) Execute(ctx context.Context) (*fnresult.ResultList, error) { +func (e *Renderer) Execute(ctx context.Context) (*fnresultv1.ResultList, error) { const op errors.Op = "fn.render" pr := printer.FromContextOrDie(ctx) root, err := newPkgNode(e.FileSystem, e.PkgPath, nil) if err != nil { - return nil, errors.E(op, types.UniquePath(e.PkgPath), err) + return nil, errors.E(op, kptfilev1.UniquePath(e.PkgPath), err) } // initialize hydration context hctx := &hydrationContext{ root: root, rootName: e.DisplayName, - pkgs: map[types.UniquePath]*pkgNode{}, - fnResults: fnresult.NewResultList(), + pkgs: map[kptfilev1.UniquePath]*pkgNode{}, + fnResults: fnresultv1.NewResultList(), runnerOptions: e.RunnerOptions, fileSystem: e.FileSystem, runtime: e.Runtime, @@ -300,7 +299,7 @@ func setRenderStatus(fs filesys.FileSystem, pkgPath string, condition kptfilev1. } } -func (e *Renderer) saveFnResults(ctx context.Context, fnResults *fnresult.ResultList) error { +func (e *Renderer) saveFnResults(ctx context.Context, fnResults *fnresultv1.ResultList) error { e.fnResultsList = fnResults resultsFile, err := fnruntime.SaveResults(e.FileSystem, e.ResultsDirPath, fnResults) if err != nil { @@ -320,7 +319,7 @@ type hydrationContext struct { // pkgs refers to the packages undergoing hydration. pkgs are key'd by their // unique paths. - pkgs map[types.UniquePath]*pkgNode + pkgs map[kptfilev1.UniquePath]*pkgNode // inputFiles is a set of filepaths containing input resources to the // functions across all the packages during hydration. @@ -336,7 +335,7 @@ type hydrationContext struct { // fnResults stores function results gathered // during pipeline execution. - fnResults *fnresult.ResultList + fnResults *fnresultv1.ResultList // saveOnRenderFailure indicates whether partially rendered resources // should be saved when rendering fails. Read from the root Kptfile annotation. @@ -529,10 +528,10 @@ func hydrateBfsOrder(ctx context.Context, root *pkgNode, hctx *hydrationContext) // discoverAndLoadPackages performs a Breadth-First search trasversal to // discover all packages, build tree structure and load their local resources. -func discoverAndLoadPackages(root *pkgNode, hctx *hydrationContext) ([]*pkgNode, map[types.UniquePath][]*pkgNode, error) { +func discoverAndLoadPackages(root *pkgNode, hctx *hydrationContext) ([]*pkgNode, map[kptfilev1.UniquePath][]*pkgNode, error) { queue := []*pkgNode{root} var allNodes []*pkgNode - childrenMap := map[types.UniquePath][]*pkgNode{} + childrenMap := map[kptfilev1.UniquePath][]*pkgNode{} for len(queue) > 0 { current := queue[0] @@ -618,7 +617,7 @@ func processSubpackages(current *pkgNode, hctx *hydrationContext) ([]*pkgNode, e // executePipelinesWithScopedVisibility executes pipelines for all packages in top-down order // Each package can see itself plus its descendants (children, granchildren) only -func executePipelinesWithScopedVisibility(ctx context.Context, allNodes []*pkgNode, childrenMap map[types.UniquePath][]*pkgNode, hctx *hydrationContext) error { +func executePipelinesWithScopedVisibility(ctx context.Context, allNodes []*pkgNode, childrenMap map[kptfilev1.UniquePath][]*pkgNode, hctx *hydrationContext) error { for _, node := range allNodes { node.state = Hydrating hctx.pkgs[node.pkg.UniquePath] = node @@ -690,7 +689,7 @@ func aggregateRootResources(allNodes []*pkgNode, hctx *hydrationContext) { // buildPipelineInputWithScopedVisibility creates the input resource // list for a package's pipeline using childrenMap to find descendants -func buildPipelineInputWithScopedVisibility(node *pkgNode, childrenMap map[types.UniquePath][]*pkgNode) []*yaml.RNode { +func buildPipelineInputWithScopedVisibility(node *pkgNode, childrenMap map[kptfilev1.UniquePath][]*pkgNode) []*yaml.RNode { var input []*yaml.RNode input = append(input, node.resources...) @@ -983,7 +982,7 @@ func pathRelToRoot(rootPkgPath, subPkgPath, resourcePath string) (relativePath s } // fnChain returns a slice of function runners given a list of functions defined in pipeline. -func fnChain(ctx context.Context, hctx *hydrationContext, pkgPath types.UniquePath, fns []kptfilev1.Function) ([]*fnruntime.FunctionRunner, int, error) { +func fnChain(ctx context.Context, hctx *hydrationContext, pkgPath kptfilev1.UniquePath, fns []kptfilev1.Function) ([]*fnruntime.FunctionRunner, int, error) { var runners []*fnruntime.FunctionRunner for i := range fns { var err error @@ -1053,7 +1052,7 @@ func pruneResources(fsys filesys.FileSystem, hctx *hydrationContext) error { // captureStepResult builds a PipelineStepResult from the fnresult.Result items // appended since resultCountBeforeExec. -func captureStepResult(fn kptfilev1.Function, fnResults *fnresult.ResultList, resultCountBeforeExec int, execErr error) kptfilev1.PipelineStepResult { +func captureStepResult(fn kptfilev1.Function, fnResults *fnresultv1.ResultList, resultCountBeforeExec int, execErr error) kptfilev1.PipelineStepResult { step := kptfilev1.PipelineStepResult{ Name: fn.Name, Image: fn.Image, diff --git a/pkg/lib/kptops/render_executor_test.go b/pkg/lib/kptops/render_executor_test.go index 87c4c0fedd..a0310eb114 100644 --- a/pkg/lib/kptops/render_executor_test.go +++ b/pkg/lib/kptops/render_executor_test.go @@ -22,12 +22,11 @@ import ( "strings" "testing" - fnresultv1 "github.com/kptdev/kpt/pkg/api/fnresult/v1" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + fnresultv1 "github.com/kptdev/kpt/api/fnresult/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" fnruntime "github.com/kptdev/kpt/pkg/fn/runtime" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "github.com/kptdev/kpt/pkg/lib/pkg" - "github.com/kptdev/kpt/pkg/lib/types" "github.com/kptdev/kpt/pkg/printer" "github.com/stretchr/testify/assert" "sigs.k8s.io/kustomize/kyaml/filesys" @@ -373,7 +372,7 @@ metadata: hctx := &hydrationContext{ root: root, - pkgs: map[types.UniquePath]*pkgNode{}, + pkgs: map[kptfilev1.UniquePath]*pkgNode{}, fileSystem: mockFileSystem, } @@ -444,7 +443,7 @@ metadata: hctx := &hydrationContext{ root: root, - pkgs: map[types.UniquePath]*pkgNode{}, + pkgs: map[kptfilev1.UniquePath]*pkgNode{}, fileSystem: mockFileSystem, } @@ -507,7 +506,7 @@ metadata: } hctx := &hydrationContext{ root: root, - pkgs: map[types.UniquePath]*pkgNode{}, + pkgs: map[kptfilev1.UniquePath]*pkgNode{}, fileSystem: mockFileSystem, } @@ -563,12 +562,12 @@ func TestRenderer_PrintPipelineExecutionSummary(t *testing.T) { hctx := hydrationContext{ executedFunctionCnt: tc.executedFunctionCnt, - pkgs: make(map[types.UniquePath]*pkgNode, tc.pkgCount), + pkgs: make(map[kptfilev1.UniquePath]*pkgNode, tc.pkgCount), } // Populate pkgs map with dummy entries for i := 0; i < tc.pkgCount; i++ { - hctx.pkgs[types.UniquePath(fmt.Sprintf("/pkg%d", i))] = &pkgNode{} + hctx.pkgs[kptfilev1.UniquePath(fmt.Sprintf("/pkg%d", i))] = &pkgNode{} } renderer.printPipelineExecutionSummary(pr, hctx, tc.hydErr) @@ -595,7 +594,7 @@ metadata: hctx := &hydrationContext{ root: &pkgNode{pkg: rootPkg}, - pkgs: map[types.UniquePath]*pkgNode{}, + pkgs: map[kptfilev1.UniquePath]*pkgNode{}, fileSystem: mockFS, } hctx.pkgs[rootPkg.UniquePath] = &pkgNode{pkg: rootPkg} @@ -628,7 +627,7 @@ metadata: hctx := &hydrationContext{ root: &pkgNode{pkg: rootPkg}, - pkgs: map[types.UniquePath]*pkgNode{}, + pkgs: map[kptfilev1.UniquePath]*pkgNode{}, fileSystem: mockFS, } hctx.pkgs[rootPkg.UniquePath] = &pkgNode{pkg: rootPkg} @@ -668,7 +667,7 @@ status: hctx := &hydrationContext{ root: &pkgNode{pkg: rootPkg}, - pkgs: map[types.UniquePath]*pkgNode{}, + pkgs: map[kptfilev1.UniquePath]*pkgNode{}, fileSystem: mockFS, } hctx.pkgs[rootPkg.UniquePath] = &pkgNode{pkg: rootPkg} @@ -712,7 +711,7 @@ metadata: hctx := &hydrationContext{ root: &pkgNode{pkg: rootPkg}, - pkgs: map[types.UniquePath]*pkgNode{}, + pkgs: map[kptfilev1.UniquePath]*pkgNode{}, fileSystem: mockFS, } hctx.pkgs[rootPkg.UniquePath] = &pkgNode{pkg: rootPkg} @@ -883,7 +882,7 @@ metadata: hctx := &hydrationContext{ root: &pkgNode{pkg: rootPkg}, - pkgs: map[types.UniquePath]*pkgNode{}, + pkgs: map[kptfilev1.UniquePath]*pkgNode{}, fileSystem: mockFS, mutationSteps: []kptfilev1.PipelineStepResult{ {Image: "set-namespace:v1", ExitCode: 0}, @@ -929,7 +928,7 @@ metadata: hctx := &hydrationContext{ root: &pkgNode{pkg: rootPkg}, - pkgs: map[types.UniquePath]*pkgNode{}, + pkgs: map[kptfilev1.UniquePath]*pkgNode{}, fileSystem: mockFS, } @@ -958,7 +957,7 @@ metadata: // First render: failure with steps hctx := &hydrationContext{ root: &pkgNode{pkg: rootPkg}, - pkgs: map[types.UniquePath]*pkgNode{}, + pkgs: map[kptfilev1.UniquePath]*pkgNode{}, fileSystem: mockFS, mutationSteps: []kptfilev1.PipelineStepResult{ {Image: "bad:v1", ExitCode: 1}, @@ -973,7 +972,7 @@ metadata: // Second render: success with no steps (empty pipeline) hctx2 := &hydrationContext{ root: &pkgNode{pkg: rootPkg}, - pkgs: map[types.UniquePath]*pkgNode{}, + pkgs: map[kptfilev1.UniquePath]*pkgNode{}, fileSystem: mockFS, } updateRenderStatus(hctx2, nil) diff --git a/pkg/lib/pkg/diff/diff.go b/pkg/lib/pkg/diff/diff.go index c61b12825f..b285fe2595 100644 --- a/pkg/lib/pkg/diff/diff.go +++ b/pkg/lib/pkg/diff/diff.go @@ -24,8 +24,8 @@ import ( "path/filepath" "strings" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" internalgitutil "github.com/kptdev/kpt/internal/gitutil" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "github.com/kptdev/kpt/pkg/lib/pkg" "github.com/kptdev/kpt/pkg/lib/util/addmergecomment" diff --git a/pkg/lib/pkg/diff/pkgdiff.go b/pkg/lib/pkg/diff/pkgdiff.go index 5049921c56..31a8b2b230 100644 --- a/pkg/lib/pkg/diff/pkgdiff.go +++ b/pkg/lib/pkg/diff/pkgdiff.go @@ -19,7 +19,7 @@ import ( "os" "path/filepath" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "github.com/kptdev/kpt/pkg/lib/pkg" "github.com/kptdev/kpt/pkg/lib/util/attribution" diff --git a/pkg/lib/pkg/pkg.go b/pkg/lib/pkg/pkg.go index 27710ec2f3..6bdf7e0b31 100644 --- a/pkg/lib/pkg/pkg.go +++ b/pkg/lib/pkg/pkg.go @@ -25,11 +25,10 @@ import ( "sort" "strings" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" - rgfilev1alpha1 "github.com/kptdev/kpt/pkg/api/resourcegroup/v1alpha1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" + rgfilev1alpha1 "github.com/kptdev/kpt/api/resourcegroup/v1alpha1" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "github.com/kptdev/kpt/pkg/lib/errors" - "github.com/kptdev/kpt/pkg/lib/types" gitutil "github.com/kptdev/kpt/pkg/lib/util/git" pathutil "github.com/kptdev/kpt/pkg/lib/util/path" regclientref "github.com/regclient/regclient/types/ref" @@ -69,7 +68,7 @@ func (e *RemoteKptfileError) Unwrap() error { // RGError is an implementation of the error interface that is returned whenever // kpt encounters errors reading a resourcegroup object file. type RGError struct { - Path types.UniquePath + Path kptfilev1.UniquePath Err error } @@ -131,14 +130,14 @@ type Pkg struct { fsys filesys.FileSystem // UniquePath represents absolute unique OS-defined path to the package directory on the filesystem. - UniquePath types.UniquePath + UniquePath kptfilev1.UniquePath // DisplayPath represents Slash-separated path to the package directory on the filesystem relative // to parent directory of root package on which the command is invoked. // root package is defined as the package on which the command is invoked by user // This is not guaranteed to be unique (e.g. in presence of symlinks) and should only // be used for display purposes and is subject to change. - DisplayPath types.DisplayPath + DisplayPath kptfilev1.DisplayPath // rootPkgParentDirPath is the absolute path to the parent directory of root package, // root package is defined as the package on which the command is invoked by user @@ -162,11 +161,11 @@ func New(fs filesys.FileSystem, path string) (*Pkg, error) { absPath := filepath.Clean(path) pkg := &Pkg{ fsys: fs, - UniquePath: types.UniquePath(absPath), + UniquePath: kptfilev1.UniquePath(absPath), // by default, rootPkgParentDirPath should be the absolute path to the parent directory of package being instantiated rootPkgParentDirPath: filepath.Dir(absPath), // by default, DisplayPath should be the package name which is same as directory name - DisplayPath: types.DisplayPath(filepath.Base(absPath)), + DisplayPath: kptfilev1.DisplayPath(filepath.Base(absPath)), } return pkg, nil } @@ -257,7 +256,7 @@ func (p *Pkg) adjustDisplayPathForSubpkg(subPkg *Pkg) error { return err } // make sure that the DisplayPath is always Slash-separated os-agnostic - subPkg.DisplayPath = types.DisplayPath(filepath.ToSlash(dp)) + subPkg.DisplayPath = kptfilev1.DisplayPath(filepath.ToSlash(dp)) return nil } @@ -322,7 +321,7 @@ func Subpackages(fsys filesys.FileSystem, rootPath string, matcher SubpackageMat if isPkg { kf, err := kptfileutil.ReadKptfile(fsys, path) if err != nil { - return errors.E(op, types.UniquePath(path), err) + return errors.E(op, kptfilev1.UniquePath(path), err) } switch matcher { case Local: @@ -506,7 +505,7 @@ func GetPkgPathAnnotation(rn *yaml.RNode) (string, error) { } // SetPkgPathAnnotation sets package path on a given resource. -func SetPkgPathAnnotation(rn *yaml.RNode, pkgPath types.UniquePath) error { +func SetPkgPathAnnotation(rn *yaml.RNode, pkgPath kptfilev1.UniquePath) error { return rn.PipeE(yaml.SetAnnotation(pkgPathAnnotation, string(pkgPath))) } @@ -541,7 +540,7 @@ func ReadRGFile(pkgPath, rgfile string) (*rgfilev1alpha1.ResourceGroup, error) { rgFilePath, _, err := pathutil.ResolveAbsAndRelPaths(rgfile) if err != nil { return nil, &RGError{ - Path: types.UniquePath(rgfile), + Path: kptfilev1.UniquePath(rgfile), Err: err, } } @@ -552,7 +551,7 @@ func ReadRGFile(pkgPath, rgfile string) (*rgfilev1alpha1.ResourceGroup, error) { f, err := os.Open(absPath) if err != nil { return nil, &RGError{ - Path: types.UniquePath(absPath), + Path: kptfilev1.UniquePath(absPath), Err: err, } } @@ -561,7 +560,7 @@ func ReadRGFile(pkgPath, rgfile string) (*rgfilev1alpha1.ResourceGroup, error) { rg, err := DecodeRGFile(f) if err != nil { return nil, &RGError{ - Path: types.UniquePath(absPath), + Path: kptfilev1.UniquePath(absPath), Err: err, } } diff --git a/pkg/lib/pkg/pkg_test.go b/pkg/lib/pkg/pkg_test.go index f5a4b70843..1d12ca72a7 100644 --- a/pkg/lib/pkg/pkg_test.go +++ b/pkg/lib/pkg/pkg_test.go @@ -22,8 +22,8 @@ import ( "sort" "testing" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/internal/testutil/pkgbuilder" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" pathutil "github.com/kptdev/kpt/pkg/lib/util/path" "github.com/stretchr/testify/assert" "sigs.k8s.io/kustomize/kyaml/filesys" diff --git a/pkg/lib/pkg/util.go b/pkg/lib/pkg/util.go index dd7fb28d73..077e51923d 100644 --- a/pkg/lib/pkg/util.go +++ b/pkg/lib/pkg/util.go @@ -22,7 +22,7 @@ import ( "sort" "strings" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "sigs.k8s.io/kustomize/kyaml/copyutil" "sigs.k8s.io/kustomize/kyaml/filesys" diff --git a/pkg/lib/pkg/util_test.go b/pkg/lib/pkg/util_test.go index 35802ab0a7..9613b37225 100644 --- a/pkg/lib/pkg/util_test.go +++ b/pkg/lib/pkg/util_test.go @@ -20,9 +20,9 @@ import ( "sort" "testing" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/internal/testutil" "github.com/kptdev/kpt/internal/testutil/pkgbuilder" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" . "github.com/kptdev/kpt/pkg/lib/pkg" "github.com/stretchr/testify/assert" ) diff --git a/pkg/lib/update/common.go b/pkg/lib/update/common.go index 0de48039e2..3a04722f3b 100644 --- a/pkg/lib/update/common.go +++ b/pkg/lib/update/common.go @@ -17,9 +17,9 @@ package update import ( "reflect" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "github.com/kptdev/kpt/pkg/lib/errors" - "github.com/kptdev/kpt/pkg/lib/types" "sigs.k8s.io/kustomize/kyaml/filesys" ) @@ -29,12 +29,12 @@ func PkgHasUpdatedUpstream(local, origin string) (bool, error) { const op errors.Op = "update.PkgHasUpdatedUpstream" originKf, err := kptfileutil.ReadKptfile(filesys.FileSystemOrOnDisk{}, origin) if err != nil { - return false, errors.E(op, types.UniquePath(local), err) + return false, errors.E(op, kptfilev1.UniquePath(local), err) } localKf, err := kptfileutil.ReadKptfile(filesys.FileSystemOrOnDisk{}, local) if err != nil { - return false, errors.E(op, types.UniquePath(local), err) + return false, errors.E(op, kptfilev1.UniquePath(local), err) } // If the upstream information in local has changed from origin, it diff --git a/pkg/lib/update/copy-merge.go b/pkg/lib/update/copy-merge.go index c7d6e5b783..3bbedf5062 100644 --- a/pkg/lib/update/copy-merge.go +++ b/pkg/lib/update/copy-merge.go @@ -15,10 +15,10 @@ package update import ( + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "github.com/kptdev/kpt/pkg/lib/errors" "github.com/kptdev/kpt/pkg/lib/pkg" - "github.com/kptdev/kpt/pkg/lib/types" "github.com/kptdev/kpt/pkg/lib/update/updatetypes" ) @@ -41,13 +41,13 @@ func (u CopyMergeUpdater) Update(options updatetypes.Options) error { org := options.OriginPath if err := kptfileutil.UpdateKptfile(dst, src, options.OriginPath, true); err != nil { - return errors.E(op, types.UniquePath(dst), err) + return errors.E(op, kptfilev1.UniquePath(dst), err) } if err := pkg.CopyPackage(src, dst, options.IsRoot, pkg.All); err != nil { - return errors.E(op, types.UniquePath(dst), err) + return errors.E(op, kptfilev1.UniquePath(dst), err) } if err := pkg.RemoveStaleItems(org, src, dst, options.IsRoot, pkg.All); err != nil { - return errors.E(op, types.UniquePath(dst), err) + return errors.E(op, kptfilev1.UniquePath(dst), err) } return nil } diff --git a/pkg/lib/update/fastforward.go b/pkg/lib/update/fastforward.go index fd43a24cec..8ac6843ec1 100644 --- a/pkg/lib/update/fastforward.go +++ b/pkg/lib/update/fastforward.go @@ -20,12 +20,11 @@ import ( "path/filepath" "slices" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "github.com/kptdev/kpt/pkg/lib/errors" "github.com/kptdev/kpt/pkg/lib/pkg" "github.com/kptdev/kpt/pkg/lib/pkg/diff" - "github.com/kptdev/kpt/pkg/lib/types" "github.com/kptdev/kpt/pkg/lib/update/updatetypes" "sigs.k8s.io/kustomize/kyaml/filesys" "sigs.k8s.io/kustomize/kyaml/sets" @@ -51,21 +50,21 @@ func (u FastForwardUpdater) Update(options updatetypes.Options) error { // Verify that there are no local changes that would prevent us from // using the FastForward strategy. if err := u.checkForLocalChanges(options.LocalPath, options.OriginPath); err != nil { - return errors.E(op, types.UniquePath(options.LocalPath), err) + return errors.E(op, kptfilev1.UniquePath(options.LocalPath), err) } if err := (&ReplaceUpdater{}).Update(options); err != nil { - return errors.E(op, types.UniquePath(options.LocalPath), err) + return errors.E(op, kptfilev1.UniquePath(options.LocalPath), err) } // Remove stale render status from the updated local Kptfile. localKf, err := kptfileutil.ReadKptfile(filesys.FileSystemOrOnDisk{}, options.LocalPath) if err != nil { - return errors.E(op, types.UniquePath(options.LocalPath), err) + return errors.E(op, kptfilev1.UniquePath(options.LocalPath), err) } clearRenderStatus(localKf) if err := kptfileutil.WriteFile(options.LocalPath, localKf); err != nil { - return errors.E(op, types.UniquePath(options.LocalPath), err) + return errors.E(op, kptfilev1.UniquePath(options.LocalPath), err) } return nil } @@ -74,7 +73,7 @@ func (u FastForwardUpdater) checkForLocalChanges(localPath, originalPath string) const op errors.Op = "update.checkForLocalChanges" found, err := pkg.Exists(originalPath) if err != nil { - return errors.E(op, types.UniquePath(localPath), err) + return errors.E(op, kptfilev1.UniquePath(localPath), err) } if !found { return nil @@ -82,7 +81,7 @@ func (u FastForwardUpdater) checkForLocalChanges(localPath, originalPath string) subPkgPaths, err := pkg.FindSubpackagesForPaths(pkg.Local, true, localPath, originalPath) if err != nil { - return errors.E(op, types.UniquePath(localPath), err) + return errors.E(op, kptfilev1.UniquePath(localPath), err) } aggDiff := sets.String{} for _, subPkgPath := range append([]string{"."}, subPkgPaths...) { @@ -91,11 +90,11 @@ func (u FastForwardUpdater) checkForLocalChanges(localPath, originalPath string) localExists, err := pkg.Exists(localSubPkgPath) if err != nil { - return errors.E(op, types.UniquePath(localSubPkgPath), err) + return errors.E(op, kptfilev1.UniquePath(localSubPkgPath), err) } originalExists, err := pkg.Exists(originalSubPkgPath) if err != nil { - return errors.E(op, types.UniquePath(localSubPkgPath), err) + return errors.E(op, kptfilev1.UniquePath(localSubPkgPath), err) } if !originalExists || !localExists { aggDiff.Insert("%s (Package)", subPkgPath) @@ -103,7 +102,7 @@ func (u FastForwardUpdater) checkForLocalChanges(localPath, originalPath string) } d, err := diff.PkgDiff(localSubPkgPath, originalSubPkgPath) if err != nil { - return errors.E(op, types.UniquePath(localSubPkgPath), err) + return errors.E(op, kptfilev1.UniquePath(localSubPkgPath), err) } // If the original package didn't have a Kptfile, one was created // in local, but we don't consider that a change unless the user @@ -111,7 +110,7 @@ func (u FastForwardUpdater) checkForLocalChanges(localPath, originalPath string) if d.Has(kptfilev1.KptFileName) && subPkgPath == "." { hasDiff, err := hasKfDiff(localSubPkgPath, originalSubPkgPath) if err != nil { - return errors.E(op, types.UniquePath(localSubPkgPath), err) + return errors.E(op, kptfilev1.UniquePath(localSubPkgPath), err) } if !hasDiff { d = d.Difference(kptfileSet) @@ -121,7 +120,7 @@ func (u FastForwardUpdater) checkForLocalChanges(localPath, originalPath string) aggDiff.Insert(d.List()...) } if aggDiff.Len() > 0 { - return errors.E(op, types.UniquePath(localPath), fmt.Sprintf( + return errors.E(op, kptfilev1.UniquePath(localPath), fmt.Sprintf( "local package files have been modified: %v.\n use a different update --strategy.", aggDiff.List())) } @@ -132,7 +131,7 @@ func hasKfDiff(localPath, orgPath string) (bool, error) { const op errors.Op = "update.hasKfDiff" localKf, err := kptfileutil.ReadKptfile(filesys.FileSystemOrOnDisk{}, localPath) if err != nil { - return false, errors.E(op, types.UniquePath(localPath), err) + return false, errors.E(op, kptfilev1.UniquePath(localPath), err) } localKf.Upstream = nil localKf.UpstreamLock = nil @@ -146,22 +145,22 @@ func hasKfDiff(localPath, orgPath string) (bool, error) { // is just the minimal Kptfile generated automatically. isDefault, err := isDefaultKptfile(localKf, filepath.Base(localPath)) if err != nil { - return false, errors.E(op, types.UniquePath(localPath), err) + return false, errors.E(op, kptfilev1.UniquePath(localPath), err) } return !isDefault, nil } - return false, errors.E(op, types.UniquePath(localPath), err) + return false, errors.E(op, kptfilev1.UniquePath(localPath), err) } orgKf, err := kptfileutil.ReadKptfile(filesys.FileSystemOrOnDisk{}, orgPath) if err != nil { - return false, errors.E(op, types.UniquePath(localPath), err) + return false, errors.E(op, kptfilev1.UniquePath(localPath), err) } clearRenderStatus(orgKf) orgKf.Name = localKf.Name equal, err := kptfileutil.Equal(localKf, orgKf) if err != nil { - return false, errors.E(op, types.UniquePath(localPath), err) + return false, errors.E(op, kptfilev1.UniquePath(localPath), err) } return !equal, nil diff --git a/pkg/lib/update/fastforward_test.go b/pkg/lib/update/fastforward_test.go index 079a2540eb..defb3edcc5 100644 --- a/pkg/lib/update/fastforward_test.go +++ b/pkg/lib/update/fastforward_test.go @@ -19,9 +19,9 @@ import ( "path/filepath" "testing" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/internal/testutil" "github.com/kptdev/kpt/internal/testutil/pkgbuilder" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" "github.com/kptdev/kpt/pkg/lib/update" "github.com/kptdev/kpt/pkg/lib/update/updatetypes" "github.com/stretchr/testify/assert" diff --git a/pkg/lib/update/replace.go b/pkg/lib/update/replace.go index 85fbed98e0..047cb73430 100644 --- a/pkg/lib/update/replace.go +++ b/pkg/lib/update/replace.go @@ -18,10 +18,10 @@ import ( "os" "path/filepath" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "github.com/kptdev/kpt/pkg/lib/errors" "github.com/kptdev/kpt/pkg/lib/pkg" - "github.com/kptdev/kpt/pkg/lib/types" "github.com/kptdev/kpt/pkg/lib/update/updatetypes" ) @@ -38,12 +38,12 @@ func (u ReplaceUpdater) Update(options updatetypes.Options) error { // Update Kptfile for root package if err := kptfileutil.UpdateKptfile(options.LocalPath, options.UpdatedPath, options.OriginPath, true); err != nil { - return errors.E(op, types.UniquePath(options.LocalPath), err) + return errors.E(op, kptfilev1.UniquePath(options.LocalPath), err) } paths, err := pkg.FindSubpackagesForPaths(pkg.Local, true, options.LocalPath, options.UpdatedPath) if err != nil { - return errors.E(op, types.UniquePath(options.LocalPath), err) + return errors.E(op, kptfilev1.UniquePath(options.LocalPath), err) } for _, p := range append([]string{"."}, paths...) { @@ -55,7 +55,7 @@ func (u ReplaceUpdater) Update(options updatetypes.Options) error { updatedSubPkgPath := filepath.Join(options.UpdatedPath, p) err = pkg.RemovePackageContent(localSubPkgPath, !isRootPkg) if err != nil { - return errors.E(op, types.UniquePath(localSubPkgPath), err) + return errors.E(op, kptfilev1.UniquePath(localSubPkgPath), err) } // If the package doesn't exist in updated, we make sure it is @@ -63,15 +63,15 @@ func (u ReplaceUpdater) Update(options updatetypes.Options) error { // the content of the package into local. _, err = os.Stat(updatedSubPkgPath) if err != nil && !os.IsNotExist(err) { - return errors.E(op, types.UniquePath(localSubPkgPath), err) + return errors.E(op, kptfilev1.UniquePath(localSubPkgPath), err) } if os.IsNotExist(err) { if err = os.RemoveAll(localSubPkgPath); err != nil { - return errors.E(op, types.UniquePath(localSubPkgPath), err) + return errors.E(op, kptfilev1.UniquePath(localSubPkgPath), err) } } else { if err = pkg.CopyPackage(updatedSubPkgPath, localSubPkgPath, !isRootPkg, pkg.None); err != nil { - return errors.E(op, types.UniquePath(localSubPkgPath), err) + return errors.E(op, kptfilev1.UniquePath(localSubPkgPath), err) } } } diff --git a/pkg/lib/update/resource-merge.go b/pkg/lib/update/resource-merge.go index 85dbeeb426..4d4b4ea280 100644 --- a/pkg/lib/update/resource-merge.go +++ b/pkg/lib/update/resource-merge.go @@ -22,11 +22,10 @@ import ( "strings" pkgdiff "github.com/kptdev/kpt/pkg/lib/pkg/diff" - "github.com/kptdev/kpt/pkg/lib/types" "github.com/kptdev/kpt/pkg/lib/update/merge3" "sigs.k8s.io/kustomize/kyaml/pathutil" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "github.com/kptdev/kpt/pkg/lib/errors" "github.com/kptdev/kpt/pkg/lib/pkg" @@ -50,7 +49,7 @@ func (u ResourceMergeUpdater) Update(options updatetypes.Options) error { if !options.IsRoot { hasChanges, err := PkgHasUpdatedUpstream(options.LocalPath, options.OriginPath) if err != nil { - return errors.E(op, types.UniquePath(options.LocalPath), err) + return errors.E(op, kptfilev1.UniquePath(options.LocalPath), err) } // If the upstream information in local has changed from origin, it @@ -67,7 +66,7 @@ func (u ResourceMergeUpdater) Update(options updatetypes.Options) error { subPkgPaths, err := pkg.FindSubpackagesForPaths(pkg.Local, true, options.LocalPath, options.UpdatedPath, options.OriginPath) if err != nil { - return errors.E(op, types.UniquePath(options.LocalPath), err) + return errors.E(op, kptfilev1.UniquePath(options.LocalPath), err) } // Update each package and subpackage. Parent package is updated before @@ -83,7 +82,7 @@ func (u ResourceMergeUpdater) Update(options updatetypes.Options) error { err := u.updatePackage(subPkgPath, localSubPkgPath, updatedSubPkgPath, originalSubPkgPath, isRootPkg) if err != nil { - return errors.E(op, types.UniquePath(localSubPkgPath), err) + return errors.E(op, kptfilev1.UniquePath(localSubPkgPath), err) } } return nil @@ -96,28 +95,28 @@ func (u ResourceMergeUpdater) updatePackage(subPkgPath, localPath, updatedPath, const op errors.Op = "update.updatePackage" localExists, err := pkg.Exists(localPath) if err != nil { - return errors.E(op, types.UniquePath(localPath), err) + return errors.E(op, kptfilev1.UniquePath(localPath), err) } updatedExists, err := pkg.Exists(updatedPath) if err != nil { - return errors.E(op, types.UniquePath(localPath), err) + return errors.E(op, kptfilev1.UniquePath(localPath), err) } originalExists, err := pkg.Exists(originalPath) if err != nil { - return errors.E(op, types.UniquePath(localPath), err) + return errors.E(op, kptfilev1.UniquePath(localPath), err) } switch { // Check if subpackage has been added both in upstream and in local case !originalExists && localExists && updatedExists: - return errors.E(op, types.UniquePath(localPath), + return errors.E(op, kptfilev1.UniquePath(localPath), fmt.Errorf("subpackage %q added in both upstream and local", subPkgPath)) // Package added in upstream case !originalExists && !localExists && updatedExists: if err := pkg.CopyPackage(updatedPath, localPath, !isRootPkg, pkg.None); err != nil { - return errors.E(op, types.UniquePath(localPath), err) + return errors.E(op, kptfilev1.UniquePath(localPath), err) } // Package added locally case !originalExists && localExists && !updatedExists: @@ -134,16 +133,16 @@ func (u ResourceMergeUpdater) updatePackage(subPkgPath, localPath, updatedPath, // Check the diff. If there are local changes, we keep the subpackage. diff, err := pkgdiff.PkgDiff(originalPath, localPath) if err != nil { - return errors.E(op, types.UniquePath(localPath), err) + return errors.E(op, kptfilev1.UniquePath(localPath), err) } if diff.Len() == 0 { if err := os.RemoveAll(localPath); err != nil { - return errors.E(op, types.UniquePath(localPath), err) + return errors.E(op, kptfilev1.UniquePath(localPath), err) } } default: if err := u.mergePackage(localPath, updatedPath, originalPath, subPkgPath, isRootPkg); err != nil { - return errors.E(op, types.UniquePath(localPath), err) + return errors.E(op, kptfilev1.UniquePath(localPath), err) } } return nil @@ -154,7 +153,7 @@ func (u ResourceMergeUpdater) updatePackage(subPkgPath, localPath, updatedPath, func (u ResourceMergeUpdater) mergePackage(localPath, updatedPath, originalPath, _ string, isRootPkg bool) error { const op errors.Op = "update.mergePackage" if err := kptfileutil.UpdateKptfile(localPath, updatedPath, originalPath, !isRootPkg); err != nil { - return errors.E(op, types.UniquePath(localPath), err) + return errors.E(op, kptfilev1.UniquePath(localPath), err) } originalKos, updatedKos, destinationKos, err := collectKubeObjectsFromPackages(localPath, updatedPath, originalPath) if err != nil { @@ -179,7 +178,7 @@ func (u ResourceMergeUpdater) mergePackage(localPath, updatedPath, originalPath, } if err := ReplaceNonKRMFiles(updatedPath, originalPath, localPath); err != nil { - return errors.E(op, types.UniquePath(localPath), err) + return errors.E(op, kptfilev1.UniquePath(localPath), err) } return nil } @@ -210,17 +209,17 @@ func ReplaceNonKRMFiles(updatedDir, originalDir, localDir string) error { const op errors.Op = "update.ReplaceNonKRMFiles" updatedSubDirs, updatedFiles, err := getSubDirsAndNonKrmFiles(updatedDir) if err != nil { - return errors.E(op, types.UniquePath(localDir), err) + return errors.E(op, kptfilev1.UniquePath(localDir), err) } originalSubDirs, originalFiles, err := getSubDirsAndNonKrmFiles(originalDir) if err != nil { - return errors.E(op, types.UniquePath(localDir), err) + return errors.E(op, kptfilev1.UniquePath(localDir), err) } localSubDirs, localFiles, err := getSubDirsAndNonKrmFiles(localDir) if err != nil { - return errors.E(op, types.UniquePath(localDir), err) + return errors.E(op, kptfilev1.UniquePath(localDir), err) } // identify all non KRM files modified locally, to leave them untouched @@ -233,7 +232,7 @@ func ReplaceNonKRMFiles(updatedDir, originalDir, localDir string) error { } same, err := compareFiles(filepath.Join(originalDir, file), filepath.Join(localDir, file)) if err != nil { - return errors.E(op, types.UniquePath(localDir), err) + return errors.E(op, kptfilev1.UniquePath(localDir), err) } if !same { // local file has been modified @@ -244,7 +243,7 @@ func ReplaceNonKRMFiles(updatedDir, originalDir, localDir string) error { // remove the file from local if it is not modified and is deleted from updated upstream if !updatedFiles.Has(file) { if err = os.Remove(filepath.Join(localDir, file)); err != nil { - return errors.E(op, types.UniquePath(localDir), err) + return errors.E(op, kptfilev1.UniquePath(localDir), err) } } } @@ -252,7 +251,7 @@ func ReplaceNonKRMFiles(updatedDir, originalDir, localDir string) error { // make sure local has all sub-dirs present in updated for _, dir := range updatedSubDirs.List() { if err = os.MkdirAll(filepath.Join(localDir, dir), 0700); err != nil { - return errors.E(op, types.UniquePath(localDir), err) + return errors.E(op, kptfilev1.UniquePath(localDir), err) } } @@ -264,7 +263,7 @@ func ReplaceNonKRMFiles(updatedDir, originalDir, localDir string) error { } err = copyutil.SyncFile(filepath.Join(updatedDir, file), filepath.Join(localDir, file)) if err != nil { - return errors.E(op, types.UniquePath(localDir), err) + return errors.E(op, kptfilev1.UniquePath(localDir), err) } } @@ -403,7 +402,7 @@ func loadResourcesFromDirectory(directoryPath string, mergeSourceAnnotation stri } nodes, err := reader.Read() if err != nil { - return nil, errors.E(types.UniquePath(directoryPath), err) + return nil, errors.E(kptfilev1.UniquePath(directoryPath), err) } return fn.MoveToKubeObjects(nodes), err } @@ -419,7 +418,7 @@ func writeResourcesToDirectory(destPath string, kubeObjects fn.KubeObjects) erro } _, err := destWriter.Read() if err != nil { - return errors.E(types.UniquePath(destPath), err) + return errors.E(kptfilev1.UniquePath(destPath), err) } err = destWriter.Write(kubeObjects.CopyToResourceNodes()) if err != nil { diff --git a/pkg/lib/update/update.go b/pkg/lib/update/update.go index b3e59b5f5a..138f56b1f6 100644 --- a/pkg/lib/update/update.go +++ b/pkg/lib/update/update.go @@ -23,12 +23,11 @@ import ( "path/filepath" "strings" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" internalgitutil "github.com/kptdev/kpt/internal/gitutil" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "github.com/kptdev/kpt/pkg/lib/errors" "github.com/kptdev/kpt/pkg/lib/pkg" - "github.com/kptdev/kpt/pkg/lib/types" "github.com/kptdev/kpt/pkg/lib/update/updatetypes" "github.com/kptdev/kpt/pkg/lib/util/addmergecomment" "github.com/kptdev/kpt/pkg/lib/util/fetch" @@ -42,7 +41,7 @@ import ( // PkgNotGitRepoError is the error type returned if the package being updated is not inside // a git repository. type PkgNotGitRepoError struct { - Path types.UniquePath + Path kptfilev1.UniquePath } func (p *PkgNotGitRepoError) Error() string { @@ -52,7 +51,7 @@ func (p *PkgNotGitRepoError) Error() string { // PkgRepoDirtyError is the error type returned if the package being updated contains // uncommitted changes. type PkgRepoDirtyError struct { - Path types.UniquePath + Path kptfilev1.UniquePath } func (p *PkgRepoDirtyError) Error() string { @@ -340,7 +339,7 @@ func (u Command) updatePackage(ctx context.Context, subPkgPath, localPath, updat localExists, err := pkg.IsPackageDir(filesys.FileSystemOrOnDisk{}, localPath) if err != nil { - return errors.E(op, types.UniquePath(localPath), err) + return errors.E(op, kptfilev1.UniquePath(localPath), err) } // We need to handle the root package special here, since the copies @@ -349,7 +348,7 @@ func (u Command) updatePackage(ctx context.Context, subPkgPath, localPath, updat if !isRootPkg { updatedExists, err = pkg.IsPackageDir(filesys.FileSystemOrOnDisk{}, updatedPath) if err != nil { - return errors.E(op, types.UniquePath(localPath), err) + return errors.E(op, kptfilev1.UniquePath(localPath), err) } } @@ -357,7 +356,7 @@ func (u Command) updatePackage(ctx context.Context, subPkgPath, localPath, updat if !isRootPkg { originExists, err = pkg.IsPackageDir(filesys.FileSystemOrOnDisk{}, originPath) if err != nil { - return errors.E(op, types.UniquePath(localPath), err) + return errors.E(op, kptfilev1.UniquePath(localPath), err) } } @@ -368,7 +367,7 @@ func (u Command) updatePackage(ctx context.Context, subPkgPath, localPath, updat // can't make a sane merge here, so we treat it as an error. case !originExists && localExists && updatedExists: pr.Printf("Package %q added in both local and upstream.\n", packageName(localPath)) - return errors.E(op, types.UniquePath(localPath), + return errors.E(op, kptfilev1.UniquePath(localPath), fmt.Errorf("subpackage %q added in both upstream and local", subPkgPath)) // Package added in upstream. We just copy the package. If the package @@ -377,7 +376,7 @@ func (u Command) updatePackage(ctx context.Context, subPkgPath, localPath, updat case !originExists && !localExists && updatedExists: pr.Printf("Adding package %q from upstream.\n", packageName(localPath)) if err := pkg.CopyPackage(updatedPath, localPath, !isRootPkg, pkg.None); err != nil { - return errors.E(op, types.UniquePath(localPath), err) + return errors.E(op, kptfilev1.UniquePath(localPath), err) } // Package added locally, so no action needed. @@ -399,19 +398,19 @@ func (u Command) updatePackage(ctx context.Context, subPkgPath, localPath, updat // Check the diff. If there are local changes, we keep the subpackage. diff, err := copyutil.Diff(originPath, localPath) if err != nil { - return errors.E(op, types.UniquePath(localPath), err) + return errors.E(op, kptfilev1.UniquePath(localPath), err) } if diff.Len() == 0 { pr.Printf("Deleting package %q from local since it is removed in upstream.\n", packageName(localPath)) if err := os.RemoveAll(localPath); err != nil { - return errors.E(op, types.UniquePath(localPath), err) + return errors.E(op, kptfilev1.UniquePath(localPath), err) } } else { pr.Printf("Package %q deleted from upstream, but keeping local since it has changes.\n", packageName(localPath)) } default: if err := u.mergePackage(ctx, localPath, updatedPath, originPath, subPkgPath, isRootPkg); err != nil { - return errors.E(op, types.UniquePath(localPath), err) + return errors.E(op, kptfilev1.UniquePath(localPath), err) } } return nil @@ -423,13 +422,13 @@ func (u Command) mergePackage(ctx context.Context, localPath, updatedPath, origi // at this point, the localPath, updatedPath and originPath exists and are about to be merged // make sure that the merge comments are added to all of them so that they are merged accurately if err := addmergecomment.Process(localPath, updatedPath, originPath); err != nil { - return errors.E(op, types.UniquePath(localPath), + return errors.E(op, kptfilev1.UniquePath(localPath), fmt.Errorf("failed to add merge comments %q", err.Error())) } updatedUnfetched, err := pkg.IsPackageUnfetched(updatedPath) if err != nil { if !errors.Is(err, os.ErrNotExist) || !isRootPkg { - return errors.E(op, types.UniquePath(localPath), err) + return errors.E(op, kptfilev1.UniquePath(localPath), err) } // For root packages, there might not be a Kptfile in the upstream repo. updatedUnfetched = false @@ -438,7 +437,7 @@ func (u Command) mergePackage(ctx context.Context, localPath, updatedPath, origi originUnfetched, err := pkg.IsPackageUnfetched(originPath) if err != nil { if !errors.Is(err, os.ErrNotExist) || !isRootPkg { - return errors.E(op, types.UniquePath(localPath), err) + return errors.E(op, kptfilev1.UniquePath(localPath), err) } // For root packages, there might not be a Kptfile in origin. originUnfetched = false @@ -459,18 +458,18 @@ func (u Command) mergePackage(ctx context.Context, localPath, updatedPath, origi // to determine if they share the common upstream and then fetch origin // using the common commit SHA. But this is a very advanced scenario, // so we just return the error for now. - return errors.E(op, types.UniquePath(localPath), fmt.Errorf("no origin available for package")) + return errors.E(op, kptfilev1.UniquePath(localPath), fmt.Errorf("no origin available for package")) default: // Both exists, so just go ahead as normal. } pkgKf, err := kptfileutil.ReadKptfile(filesys.FileSystemOrOnDisk{}, localPath) if err != nil { - return errors.E(op, types.UniquePath(localPath), err) + return errors.E(op, kptfilev1.UniquePath(localPath), err) } updater, found := strategies[pkgKf.Upstream.UpdateStrategy] if !found { - return errors.E(op, types.UniquePath(localPath), + return errors.E(op, kptfilev1.UniquePath(localPath), fmt.Errorf("unrecognized update strategy %s", u.Strategy)) } pr.Printf("Updating package %q with strategy %q.\n", packageName(localPath), pkgKf.Upstream.UpdateStrategy) @@ -481,7 +480,7 @@ func (u Command) mergePackage(ctx context.Context, localPath, updatedPath, origi OriginPath: originPath, IsRoot: isRootPkg, }); err != nil { - return errors.E(op, types.UniquePath(localPath), err) + return errors.E(op, kptfilev1.UniquePath(localPath), err) } return nil diff --git a/pkg/lib/update/update_test.go b/pkg/lib/update/update_test.go index 5997a4c8ee..67ff220c90 100644 --- a/pkg/lib/update/update_test.go +++ b/pkg/lib/update/update_test.go @@ -23,9 +23,9 @@ import ( "slices" "testing" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/internal/testutil" "github.com/kptdev/kpt/internal/testutil/pkgbuilder" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "github.com/kptdev/kpt/pkg/lib/update" "github.com/kptdev/kpt/pkg/printer/fake" diff --git a/pkg/lib/util/fetch/fetch.go b/pkg/lib/util/fetch/fetch.go index b3a966c488..6785718c97 100644 --- a/pkg/lib/util/fetch/fetch.go +++ b/pkg/lib/util/fetch/fetch.go @@ -24,11 +24,10 @@ import ( internalgitutil "github.com/kptdev/kpt/internal/gitutil" "github.com/kptdev/kpt/pkg/lib/errors" - "github.com/kptdev/kpt/pkg/lib/types" "github.com/otiai10/copy" "sigs.k8s.io/kustomize/kyaml/filesys" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "github.com/kptdev/kpt/pkg/lib/pkg" gitutil "github.com/kptdev/kpt/pkg/lib/util/git" @@ -133,7 +132,7 @@ func (c *Cloner) cloneAndCopy(ctx context.Context, dest string) error { err := c.ClonerUsingGitExec(ctx) if err != nil { - return errors.E(op, errors.Git, types.UniquePath(dest), err) + return errors.E(op, errors.Git, kptfilev1.UniquePath(dest), err) } defer os.RemoveAll(c.repoSpec.Dir) // update cache before removing clone dir @@ -142,15 +141,15 @@ func (c *Cloner) cloneAndCopy(ctx context.Context, dest string) error { sourcePath := filepath.Join(c.repoSpec.Dir, c.repoSpec.Path) pr.Printf("Adding package %q.\n", strings.TrimPrefix(c.repoSpec.Path, "/")) if err := pkg.CopyPackage(sourcePath, dest, true, pkg.All); err != nil { - return errors.E(op, types.UniquePath(dest), err) + return errors.E(op, kptfilev1.UniquePath(dest), err) } if err := kptfileutil.UpdateKptfileWithoutOrigin(dest, sourcePath, false); err != nil { - return errors.E(op, types.UniquePath(dest), err) + return errors.E(op, kptfilev1.UniquePath(dest), err) } if err := kptfileutil.UpdateUpstreamLockFromGit(dest, c.repoSpec); err != nil { - return errors.E(op, errors.Git, types.UniquePath(dest), err) + return errors.E(op, errors.Git, kptfilev1.UniquePath(dest), err) } return nil } diff --git a/pkg/lib/util/fetch/fetch_test.go b/pkg/lib/util/fetch/fetch_test.go index cd1537c638..625558d789 100644 --- a/pkg/lib/util/fetch/fetch_test.go +++ b/pkg/lib/util/fetch/fetch_test.go @@ -19,9 +19,9 @@ import ( "path/filepath" "testing" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/internal/testutil" "github.com/kptdev/kpt/internal/testutil/pkgbuilder" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "github.com/kptdev/kpt/pkg/lib/util/fetch" "github.com/kptdev/kpt/pkg/printer/fake" diff --git a/pkg/lib/util/get/example_test.go b/pkg/lib/util/get/example_test.go index 52ee77fe2c..3b374873ea 100644 --- a/pkg/lib/util/get/example_test.go +++ b/pkg/lib/util/get/example_test.go @@ -18,7 +18,7 @@ import ( "fmt" "path/filepath" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/pkg/lib/util/get" "github.com/kptdev/kpt/pkg/printer/fake" ) diff --git a/pkg/lib/util/get/get.go b/pkg/lib/util/get/get.go index d100cd0d54..26d3a879bb 100644 --- a/pkg/lib/util/get/get.go +++ b/pkg/lib/util/get/get.go @@ -23,13 +23,12 @@ import ( "path/filepath" "strings" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "github.com/kptdev/kpt/pkg/lib/errors" "github.com/kptdev/kpt/pkg/lib/kptops" "github.com/kptdev/kpt/pkg/lib/pkg" "github.com/kptdev/kpt/pkg/lib/runneroptions" - "github.com/kptdev/kpt/pkg/lib/types" "github.com/kptdev/kpt/pkg/lib/util/addmergecomment" "github.com/kptdev/kpt/pkg/lib/util/attribution" "github.com/kptdev/kpt/pkg/lib/util/fetch" @@ -79,26 +78,26 @@ func (c Command) Run(ctx context.Context) error { case err == nil: // Destination exists - check if it's an empty directory if !destInfo.IsDir() { - return errors.E(op, errors.Exist, types.UniquePath(c.Destination), fmt.Errorf("destination exists and is not a directory")) + return errors.E(op, errors.Exist, kptfilev1.UniquePath(c.Destination), fmt.Errorf("destination exists and is not a directory")) } // Check if directory is empty entries, err := os.ReadDir(c.Destination) if err != nil { - return errors.E(op, errors.IO, types.UniquePath(c.Destination), err) + return errors.E(op, errors.IO, kptfilev1.UniquePath(c.Destination), err) } if len(entries) > 0 { - return errors.E(op, errors.Exist, types.UniquePath(c.Destination), fmt.Errorf("destination directory already exists")) + return errors.E(op, errors.Exist, kptfilev1.UniquePath(c.Destination), fmt.Errorf("destination directory already exists")) } // Directory exists but is empty, we can use it case goerrors.Is(err, os.ErrNotExist): // Directory doesn't exist, create it err = os.MkdirAll(c.Destination, 0700) if err != nil { - return errors.E(op, errors.IO, types.UniquePath(c.Destination), err) + return errors.E(op, errors.IO, kptfilev1.UniquePath(c.Destination), err) } default: - return errors.E(op, errors.IO, types.UniquePath(c.Destination), err) + return errors.E(op, errors.IO, kptfilev1.UniquePath(c.Destination), err) } // normalize path to a filepath @@ -254,7 +253,7 @@ func cleanUpDirAndError(destination string, err error) error { const op errors.Op = "get.Run" rmErr := os.RemoveAll(destination) if rmErr != nil { - return errors.E(op, types.UniquePath(destination), err, rmErr) + return errors.E(op, kptfilev1.UniquePath(destination), err, rmErr) } - return errors.E(op, types.UniquePath(destination), err) + return errors.E(op, kptfilev1.UniquePath(destination), err) } diff --git a/pkg/lib/util/get/get_test.go b/pkg/lib/util/get/get_test.go index fe8ce0815a..f35153e61e 100644 --- a/pkg/lib/util/get/get_test.go +++ b/pkg/lib/util/get/get_test.go @@ -20,9 +20,9 @@ import ( "path/filepath" "testing" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/internal/testutil" "github.com/kptdev/kpt/internal/testutil/pkgbuilder" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" "github.com/kptdev/kpt/pkg/lib/util/get" "github.com/kptdev/kpt/pkg/printer/fake" "github.com/stretchr/testify/assert" diff --git a/pkg/lib/util/man/man.go b/pkg/lib/util/man/man.go index 4cf6ade6cf..389a773fe9 100644 --- a/pkg/lib/util/man/man.go +++ b/pkg/lib/util/man/man.go @@ -24,7 +24,7 @@ import ( "strings" "github.com/cpuguy83/go-md2man/v2/md2man" - v1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "sigs.k8s.io/kustomize/kyaml/errors" "sigs.k8s.io/kustomize/kyaml/filesys" @@ -62,7 +62,7 @@ func (m Command) Run() error { return err } if k.Info == nil { - k.Info = &v1.PackageInfo{} + k.Info = &kptfilev1.PackageInfo{} } if k.Info.Man == "" { diff --git a/pkg/lib/util/man/man_test.go b/pkg/lib/util/man/man_test.go index 2b2b0ada2c..90665a88a0 100644 --- a/pkg/lib/util/man/man_test.go +++ b/pkg/lib/util/man/man_test.go @@ -21,7 +21,7 @@ import ( "path/filepath" "testing" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/pkg/lib/util/man" "github.com/stretchr/testify/assert" ) diff --git a/pkg/lib/util/parse/parse.go b/pkg/lib/util/parse/parse.go index 3f5fe78a0a..c1b5efc8e3 100644 --- a/pkg/lib/util/parse/parse.go +++ b/pkg/lib/util/parse/parse.go @@ -23,8 +23,8 @@ import ( "regexp" "strings" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" internalgitutil "github.com/kptdev/kpt/internal/gitutil" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" "sigs.k8s.io/kustomize/kyaml/errors" ) diff --git a/pkg/lib/util/parse/parse_test.go b/pkg/lib/util/parse/parse_test.go index 8496785fee..f360d206a8 100644 --- a/pkg/lib/util/parse/parse_test.go +++ b/pkg/lib/util/parse/parse_test.go @@ -19,7 +19,7 @@ import ( "fmt" "testing" - v1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/pkg/printer" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -224,7 +224,7 @@ func Test_GitParseArgs(t *testing.T) { }{ "git@ url with .git suffix": { ghURL: "git@github.com:github.com/kptdev/kpt.git", - expected: Target{Git: v1.Git{ + expected: Target{Git: kptfilev1.Git{ Repo: "git@github.com:github.com/kptdev/kpt", Directory: "/", Ref: "main", @@ -235,7 +235,7 @@ func Test_GitParseArgs(t *testing.T) { }, "http url with .git suffix": { ghURL: "https://github.com/kptdev/kpt.git", - expected: Target{Git: v1.Git{ + expected: Target{Git: kptfilev1.Git{ Repo: "https://github.com/kptdev/kpt", Directory: "/", Ref: "main", @@ -244,7 +244,7 @@ func Test_GitParseArgs(t *testing.T) { }, "starts with github.com": { ghURL: "https://github.com/kptdev/kpt", - expected: Target{Git: v1.Git{ + expected: Target{Git: kptfilev1.Git{ Repo: "https://github.com/kptdev/kpt", Directory: "/", Ref: "main", diff --git a/pkg/live/load.go b/pkg/live/load.go index 18282a3637..87f646f214 100644 --- a/pkg/live/load.go +++ b/pkg/live/load.go @@ -19,8 +19,8 @@ import ( "fmt" "io" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" - rgfilev1alpha1 "github.com/kptdev/kpt/pkg/api/resourcegroup/v1alpha1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" + rgfilev1alpha1 "github.com/kptdev/kpt/api/resourcegroup/v1alpha1" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "github.com/kptdev/kpt/pkg/lib/errors" "github.com/kptdev/kpt/pkg/lib/pkg" diff --git a/pkg/live/load_test.go b/pkg/live/load_test.go index 9e3b9d3156..c50aa3427d 100644 --- a/pkg/live/load_test.go +++ b/pkg/live/load_test.go @@ -22,10 +22,10 @@ import ( "sort" "testing" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" + rgfilev1alpha1 "github.com/kptdev/kpt/api/resourcegroup/v1alpha1" "github.com/kptdev/kpt/internal/testutil" "github.com/kptdev/kpt/internal/testutil/pkgbuilder" - kptfile "github.com/kptdev/kpt/pkg/api/kptfile/v1" - rgfilev1alpha1 "github.com/kptdev/kpt/pkg/api/resourcegroup/v1alpha1" "github.com/stretchr/testify/assert" "k8s.io/apimachinery/pkg/runtime/schema" cmdtesting "k8s.io/kubectl/pkg/cmd/testing" @@ -38,7 +38,7 @@ func TestLoad_LocalDisk(t *testing.T) { pkg *pkgbuilder.RootPkg namespace string expectedObjs object.ObjMetadataSet - expectedInv kptfile.Inventory + expectedInv kptfilev1.Inventory expectedErrMsg string rgFile string }{ @@ -99,7 +99,7 @@ func TestLoad_LocalDisk(t *testing.T) { WithFile("deployment.yaml", deploymentA), ), namespace: "foo", - expectedInv: kptfile.Inventory{ + expectedInv: kptfilev1.Inventory{ Name: "foo", Namespace: "bar", InventoryID: "foo-bar", @@ -156,7 +156,7 @@ func TestLoad_LocalDisk(t *testing.T) { Namespace: "foo", }, }, - expectedInv: kptfile.Inventory{ + expectedInv: kptfilev1.Inventory{ Name: "foo", Namespace: "bar", InventoryID: "foo-bar", @@ -185,7 +185,7 @@ func TestLoad_LocalDisk(t *testing.T) { ), namespace: "foo", expectedObjs: []object.ObjMetadata{}, - expectedInv: kptfile.Inventory{ + expectedInv: kptfilev1.Inventory{ Name: "foo", Namespace: "bar", InventoryID: "foo-bar", @@ -202,7 +202,7 @@ func TestLoad_LocalDisk(t *testing.T) { )), namespace: "foo", expectedObjs: []object.ObjMetadata{}, - expectedInv: kptfile.Inventory{ + expectedInv: kptfilev1.Inventory{ Name: "foo", Namespace: "bar", InventoryID: "foo-bar", @@ -226,7 +226,7 @@ func TestLoad_LocalDisk(t *testing.T) { }), namespace: "foo", expectedObjs: []object.ObjMetadata{}, - expectedInv: kptfile.Inventory{ + expectedInv: kptfilev1.Inventory{ Name: "foo", Namespace: "bar", InventoryID: "foo-bar", @@ -287,7 +287,7 @@ func TestLoad_StdIn(t *testing.T) { pkg *pkgbuilder.RootPkg namespace string expectedObjs object.ObjMetadataSet - expectedInv kptfile.Inventory + expectedInv kptfilev1.Inventory expectedErrMsg string rgFile string }{ @@ -320,7 +320,7 @@ func TestLoad_StdIn(t *testing.T) { Namespace: "foo", }, }, - expectedInv: kptfile.Inventory{ + expectedInv: kptfilev1.Inventory{ Name: "foo", Namespace: "bar", InventoryID: "foo-bar", @@ -360,7 +360,7 @@ func TestLoad_StdIn(t *testing.T) { Namespace: "foo", }, }, - expectedInv: kptfile.Inventory{ + expectedInv: kptfilev1.Inventory{ Name: "foo", Namespace: "bar", InventoryID: "foo-bar", @@ -403,7 +403,7 @@ func TestLoad_StdIn(t *testing.T) { }, )), namespace: "foo", - expectedInv: kptfile.Inventory{ + expectedInv: kptfilev1.Inventory{ Name: "foo", Namespace: "bar", InventoryID: "foo-bar", @@ -433,7 +433,7 @@ func TestLoad_StdIn(t *testing.T) { }, }), namespace: "foo", - expectedInv: kptfile.Inventory{ + expectedInv: kptfilev1.Inventory{ Name: "foo", Namespace: "bar", InventoryID: "foo-bar", @@ -515,7 +515,7 @@ func TestLoad_StdIn(t *testing.T) { kio.LocalPackageReader{ PackagePath: dir, OmitReaderAnnotations: true, - MatchFilesGlob: append([]string{kptfile.KptFileName}, kio.DefaultMatch...), + MatchFilesGlob: append([]string{kptfilev1.KptFileName}, kio.DefaultMatch...), IncludeSubpackages: true, WrapBareSeqNode: true, }, @@ -530,7 +530,7 @@ func TestLoad_StdIn(t *testing.T) { t.FailNow() } - os.Remove(filepath.Join(dir, kptfile.KptFileName)) + os.Remove(filepath.Join(dir, kptfilev1.KptFileName)) os.Remove(filepath.Join(dir, tc.rgFile)) objs, inv, err := Load(tf, "-", &buf) @@ -564,12 +564,12 @@ func TestLoad_StdIn(t *testing.T) { func TestValidateInventory(t *testing.T) { testCases := map[string]struct { - inventory kptfile.Inventory + inventory kptfilev1.Inventory expectErr bool expectedErrorFields []string }{ "complete inventory info validate": { - inventory: kptfile.Inventory{ + inventory: kptfilev1.Inventory{ Name: "foo", Namespace: "default", InventoryID: "foo-default", @@ -577,7 +577,7 @@ func TestValidateInventory(t *testing.T) { expectErr: false, }, "inventory info without name doesn't validate": { - inventory: kptfile.Inventory{ + inventory: kptfilev1.Inventory{ Namespace: "default", InventoryID: "foo-default", }, @@ -585,7 +585,7 @@ func TestValidateInventory(t *testing.T) { expectedErrorFields: []string{"name"}, }, "inventory namespace doesn't validate": { - inventory: kptfile.Inventory{ + inventory: kptfilev1.Inventory{ Name: "foo", }, expectErr: true, diff --git a/pkg/live/rgpath.go b/pkg/live/rgpath.go index 15bcf539f3..41d674a9a4 100644 --- a/pkg/live/rgpath.go +++ b/pkg/live/rgpath.go @@ -18,7 +18,7 @@ import ( "encoding/json" "fmt" - rgfilev1alpha1 "github.com/kptdev/kpt/pkg/api/resourcegroup/v1alpha1" + rgfilev1alpha1 "github.com/kptdev/kpt/api/resourcegroup/v1alpha1" pathutil "github.com/kptdev/kpt/pkg/lib/util/path" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "sigs.k8s.io/cli-utils/pkg/manifestreader" diff --git a/pkg/live/rgstream.go b/pkg/live/rgstream.go index d2b190f51c..b6131f07c9 100644 --- a/pkg/live/rgstream.go +++ b/pkg/live/rgstream.go @@ -18,8 +18,8 @@ import ( "bytes" "io" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" - rgfilev1alpha1 "github.com/kptdev/kpt/pkg/api/resourcegroup/v1alpha1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" + rgfilev1alpha1 "github.com/kptdev/kpt/api/resourcegroup/v1alpha1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/cli-utils/pkg/manifestreader" diff --git a/pkg/printer/printer.go b/pkg/printer/printer.go index 08f75cb26e..2e4645880c 100644 --- a/pkg/printer/printer.go +++ b/pkg/printer/printer.go @@ -21,8 +21,8 @@ import ( "io" "os" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/pkg/lib/pkg" - "github.com/kptdev/kpt/pkg/lib/types" ) // TruncateOutput defines should output be truncated @@ -46,9 +46,9 @@ type Printer interface { // Options are optional options for printer type Options struct { // PkgPath is the unique path to the package - PkgPath types.UniquePath + PkgPath kptfilev1.UniquePath // PkgDisplayPath is the display path for the package - PkgDisplayPath types.DisplayPath + PkgDisplayPath kptfilev1.DisplayPath // PkgDisplayName is the display name of the package. // It takes precedence over PkgPath and PkgDisplayPath in most logging scenarios. PkgDisplayName string @@ -60,13 +60,13 @@ func NewOpt() *Options { } // Pkg sets the package unique path in options -func (opt *Options) Pkg(p types.UniquePath) *Options { +func (opt *Options) Pkg(p kptfilev1.UniquePath) *Options { opt.PkgPath = p return opt } // PkgDisplayPath sets the package display path in options -func (opt *Options) PkgDisplay(p types.DisplayPath) *Options { +func (opt *Options) PkgDisplay(p kptfilev1.DisplayPath) *Options { opt.PkgDisplayPath = p return opt } diff --git a/pkg/test/runner/config.go b/pkg/test/runner/config.go index 0809e5c6c7..c5dfb6a4eb 100644 --- a/pkg/test/runner/config.go +++ b/pkg/test/runner/config.go @@ -19,7 +19,7 @@ import ( "os" "path/filepath" - "github.com/kptdev/kpt/pkg/lib/types" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "sigs.k8s.io/kustomize/kyaml/yaml" ) @@ -31,7 +31,7 @@ type EvalTestCaseConfig struct { // The path should be separated by slash '/' ExecPath string `json:"execPath,omitempty" yaml:"execPath,omitempty"` // execUniquePath is an absolute, OS-specific path to exec file. - execUniquePath types.UniquePath + execUniquePath kptfilev1.UniquePath // Image is the image name for the function Image string `json:"image,omitempty" yaml:"image,omitempty"` Tag string `json:"tag,omitempty" yaml:"tag,omitempty"` @@ -47,7 +47,7 @@ type EvalTestCaseConfig struct { // The path should be separated by slash '/' FnConfig string `json:"fnConfig,omitempty" yaml:"fnConfig,omitempty"` // fnConfigUniquePath is an absolute, OS-specific path to function config file. - fnConfigUniquePath types.UniquePath + fnConfigUniquePath kptfilev1.UniquePath } // TestCaseConfig contains the config information for the test case @@ -222,17 +222,17 @@ func ScanTestCases(path string) (*TestCases, error) { // fromSlashPath returns a UniquePath according to the input slash 'path'. // 'base' should be an OS-specific base path which will be joined with 'path' // if 'path' is not absolute. -func fromSlashPath(base, path string) (types.UniquePath, error) { +func fromSlashPath(base, path string) (kptfilev1.UniquePath, error) { if path == "" { - return types.UniquePath(""), nil + return kptfilev1.UniquePath(""), nil } path = filepath.FromSlash(path) if filepath.IsAbs(path) { - return types.UniquePath(path), nil + return kptfilev1.UniquePath(path), nil } p, err := filepath.Abs(filepath.Join(base, path)) if err != nil { return "", err } - return types.UniquePath(p), nil + return kptfilev1.UniquePath(p), nil } diff --git a/thirdparty/cmdconfig/commands/cmdcat/cmdcat.go b/thirdparty/cmdconfig/commands/cmdcat/cmdcat.go index 2a5a3ffd9a..2934116a73 100644 --- a/thirdparty/cmdconfig/commands/cmdcat/cmdcat.go +++ b/thirdparty/cmdconfig/commands/cmdcat/cmdcat.go @@ -25,8 +25,8 @@ import ( "strings" "unicode/utf8" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/internal/docs/generated/pkgdocs" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" argsutil "github.com/kptdev/kpt/pkg/lib/util/args" "github.com/kptdev/kpt/thirdparty/cmdconfig/commands/runner" "github.com/spf13/cobra" diff --git a/thirdparty/cmdconfig/commands/cmdeval/cmdeval.go b/thirdparty/cmdconfig/commands/cmdeval/cmdeval.go index 11928339f8..e0cfbd25fb 100644 --- a/thirdparty/cmdconfig/commands/cmdeval/cmdeval.go +++ b/thirdparty/cmdconfig/commands/cmdeval/cmdeval.go @@ -13,8 +13,8 @@ import ( "strings" "github.com/google/shlex" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" docs "github.com/kptdev/kpt/internal/docs/generated/fndocs" - kptfile "github.com/kptdev/kpt/pkg/api/kptfile/v1" "github.com/kptdev/kpt/pkg/kptfile/kptfileutil" "github.com/kptdev/kpt/pkg/lib/runneroptions" argsutil "github.com/kptdev/kpt/pkg/lib/util/args" @@ -149,8 +149,8 @@ type EvalFnRunner struct { AsCurrentUser bool IncludeMetaResources bool Ctx context.Context - Selector kptfile.Selector - Exclusion kptfile.Selector + Selector kptfilev1.Selector + Exclusion kptfilev1.Selector dataItems []string RunnerOptions runneroptions.RunnerOptions @@ -185,8 +185,8 @@ func (r *EvalFnRunner) runE(c *cobra.Command, _ []string) error { // NewFunction creates a Kptfile.Function object which has the evaluated fn configurations. // This object can be written to Kptfile `pipeline.mutators`. -func (r *EvalFnRunner) NewFunction() *kptfile.Function { - newFn := &kptfile.Function{} +func (r *EvalFnRunner) NewFunction() *kptfilev1.Function { + newFn := &kptfilev1.Function{} if r.Image != "" { newFn.Image = r.Image newFn.Tag = r.Tag @@ -194,10 +194,10 @@ func (r *EvalFnRunner) NewFunction() *kptfile.Function { newFn.Exec = r.Exec } if !r.Selector.IsEmpty() { - newFn.Selectors = []kptfile.Selector{r.Selector} + newFn.Selectors = []kptfilev1.Selector{r.Selector} } if !r.Exclusion.IsEmpty() { - newFn.Exclusions = []kptfile.Selector{r.Exclusion} + newFn.Exclusions = []kptfilev1.Selector{r.Exclusion} } if r.FnConfigPath != "" { fnConfigAbsPath, _, _ := pathutil.ResolveAbsAndRelPaths(r.FnConfigPath) @@ -221,8 +221,8 @@ func (r *EvalFnRunner) NewFunction() *kptfile.Function { // Add the evaluated function to the kptfile.Function list, this Function can either be // `pipeline.mutators` or `pipeline.validators` -func (r *EvalFnRunner) updateFnList(oldFNs []kptfile.Function) ([]kptfile.Function, string) { - var newFns []kptfile.Function +func (r *EvalFnRunner) updateFnList(oldFNs []kptfilev1.Function) ([]kptfilev1.Function, string) { + var newFns []kptfilev1.Function found := false newFn := r.NewFunction() var message string @@ -261,7 +261,7 @@ func (r *EvalFnRunner) SaveFnToKptfile() { } if kf.Pipeline == nil { - kf.Pipeline = &kptfile.Pipeline{} + kf.Pipeline = &kptfilev1.Pipeline{} } var usrMsg string switch r.FnType { @@ -288,8 +288,8 @@ func (r *EvalFnRunner) SaveFnToKptfile() { // preserveCommentsAndFieldOrder syncs the mutated Kptfile with the original to preserve // comments and field order, and returns the result as a yaml Node -func (r *EvalFnRunner) preserveCommentsAndFieldOrder(kf *kptfile.KptFile) (*yaml.Node, error) { - kfAsRNode, err := yaml.ReadFile(filepath.Join(r.runFns.Path, kptfile.KptFileName)) +func (r *EvalFnRunner) preserveCommentsAndFieldOrder(kf *kptfilev1.KptFile) (*yaml.Node, error) { + kfAsRNode, err := yaml.ReadFile(filepath.Join(r.runFns.Path, kptfilev1.KptFileName)) if err != nil { return nil, fmt.Errorf("could not read Kptfile: %v", err) } @@ -381,7 +381,7 @@ func (r *EvalFnRunner) getFunctionSpec() (*runtimeutil.FunctionSpec, []string, e fn := &runtimeutil.FunctionSpec{} var execArgs []string if r.Image != "" { - if err := kptfile.ValidateFunctionImageURL(r.Image); err != nil { + if err := kptfilev1.ValidateFunctionImageURL(r.Image); err != nil { return nil, nil, err } fn.Container.Image = r.Image diff --git a/thirdparty/cmdconfig/commands/cmdsource/cmdsource.go b/thirdparty/cmdconfig/commands/cmdsource/cmdsource.go index 7fba739a4a..354253ae1f 100644 --- a/thirdparty/cmdconfig/commands/cmdsource/cmdsource.go +++ b/thirdparty/cmdconfig/commands/cmdsource/cmdsource.go @@ -8,8 +8,8 @@ import ( "fmt" "path/filepath" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/internal/docs/generated/fndocs" - kptfile "github.com/kptdev/kpt/pkg/api/kptfile/v1" "github.com/kptdev/kpt/pkg/lib/pkg" argsutil "github.com/kptdev/kpt/pkg/lib/util/args" "github.com/kptdev/kpt/pkg/lib/util/cmdutil" @@ -110,7 +110,7 @@ func (r *SourceRunner) runE(c *cobra.Command, args []string) error { PackagePath: resolvedPath, MatchFilesGlob: pkg.MatchAllKRM, PreserveSeqIndent: true, - PackageFileName: kptfile.KptFileName, + PackageFileName: kptfilev1.KptFileName, IncludeSubpackages: true, WrapBareSeqNode: true, }) diff --git a/thirdparty/cmdconfig/commands/cmdtree/cmdtree.go b/thirdparty/cmdconfig/commands/cmdtree/cmdtree.go index b368f0bc1c..e9f6aa183b 100644 --- a/thirdparty/cmdconfig/commands/cmdtree/cmdtree.go +++ b/thirdparty/cmdconfig/commands/cmdtree/cmdtree.go @@ -23,8 +23,8 @@ import ( "path/filepath" "strings" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/internal/docs/generated/pkgdocs" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" argsutil "github.com/kptdev/kpt/pkg/lib/util/args" "github.com/kptdev/kpt/pkg/printer" "github.com/kptdev/kpt/thirdparty/cmdconfig/commands/runner" diff --git a/thirdparty/cmdconfig/commands/cmdtree/tree.go b/thirdparty/cmdconfig/commands/cmdtree/tree.go index 5931a80ef8..a165c21100 100644 --- a/thirdparty/cmdconfig/commands/cmdtree/tree.go +++ b/thirdparty/cmdconfig/commands/cmdtree/tree.go @@ -23,7 +23,7 @@ import ( "sort" "strings" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/xlab/treeprint" "sigs.k8s.io/kustomize/kyaml/kio/kioutil" "sigs.k8s.io/kustomize/kyaml/yaml" diff --git a/thirdparty/cmdconfig/commands/runner/runner.go b/thirdparty/cmdconfig/commands/runner/runner.go index 3f74b868f8..07798b0662 100644 --- a/thirdparty/cmdconfig/commands/runner/runner.go +++ b/thirdparty/cmdconfig/commands/runner/runner.go @@ -12,7 +12,7 @@ import ( "strings" "github.com/go-errors/errors" - kptfilev1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/pkg/printer" "github.com/spf13/cobra" "sigs.k8s.io/kustomize/kyaml/pathutil" diff --git a/thirdparty/kyaml/runfn/runfn.go b/thirdparty/kyaml/runfn/runfn.go index 5306156b36..855758abc3 100644 --- a/thirdparty/kyaml/runfn/runfn.go +++ b/thirdparty/kyaml/runfn/runfn.go @@ -12,9 +12,10 @@ import ( "path/filepath" "strings" + fnresultv1 "github.com/kptdev/kpt/api/fnresult/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" fnruntime "github.com/kptdev/kpt/pkg/fn/runtime" "github.com/kptdev/kpt/pkg/lib/runneroptions" - "github.com/kptdev/kpt/pkg/lib/types" "github.com/kptdev/kpt/pkg/printer" "sigs.k8s.io/kustomize/kyaml/errors" "sigs.k8s.io/kustomize/kyaml/filesys" @@ -22,8 +23,6 @@ import ( "sigs.k8s.io/kustomize/kyaml/kio" "sigs.k8s.io/kustomize/kyaml/yaml" - fnresult "github.com/kptdev/kpt/pkg/api/fnresult/v1" - kptfile "github.com/kptdev/kpt/pkg/api/kptfile/v1" "github.com/kptdev/kpt/pkg/lib/pkg" ) @@ -38,7 +37,7 @@ type RunFns struct { Path string // uniquePath is the absolute version of Path - uniquePath types.UniquePath + uniquePath kptfilev1.UniquePath // FnConfigPath specifies a config file which contains the configs used in // function input. It can be absolute or relative to kpt working directory. @@ -63,7 +62,7 @@ type RunFns struct { // ResultsDir is where to write each functions results ResultsDir string - fnResults *fnresult.ResultList + fnResults *fnresultv1.ResultList // functionFilterProvider provides a filter to perform the function. // this is a variable so it can be mocked in tests @@ -93,9 +92,9 @@ type RunFns struct { // OriginalExec is the original exec commands OriginalExec string - Selector kptfile.Selector + Selector kptfilev1.Selector - Exclusion kptfile.Selector + Exclusion kptfilev1.Selector } // Execute runs the command @@ -126,7 +125,7 @@ func (r RunFns) getNodesAndFilters() ( PackagePath: string(r.uniquePath), MatchFilesGlob: pkg.MatchAllKRM, PreserveSeqIndent: true, - PackageFileName: kptfile.KptFileName, + PackageFileName: kptfilev1.KptFileName, IncludeSubpackages: true, WrapBareSeqNode: true, } @@ -201,8 +200,8 @@ func (r RunFns) runFunctions(input kio.Reader, output kio.Writer, fltrs []kio.Fi // select the resources on which function should be applied selectedInput, err = fnruntime.SelectInput( inputResources, - []kptfile.Selector{r.Selector}, - []kptfile.Selector{r.Exclusion}, + []kptfilev1.Selector{r.Selector}, + []kptfilev1.Selector{r.Exclusion}, &fnruntime.SelectionContext{RootPackagePath: r.uniquePath}) if err != nil { return err @@ -284,10 +283,10 @@ func (r *RunFns) init() error { if err != nil { return errors.Wrap(err) } - r.uniquePath = types.UniquePath(absPath) + r.uniquePath = kptfilev1.UniquePath(absPath) } - r.fnResults = fnresult.NewResultList() + r.fnResults = fnresultv1.NewResultList() // functionFilterProvider set the filter provider if r.functionFilterProvider == nil { @@ -326,7 +325,7 @@ func getUIDGID(asCurrentUser bool, currentUser currentUserFunc) (string, error) // getFunctionConfig returns yaml representation of functionConfig that can // be provided to a function as input. func (r *RunFns) getFunctionConfig() (*yaml.RNode, error) { - return kptfile.GetValidatedFnConfigFromPath(filesys.FileSystemOrOnDisk{}, "", r.FnConfigPath) + return kptfilev1.GetValidatedFnConfigFromPath(filesys.FileSystemOrOnDisk{}, "", r.FnConfigPath) } // defaultFnFilterProvider provides function filters @@ -346,7 +345,7 @@ func (r *RunFns) defaultFnFilterProvider(spec runtimeutil.FunctionSpec, fnConfig FunctionConfig: fnConfig, DeferFailure: spec.DeferFailure, } - fnResult := &fnresult.Result{ + fnResult := &fnresultv1.Result{ // TODO(droot): This is required for making structured results subpackage aware. // Enable this once test harness supports filepath based assertions. // Pkg: string(r.uniquePath), diff --git a/thirdparty/kyaml/runfn/runfn_test.go b/thirdparty/kyaml/runfn/runfn_test.go index fec8c00b71..d1096e4025 100644 --- a/thirdparty/kyaml/runfn/runfn_test.go +++ b/thirdparty/kyaml/runfn/runfn_test.go @@ -10,8 +10,8 @@ import ( "runtime" "testing" - fnresult "github.com/kptdev/kpt/pkg/api/fnresult/v1" - v1 "github.com/kptdev/kpt/pkg/api/kptfile/v1" + fnresultv1 "github.com/kptdev/kpt/api/fnresult/v1" + kptfilev1 "github.com/kptdev/kpt/api/kptfile/v1" "github.com/kptdev/kpt/pkg/printer/fake" "github.com/stretchr/testify/assert" @@ -141,7 +141,7 @@ func TestCmd_Execute(t *testing.T) { functionFilterProvider: getFilterProvider(t), Function: fn, FnConfig: fnConfig, - fnResults: fnresult.NewResultList(), + fnResults: fnresultv1.NewResultList(), } if !assert.NoError(t, instance.Execute()) { t.FailNow() @@ -170,7 +170,7 @@ func TestCmd_Execute_includeMetaResources(t *testing.T) { // write a Kptfile to the directory of configuration if !assert.NoError(t, os.WriteFile( - filepath.Join(dir, v1.KptFileName), []byte(KptfileData), 0600)) { + filepath.Join(dir, kptfilev1.KptFileName), []byte(KptfileData), 0600)) { return } @@ -180,13 +180,13 @@ func TestCmd_Execute_includeMetaResources(t *testing.T) { functionFilterProvider: getMetaResourceFilterProvider(), Function: fn, FnConfig: fnConfig, - fnResults: fnresult.NewResultList(), + fnResults: fnresultv1.NewResultList(), } if !assert.NoError(t, instance.Execute()) { t.FailNow() } b, err := os.ReadFile( - filepath.Join(dir, v1.KptFileName)) + filepath.Join(dir, kptfilev1.KptFileName)) if !assert.NoError(t, err) { t.FailNow() } @@ -205,7 +205,7 @@ func TestCmd_Execute_notIncludeMetaResources(t *testing.T) { // write a Kptfile to the directory of configuration if !assert.NoError(t, os.WriteFile( - filepath.Join(dir, v1.KptFileName), []byte(KptfileData), 0600)) { + filepath.Join(dir, kptfilev1.KptFileName), []byte(KptfileData), 0600)) { return } @@ -213,13 +213,13 @@ func TestCmd_Execute_notIncludeMetaResources(t *testing.T) { Ctx: fake.CtxWithDefaultPrinter(), Path: dir, functionFilterProvider: getMetaResourceFilterProvider(), - fnResults: fnresult.NewResultList(), + fnResults: fnresultv1.NewResultList(), } if !assert.NoError(t, instance.Execute()) { t.FailNow() } b, err := os.ReadFile( - filepath.Join(dir, v1.KptFileName)) + filepath.Join(dir, kptfilev1.KptFileName)) if !assert.NoError(t, err) { t.FailNow() } @@ -299,7 +299,7 @@ func TestCmd_Execute_setFnConfigPath(t *testing.T) { Path: dir, Function: fn, FnConfig: fnConfig, - fnResults: fnresult.NewResultList(), + fnResults: fnresultv1.NewResultList(), } instance.functionFilterProvider = getFnConfigPathFilterProvider(t, &instance) // initialize the defaults @@ -340,7 +340,7 @@ func TestCmd_Execute_setOutput(t *testing.T) { functionFilterProvider: getFilterProvider(t), Function: fn, FnConfig: fnConfig, - fnResults: fnresult.NewResultList(), + fnResults: fnresultv1.NewResultList(), } // initialize the defaults assert.NoError(t, instance.init()) @@ -397,7 +397,7 @@ func TestCmd_Execute_setInput(t *testing.T) { functionFilterProvider: getFilterProvider(t), Function: fn, FnConfig: fnConfig, - fnResults: fnresult.NewResultList(), + fnResults: fnresultv1.NewResultList(), } // initialize the defaults assert.NoError(t, instance.init())