diff --git a/pkg/commands/build.go b/pkg/commands/build/build.go similarity index 98% rename from pkg/commands/build.go rename to pkg/commands/build/build.go index 338aadbf8..be97d46a4 100644 --- a/pkg/commands/build.go +++ b/pkg/commands/build/build.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package commands +package build import ( "errors" @@ -57,8 +57,8 @@ Use different transformer configurations by passing files to kustomize build somedir -t some-transformer-configfile,another-transformer-configfile ` -// newCmdBuild creates a new build command. -func newCmdBuild( +// NewCmdBuild creates a new build command. +func NewCmdBuild( out io.Writer, fs fs.FileSystem, decoder ifc.Decoder) *cobra.Command { var o buildOptions diff --git a/pkg/commands/build_test.go b/pkg/commands/build/build_test.go similarity index 97% rename from pkg/commands/build_test.go rename to pkg/commands/build/build_test.go index 66abaf01d..d4d3a97d1 100644 --- a/pkg/commands/build_test.go +++ b/pkg/commands/build/build_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package commands +package build import ( "bytes" @@ -22,12 +22,12 @@ import ( "os" "path/filepath" "reflect" - "sigs.k8s.io/kustomize/internal/k8sdeps" "strings" "testing" "github.com/ghodss/yaml" - + "sigs.k8s.io/kustomize/internal/k8sdeps" + "sigs.k8s.io/kustomize/pkg/commands/kustfile" "sigs.k8s.io/kustomize/pkg/constants" "sigs.k8s.io/kustomize/pkg/fs" ) @@ -99,7 +99,7 @@ func TestBuild(t *testing.T) { return nil }) // sanity check that we found the right folder - if !stringInSlice("simple", testcases) { + if !kustfile.StringInSlice("simple", testcases) { t.Fatalf("Error locating testcases") } diff --git a/pkg/commands/testdata/testcase-base-only/expected.diff b/pkg/commands/build/testdata/testcase-base-only/expected.diff similarity index 100% rename from pkg/commands/testdata/testcase-base-only/expected.diff rename to pkg/commands/build/testdata/testcase-base-only/expected.diff diff --git a/pkg/commands/testdata/testcase-base-only/expected.yaml b/pkg/commands/build/testdata/testcase-base-only/expected.yaml similarity index 100% rename from pkg/commands/testdata/testcase-base-only/expected.yaml rename to pkg/commands/build/testdata/testcase-base-only/expected.yaml diff --git a/pkg/commands/testdata/testcase-base-only/in/kustomization.yaml b/pkg/commands/build/testdata/testcase-base-only/in/kustomization.yaml similarity index 100% rename from pkg/commands/testdata/testcase-base-only/in/kustomization.yaml rename to pkg/commands/build/testdata/testcase-base-only/in/kustomization.yaml diff --git a/pkg/commands/testdata/testcase-base-only/in/resources/deployment.yaml b/pkg/commands/build/testdata/testcase-base-only/in/resources/deployment.yaml similarity index 100% rename from pkg/commands/testdata/testcase-base-only/in/resources/deployment.yaml rename to pkg/commands/build/testdata/testcase-base-only/in/resources/deployment.yaml diff --git a/pkg/commands/testdata/testcase-base-only/in/resources/networkpolicy.yaml b/pkg/commands/build/testdata/testcase-base-only/in/resources/networkpolicy.yaml similarity index 100% rename from pkg/commands/testdata/testcase-base-only/in/resources/networkpolicy.yaml rename to pkg/commands/build/testdata/testcase-base-only/in/resources/networkpolicy.yaml diff --git a/pkg/commands/testdata/testcase-base-only/in/resources/service.yaml b/pkg/commands/build/testdata/testcase-base-only/in/resources/service.yaml similarity index 100% rename from pkg/commands/testdata/testcase-base-only/in/resources/service.yaml rename to pkg/commands/build/testdata/testcase-base-only/in/resources/service.yaml diff --git a/pkg/commands/testdata/testcase-base-only/test.yaml b/pkg/commands/build/testdata/testcase-base-only/test.yaml similarity index 100% rename from pkg/commands/testdata/testcase-base-only/test.yaml rename to pkg/commands/build/testdata/testcase-base-only/test.yaml diff --git a/pkg/commands/testdata/testcase-configmaps/base/myapp/mycomponent/kustomization.yaml b/pkg/commands/build/testdata/testcase-configmaps/base/myapp/mycomponent/kustomization.yaml similarity index 100% rename from pkg/commands/testdata/testcase-configmaps/base/myapp/mycomponent/kustomization.yaml rename to pkg/commands/build/testdata/testcase-configmaps/base/myapp/mycomponent/kustomization.yaml diff --git a/pkg/commands/testdata/testcase-configmaps/base/myapp/mycomponent2/kustomization.yaml b/pkg/commands/build/testdata/testcase-configmaps/base/myapp/mycomponent2/kustomization.yaml similarity index 100% rename from pkg/commands/testdata/testcase-configmaps/base/myapp/mycomponent2/kustomization.yaml rename to pkg/commands/build/testdata/testcase-configmaps/base/myapp/mycomponent2/kustomization.yaml diff --git a/pkg/commands/testdata/testcase-configmaps/expected.diff b/pkg/commands/build/testdata/testcase-configmaps/expected.diff similarity index 100% rename from pkg/commands/testdata/testcase-configmaps/expected.diff rename to pkg/commands/build/testdata/testcase-configmaps/expected.diff diff --git a/pkg/commands/testdata/testcase-configmaps/expected.yaml b/pkg/commands/build/testdata/testcase-configmaps/expected.yaml similarity index 100% rename from pkg/commands/testdata/testcase-configmaps/expected.yaml rename to pkg/commands/build/testdata/testcase-configmaps/expected.yaml diff --git a/pkg/commands/testdata/testcase-configmaps/overlay/dev/kustomization.yaml b/pkg/commands/build/testdata/testcase-configmaps/overlay/dev/kustomization.yaml similarity index 100% rename from pkg/commands/testdata/testcase-configmaps/overlay/dev/kustomization.yaml rename to pkg/commands/build/testdata/testcase-configmaps/overlay/dev/kustomization.yaml diff --git a/pkg/commands/testdata/testcase-configmaps/overlay/dev/myapp/mycomponent/kustomization.yaml b/pkg/commands/build/testdata/testcase-configmaps/overlay/dev/myapp/mycomponent/kustomization.yaml similarity index 100% rename from pkg/commands/testdata/testcase-configmaps/overlay/dev/myapp/mycomponent/kustomization.yaml rename to pkg/commands/build/testdata/testcase-configmaps/overlay/dev/myapp/mycomponent/kustomization.yaml diff --git a/pkg/commands/testdata/testcase-configmaps/overlay/dev/myapp/mycomponent2/kustomization.yaml b/pkg/commands/build/testdata/testcase-configmaps/overlay/dev/myapp/mycomponent2/kustomization.yaml similarity index 100% rename from pkg/commands/testdata/testcase-configmaps/overlay/dev/myapp/mycomponent2/kustomization.yaml rename to pkg/commands/build/testdata/testcase-configmaps/overlay/dev/myapp/mycomponent2/kustomization.yaml diff --git a/pkg/commands/testdata/testcase-configmaps/test.yaml b/pkg/commands/build/testdata/testcase-configmaps/test.yaml similarity index 100% rename from pkg/commands/testdata/testcase-configmaps/test.yaml rename to pkg/commands/build/testdata/testcase-configmaps/test.yaml diff --git a/pkg/commands/testdata/testcase-crds/crd/bee.yaml b/pkg/commands/build/testdata/testcase-crds/crd/bee.yaml similarity index 100% rename from pkg/commands/testdata/testcase-crds/crd/bee.yaml rename to pkg/commands/build/testdata/testcase-crds/crd/bee.yaml diff --git a/pkg/commands/testdata/testcase-crds/crd/kustomization.yaml b/pkg/commands/build/testdata/testcase-crds/crd/kustomization.yaml similarity index 100% rename from pkg/commands/testdata/testcase-crds/crd/kustomization.yaml rename to pkg/commands/build/testdata/testcase-crds/crd/kustomization.yaml diff --git a/pkg/commands/testdata/testcase-crds/crd/mycrd.json b/pkg/commands/build/testdata/testcase-crds/crd/mycrd.json similarity index 100% rename from pkg/commands/testdata/testcase-crds/crd/mycrd.json rename to pkg/commands/build/testdata/testcase-crds/crd/mycrd.json diff --git a/pkg/commands/testdata/testcase-crds/crd/mykind.yaml b/pkg/commands/build/testdata/testcase-crds/crd/mykind.yaml similarity index 100% rename from pkg/commands/testdata/testcase-crds/crd/mykind.yaml rename to pkg/commands/build/testdata/testcase-crds/crd/mykind.yaml diff --git a/pkg/commands/testdata/testcase-crds/crd/secret.yaml b/pkg/commands/build/testdata/testcase-crds/crd/secret.yaml similarity index 100% rename from pkg/commands/testdata/testcase-crds/crd/secret.yaml rename to pkg/commands/build/testdata/testcase-crds/crd/secret.yaml diff --git a/pkg/commands/testdata/testcase-crds/expected.diff b/pkg/commands/build/testdata/testcase-crds/expected.diff similarity index 100% rename from pkg/commands/testdata/testcase-crds/expected.diff rename to pkg/commands/build/testdata/testcase-crds/expected.diff diff --git a/pkg/commands/testdata/testcase-crds/expected.yaml b/pkg/commands/build/testdata/testcase-crds/expected.yaml similarity index 100% rename from pkg/commands/testdata/testcase-crds/expected.yaml rename to pkg/commands/build/testdata/testcase-crds/expected.yaml diff --git a/pkg/commands/testdata/testcase-crds/test.yaml b/pkg/commands/build/testdata/testcase-crds/test.yaml similarity index 100% rename from pkg/commands/testdata/testcase-crds/test.yaml rename to pkg/commands/build/testdata/testcase-crds/test.yaml diff --git a/pkg/commands/testdata/testcase-multibases-conflict/base/kustomization.yaml b/pkg/commands/build/testdata/testcase-multibases-conflict/base/kustomization.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multibases-conflict/base/kustomization.yaml rename to pkg/commands/build/testdata/testcase-multibases-conflict/base/kustomization.yaml diff --git a/pkg/commands/testdata/testcase-multibases-conflict/base/rolebinding.yaml b/pkg/commands/build/testdata/testcase-multibases-conflict/base/rolebinding.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multibases-conflict/base/rolebinding.yaml rename to pkg/commands/build/testdata/testcase-multibases-conflict/base/rolebinding.yaml diff --git a/pkg/commands/testdata/testcase-multibases-conflict/base/serviceaccount.yaml b/pkg/commands/build/testdata/testcase-multibases-conflict/base/serviceaccount.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multibases-conflict/base/serviceaccount.yaml rename to pkg/commands/build/testdata/testcase-multibases-conflict/base/serviceaccount.yaml diff --git a/pkg/commands/testdata/testcase-multibases-conflict/combined/kustomization.yaml b/pkg/commands/build/testdata/testcase-multibases-conflict/combined/kustomization.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multibases-conflict/combined/kustomization.yaml rename to pkg/commands/build/testdata/testcase-multibases-conflict/combined/kustomization.yaml diff --git a/pkg/commands/testdata/testcase-multibases-conflict/overlays/a/kustomization.yaml b/pkg/commands/build/testdata/testcase-multibases-conflict/overlays/a/kustomization.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multibases-conflict/overlays/a/kustomization.yaml rename to pkg/commands/build/testdata/testcase-multibases-conflict/overlays/a/kustomization.yaml diff --git a/pkg/commands/testdata/testcase-multibases-conflict/overlays/a/serviceaccount.yaml b/pkg/commands/build/testdata/testcase-multibases-conflict/overlays/a/serviceaccount.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multibases-conflict/overlays/a/serviceaccount.yaml rename to pkg/commands/build/testdata/testcase-multibases-conflict/overlays/a/serviceaccount.yaml diff --git a/pkg/commands/testdata/testcase-multibases-conflict/overlays/b/kustomization.yaml b/pkg/commands/build/testdata/testcase-multibases-conflict/overlays/b/kustomization.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multibases-conflict/overlays/b/kustomization.yaml rename to pkg/commands/build/testdata/testcase-multibases-conflict/overlays/b/kustomization.yaml diff --git a/pkg/commands/testdata/testcase-multibases-conflict/test.yaml b/pkg/commands/build/testdata/testcase-multibases-conflict/test.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multibases-conflict/test.yaml rename to pkg/commands/build/testdata/testcase-multibases-conflict/test.yaml diff --git a/pkg/commands/testdata/testcase-multibases-nonconflict/base/kustomization.yaml b/pkg/commands/build/testdata/testcase-multibases-nonconflict/base/kustomization.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multibases-nonconflict/base/kustomization.yaml rename to pkg/commands/build/testdata/testcase-multibases-nonconflict/base/kustomization.yaml diff --git a/pkg/commands/testdata/testcase-multibases-nonconflict/base/rolebinding.yaml b/pkg/commands/build/testdata/testcase-multibases-nonconflict/base/rolebinding.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multibases-nonconflict/base/rolebinding.yaml rename to pkg/commands/build/testdata/testcase-multibases-nonconflict/base/rolebinding.yaml diff --git a/pkg/commands/testdata/testcase-multibases-nonconflict/base/serviceaccount.yaml b/pkg/commands/build/testdata/testcase-multibases-nonconflict/base/serviceaccount.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multibases-nonconflict/base/serviceaccount.yaml rename to pkg/commands/build/testdata/testcase-multibases-nonconflict/base/serviceaccount.yaml diff --git a/pkg/commands/testdata/testcase-multibases-nonconflict/combined/kustomization.yaml b/pkg/commands/build/testdata/testcase-multibases-nonconflict/combined/kustomization.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multibases-nonconflict/combined/kustomization.yaml rename to pkg/commands/build/testdata/testcase-multibases-nonconflict/combined/kustomization.yaml diff --git a/pkg/commands/testdata/testcase-multibases-nonconflict/expected.yaml b/pkg/commands/build/testdata/testcase-multibases-nonconflict/expected.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multibases-nonconflict/expected.yaml rename to pkg/commands/build/testdata/testcase-multibases-nonconflict/expected.yaml diff --git a/pkg/commands/testdata/testcase-multibases-nonconflict/overlays/a/kustomization.yaml b/pkg/commands/build/testdata/testcase-multibases-nonconflict/overlays/a/kustomization.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multibases-nonconflict/overlays/a/kustomization.yaml rename to pkg/commands/build/testdata/testcase-multibases-nonconflict/overlays/a/kustomization.yaml diff --git a/pkg/commands/testdata/testcase-multibases-nonconflict/overlays/b/kustomization.yaml b/pkg/commands/build/testdata/testcase-multibases-nonconflict/overlays/b/kustomization.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multibases-nonconflict/overlays/b/kustomization.yaml rename to pkg/commands/build/testdata/testcase-multibases-nonconflict/overlays/b/kustomization.yaml diff --git a/pkg/commands/testdata/testcase-multibases-nonconflict/test.yaml b/pkg/commands/build/testdata/testcase-multibases-nonconflict/test.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multibases-nonconflict/test.yaml rename to pkg/commands/build/testdata/testcase-multibases-nonconflict/test.yaml diff --git a/pkg/commands/testdata/testcase-multiple-patches-conflict/in/overlay/deployment-patch1.yaml b/pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/overlay/deployment-patch1.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multiple-patches-conflict/in/overlay/deployment-patch1.yaml rename to pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/overlay/deployment-patch1.yaml diff --git a/pkg/commands/testdata/testcase-multiple-patches-conflict/in/overlay/deployment-patch2.yaml b/pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/overlay/deployment-patch2.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multiple-patches-conflict/in/overlay/deployment-patch2.yaml rename to pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/overlay/deployment-patch2.yaml diff --git a/pkg/commands/testdata/testcase-multiple-patches-conflict/in/overlay/kustomization.yaml b/pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/overlay/kustomization.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multiple-patches-conflict/in/overlay/kustomization.yaml rename to pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/overlay/kustomization.yaml diff --git a/pkg/commands/testdata/testcase-multiple-patches-conflict/in/package/deployment.yaml b/pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/package/deployment.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multiple-patches-conflict/in/package/deployment.yaml rename to pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/package/deployment.yaml diff --git a/pkg/commands/testdata/testcase-multiple-patches-conflict/in/package/kustomization.yaml b/pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/package/kustomization.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multiple-patches-conflict/in/package/kustomization.yaml rename to pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/package/kustomization.yaml diff --git a/pkg/commands/testdata/testcase-multiple-patches-conflict/in/package/service.yaml b/pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/package/service.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multiple-patches-conflict/in/package/service.yaml rename to pkg/commands/build/testdata/testcase-multiple-patches-conflict/in/package/service.yaml diff --git a/pkg/commands/testdata/testcase-multiple-patches-conflict/test.yaml b/pkg/commands/build/testdata/testcase-multiple-patches-conflict/test.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multiple-patches-conflict/test.yaml rename to pkg/commands/build/testdata/testcase-multiple-patches-conflict/test.yaml diff --git a/pkg/commands/testdata/testcase-multiple-patches-noconflict/expected.diff b/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/expected.diff similarity index 100% rename from pkg/commands/testdata/testcase-multiple-patches-noconflict/expected.diff rename to pkg/commands/build/testdata/testcase-multiple-patches-noconflict/expected.diff diff --git a/pkg/commands/testdata/testcase-multiple-patches-noconflict/expected.yaml b/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/expected.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multiple-patches-noconflict/expected.yaml rename to pkg/commands/build/testdata/testcase-multiple-patches-noconflict/expected.yaml diff --git a/pkg/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/kustomization.yaml b/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/overlay/kustomization.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/kustomization.yaml rename to pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/overlay/kustomization.yaml diff --git a/pkg/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/patches/deployment-patch1.yaml b/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/overlay/patches/deployment-patch1.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/patches/deployment-patch1.yaml rename to pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/overlay/patches/deployment-patch1.yaml diff --git a/pkg/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/patches/deployment-patch2.yaml b/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/overlay/patches/deployment-patch2.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/patches/deployment-patch2.yaml rename to pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/overlay/patches/deployment-patch2.yaml diff --git a/pkg/commands/testdata/testcase-multiple-patches-noconflict/in/package/deployment.yaml b/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/package/deployment.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multiple-patches-noconflict/in/package/deployment.yaml rename to pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/package/deployment.yaml diff --git a/pkg/commands/testdata/testcase-multiple-patches-noconflict/in/package/kustomization.yaml b/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/package/kustomization.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multiple-patches-noconflict/in/package/kustomization.yaml rename to pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/package/kustomization.yaml diff --git a/pkg/commands/testdata/testcase-multiple-patches-noconflict/in/package/service.yaml b/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/package/service.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multiple-patches-noconflict/in/package/service.yaml rename to pkg/commands/build/testdata/testcase-multiple-patches-noconflict/in/package/service.yaml diff --git a/pkg/commands/testdata/testcase-multiple-patches-noconflict/test.yaml b/pkg/commands/build/testdata/testcase-multiple-patches-noconflict/test.yaml similarity index 100% rename from pkg/commands/testdata/testcase-multiple-patches-noconflict/test.yaml rename to pkg/commands/build/testdata/testcase-multiple-patches-noconflict/test.yaml diff --git a/pkg/commands/testdata/testcase-simple/expected.diff b/pkg/commands/build/testdata/testcase-simple/expected.diff similarity index 100% rename from pkg/commands/testdata/testcase-simple/expected.diff rename to pkg/commands/build/testdata/testcase-simple/expected.diff diff --git a/pkg/commands/testdata/testcase-simple/expected.yaml b/pkg/commands/build/testdata/testcase-simple/expected.yaml similarity index 100% rename from pkg/commands/testdata/testcase-simple/expected.yaml rename to pkg/commands/build/testdata/testcase-simple/expected.yaml diff --git a/pkg/commands/testdata/testcase-simple/test.yaml b/pkg/commands/build/testdata/testcase-simple/test.yaml similarity index 68% rename from pkg/commands/testdata/testcase-simple/test.yaml rename to pkg/commands/build/testdata/testcase-simple/test.yaml index 97f22e31e..82bc2939e 100644 --- a/pkg/commands/testdata/testcase-simple/test.yaml +++ b/pkg/commands/build/testdata/testcase-simple/test.yaml @@ -1,5 +1,5 @@ description: simple args: [] -filename: ../examplelayout/simple/instances/exampleinstance/ +filename: ../../examplelayout/simple/instances/exampleinstance/ expectedStdout: testdata/testcase-simple/expected.yaml expectedDiff: testdata/testcase-simple/expected.diff diff --git a/pkg/commands/testdata/testcase-single-overlay/expected.diff b/pkg/commands/build/testdata/testcase-single-overlay/expected.diff similarity index 100% rename from pkg/commands/testdata/testcase-single-overlay/expected.diff rename to pkg/commands/build/testdata/testcase-single-overlay/expected.diff diff --git a/pkg/commands/testdata/testcase-single-overlay/expected.yaml b/pkg/commands/build/testdata/testcase-single-overlay/expected.yaml similarity index 100% rename from pkg/commands/testdata/testcase-single-overlay/expected.yaml rename to pkg/commands/build/testdata/testcase-single-overlay/expected.yaml diff --git a/pkg/commands/testdata/testcase-single-overlay/in/overlay/deployment.yaml b/pkg/commands/build/testdata/testcase-single-overlay/in/overlay/deployment.yaml similarity index 100% rename from pkg/commands/testdata/testcase-single-overlay/in/overlay/deployment.yaml rename to pkg/commands/build/testdata/testcase-single-overlay/in/overlay/deployment.yaml diff --git a/pkg/commands/testdata/testcase-single-overlay/in/overlay/kustomization.yaml b/pkg/commands/build/testdata/testcase-single-overlay/in/overlay/kustomization.yaml similarity index 100% rename from pkg/commands/testdata/testcase-single-overlay/in/overlay/kustomization.yaml rename to pkg/commands/build/testdata/testcase-single-overlay/in/overlay/kustomization.yaml diff --git a/pkg/commands/testdata/testcase-single-overlay/in/package/deployment.yaml b/pkg/commands/build/testdata/testcase-single-overlay/in/package/deployment.yaml similarity index 100% rename from pkg/commands/testdata/testcase-single-overlay/in/package/deployment.yaml rename to pkg/commands/build/testdata/testcase-single-overlay/in/package/deployment.yaml diff --git a/pkg/commands/testdata/testcase-single-overlay/in/package/kustomization.yaml b/pkg/commands/build/testdata/testcase-single-overlay/in/package/kustomization.yaml similarity index 100% rename from pkg/commands/testdata/testcase-single-overlay/in/package/kustomization.yaml rename to pkg/commands/build/testdata/testcase-single-overlay/in/package/kustomization.yaml diff --git a/pkg/commands/testdata/testcase-single-overlay/in/package/service.yaml b/pkg/commands/build/testdata/testcase-single-overlay/in/package/service.yaml similarity index 100% rename from pkg/commands/testdata/testcase-single-overlay/in/package/service.yaml rename to pkg/commands/build/testdata/testcase-single-overlay/in/package/service.yaml diff --git a/pkg/commands/testdata/testcase-single-overlay/test.yaml b/pkg/commands/build/testdata/testcase-single-overlay/test.yaml similarity index 100% rename from pkg/commands/testdata/testcase-single-overlay/test.yaml rename to pkg/commands/build/testdata/testcase-single-overlay/test.yaml diff --git a/pkg/commands/testdata/testcase-variable-ref/expected.diff b/pkg/commands/build/testdata/testcase-variable-ref/expected.diff similarity index 100% rename from pkg/commands/testdata/testcase-variable-ref/expected.diff rename to pkg/commands/build/testdata/testcase-variable-ref/expected.diff diff --git a/pkg/commands/testdata/testcase-variable-ref/expected.yaml b/pkg/commands/build/testdata/testcase-variable-ref/expected.yaml similarity index 100% rename from pkg/commands/testdata/testcase-variable-ref/expected.yaml rename to pkg/commands/build/testdata/testcase-variable-ref/expected.yaml diff --git a/pkg/commands/testdata/testcase-variable-ref/in/overlay/kustomization.yaml b/pkg/commands/build/testdata/testcase-variable-ref/in/overlay/kustomization.yaml similarity index 100% rename from pkg/commands/testdata/testcase-variable-ref/in/overlay/kustomization.yaml rename to pkg/commands/build/testdata/testcase-variable-ref/in/overlay/kustomization.yaml diff --git a/pkg/commands/testdata/testcase-variable-ref/in/package/cockroachdb-statefulset-secure.yaml b/pkg/commands/build/testdata/testcase-variable-ref/in/package/cockroachdb-statefulset-secure.yaml similarity index 100% rename from pkg/commands/testdata/testcase-variable-ref/in/package/cockroachdb-statefulset-secure.yaml rename to pkg/commands/build/testdata/testcase-variable-ref/in/package/cockroachdb-statefulset-secure.yaml diff --git a/pkg/commands/testdata/testcase-variable-ref/in/package/cronjob.yaml b/pkg/commands/build/testdata/testcase-variable-ref/in/package/cronjob.yaml similarity index 100% rename from pkg/commands/testdata/testcase-variable-ref/in/package/cronjob.yaml rename to pkg/commands/build/testdata/testcase-variable-ref/in/package/cronjob.yaml diff --git a/pkg/commands/testdata/testcase-variable-ref/in/package/kustomization.yaml b/pkg/commands/build/testdata/testcase-variable-ref/in/package/kustomization.yaml similarity index 100% rename from pkg/commands/testdata/testcase-variable-ref/in/package/kustomization.yaml rename to pkg/commands/build/testdata/testcase-variable-ref/in/package/kustomization.yaml diff --git a/pkg/commands/testdata/testcase-variable-ref/test.yaml b/pkg/commands/build/testdata/testcase-variable-ref/test.yaml similarity index 100% rename from pkg/commands/testdata/testcase-variable-ref/test.yaml rename to pkg/commands/build/testdata/testcase-variable-ref/test.yaml diff --git a/pkg/commands/commands.go b/pkg/commands/commands.go index afb803ca5..f4faca65d 100644 --- a/pkg/commands/commands.go +++ b/pkg/commands/commands.go @@ -22,6 +22,9 @@ import ( "os" "github.com/spf13/cobra" + "sigs.k8s.io/kustomize/pkg/commands/build" + "sigs.k8s.io/kustomize/pkg/commands/edit" + "sigs.k8s.io/kustomize/pkg/commands/misc" "sigs.k8s.io/kustomize/pkg/fs" "sigs.k8s.io/kustomize/pkg/ifc" ) @@ -44,10 +47,10 @@ See https://sigs.k8s.io/kustomize c.AddCommand( // TODO: Make consistent API for newCmd* functions. - newCmdBuild(stdOut, fsys, decoder), - newCmdEdit(fsys, validator), - newCmdConfig(fsys), - newCmdVersion(stdOut), + build.NewCmdBuild(stdOut, fsys, decoder), + edit.NewCmdEdit(fsys, validator), + misc.NewCmdConfig(fsys), + misc.NewCmdVersion(stdOut), ) c.PersistentFlags().AddGoFlagSet(flag.CommandLine) @@ -56,85 +59,3 @@ See https://sigs.k8s.io/kustomize flag.CommandLine.Parse([]string{}) return c } - -// newCmdEdit returns an instance of 'edit' subcommand. -func newCmdEdit(fsys fs.FileSystem, v ifc.Validator) *cobra.Command { - c := &cobra.Command{ - Use: "edit", - Short: "Edits a kustomization file", - Long: "", - Example: ` - # Adds a configmap to the kustomization file - kustomize edit add configmap NAME --from-literal=k=v - - # Sets the nameprefix field - kustomize edit set nameprefix -`, - Args: cobra.MinimumNArgs(1), - } - c.AddCommand( - newCmdAdd(fsys, v), - newCmdSet(fsys, v), - ) - return c -} - -// newAddCommand returns an instance of 'add' subcommand. -func newCmdAdd(fsys fs.FileSystem, v ifc.Validator) *cobra.Command { - c := &cobra.Command{ - Use: "add", - Short: "Adds configmap/resource/patch/base to the kustomization file.", - Long: "", - Example: ` - # Adds a configmap to the kustomization file - kustomize edit add configmap NAME --from-literal=k=v - - # Adds a resource to the kustomization - kustomize edit add resource - - # Adds a patch to the kustomization - kustomize edit add patch - - # Adds one or more base directories to the kustomization - kustomize edit add base - kustomize edit add base ,, - - # Adds one or more commonLabels to the kustomization - kustomize edit add label {labelKey1:labelValue1},{labelKey2:labelValue2} - - # Adds one or more commonAnnotations to the kustomization - kustomize edit add annotation {annotationKey1:annotationValue1},{annotationKey2:annotationValue2} -`, - Args: cobra.MinimumNArgs(1), - } - c.AddCommand( - newCmdAddResource(fsys), - newCmdAddPatch(fsys), - newCmdAddConfigMap(fsys), - newCmdAddBase(fsys), - newCmdAddLabel(fsys, v.MakeLabelValidator()), - newCmdAddAnnotation(fsys, v.MakeAnnotationValidator()), - ) - return c -} - -// newSetCommand returns an instance of 'set' subcommand. -func newCmdSet(fsys fs.FileSystem, v ifc.Validator) *cobra.Command { - c := &cobra.Command{ - Use: "set", - Short: "Sets the value of different fields in kustomization file.", - Long: "", - Example: ` - # Sets the nameprefix field - kustomize edit set nameprefix -`, - Args: cobra.MinimumNArgs(1), - } - - c.AddCommand( - newCmdSetNamePrefix(fsys), - newCmdSetNamespace(fsys, v), - newCmdSetImageTag(fsys), - ) - return c -} diff --git a/pkg/commands/addbase.go b/pkg/commands/edit/add/addbase.go similarity index 90% rename from pkg/commands/addbase.go rename to pkg/commands/edit/add/addbase.go index 9dee60a8a..74ab05f9b 100644 --- a/pkg/commands/addbase.go +++ b/pkg/commands/edit/add/addbase.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package commands +package add import ( "errors" @@ -22,7 +22,7 @@ import ( "strings" "github.com/spf13/cobra" - + "sigs.k8s.io/kustomize/pkg/commands/kustfile" "sigs.k8s.io/kustomize/pkg/constants" "sigs.k8s.io/kustomize/pkg/fs" ) @@ -71,12 +71,12 @@ func (o *addBaseOptions) Complete(cmd *cobra.Command, args []string) error { // RunAddBase runs addBase command (do real work). func (o *addBaseOptions) RunAddBase(fsys fs.FileSystem) error { - mf, err := newKustomizationFile(constants.KustomizationFileName, fsys) + mf, err := kustfile.NewKustomizationFile(constants.KustomizationFileName, fsys) if err != nil { return err } - m, err := mf.read() + m, err := mf.Read() if err != nil { return err } @@ -87,12 +87,12 @@ func (o *addBaseOptions) RunAddBase(fsys fs.FileSystem) error { if !fsys.Exists(path) { return errors.New(path + " does not exist") } - if stringInSlice(path, m.Bases) { + if kustfile.StringInSlice(path, m.Bases) { return fmt.Errorf("base %s already in kustomization file", path) } m.Bases = append(m.Bases, path) } - return mf.write(m) + return mf.Write(m) } diff --git a/pkg/commands/addbase_test.go b/pkg/commands/edit/add/addbase_test.go similarity index 91% rename from pkg/commands/addbase_test.go rename to pkg/commands/edit/add/addbase_test.go index 9a071f397..6d28c9ec1 100644 --- a/pkg/commands/addbase_test.go +++ b/pkg/commands/edit/add/addbase_test.go @@ -14,13 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -package commands +package add import ( + "strings" "testing" - "strings" - + "sigs.k8s.io/kustomize/pkg/commands/kustfile" "sigs.k8s.io/kustomize/pkg/constants" "sigs.k8s.io/kustomize/pkg/fs" ) @@ -35,7 +35,7 @@ func TestAddBaseHappyPath(t *testing.T) { for _, base := range bases { fakeFS.Mkdir(base) } - fakeFS.WriteFile(constants.KustomizationFileName, []byte(kustomizationContent)) + fakeFS.WriteTestKustomization() cmd := newCmdAddBase(fakeFS) args := []string{baseDirectoryPaths} @@ -62,7 +62,7 @@ func TestAddBaseAlreadyThere(t *testing.T) { for _, base := range bases { fakeFS.Mkdir(base) } - fakeFS.WriteFile(constants.KustomizationFileName, []byte(kustomizationContent)) + fakeFS.WriteTestKustomization() cmd := newCmdAddBase(fakeFS) args := []string{baseDirectoryPaths} @@ -79,7 +79,7 @@ func TestAddBaseAlreadyThere(t *testing.T) { for _, base := range bases { msg := "base " + base + " already in kustomization file" expectedErrors = append(expectedErrors, msg) - if !stringInSlice(msg, expectedErrors) { + if !kustfile.StringInSlice(msg, expectedErrors) { t.Errorf("unexpected error %v", err) } } diff --git a/pkg/commands/addmetadata.go b/pkg/commands/edit/add/addmetadata.go similarity index 96% rename from pkg/commands/addmetadata.go rename to pkg/commands/edit/add/addmetadata.go index e51ef4a79..b439840cb 100644 --- a/pkg/commands/addmetadata.go +++ b/pkg/commands/edit/add/addmetadata.go @@ -14,13 +14,14 @@ See the License for the specific language governing permissions and limitations under the License. */ -package commands +package add import ( "fmt" "strings" "github.com/spf13/cobra" + "sigs.k8s.io/kustomize/pkg/commands/kustfile" "sigs.k8s.io/kustomize/pkg/constants" "sigs.k8s.io/kustomize/pkg/fs" "sigs.k8s.io/kustomize/pkg/types" @@ -91,11 +92,11 @@ func (o *addMetadataOptions) runE( if err != nil { return err } - kf, err := newKustomizationFile(constants.KustomizationFileName, fSys) + kf, err := kustfile.NewKustomizationFile(constants.KustomizationFileName, fSys) if err != nil { return err } - m, err := kf.read() + m, err := kf.Read() if err != nil { return err } @@ -103,7 +104,7 @@ func (o *addMetadataOptions) runE( if err != nil { return err } - return kf.write(m) + return kf.Write(m) } // validateAndParse validates `add` commands and parses them into o.metadata diff --git a/pkg/commands/addmetadata_test.go b/pkg/commands/edit/add/addmetadata_test.go similarity index 92% rename from pkg/commands/addmetadata_test.go rename to pkg/commands/edit/add/addmetadata_test.go index 8f7f6bfdb..317b9e984 100644 --- a/pkg/commands/addmetadata_test.go +++ b/pkg/commands/edit/add/addmetadata_test.go @@ -14,11 +14,12 @@ See the License for the specific language governing permissions and limitations under the License. */ -package commands +package add import ( "testing" + "sigs.k8s.io/kustomize/pkg/commands/kustfile" "sigs.k8s.io/kustomize/pkg/constants" "sigs.k8s.io/kustomize/pkg/fs" "sigs.k8s.io/kustomize/pkg/types" @@ -27,12 +28,12 @@ import ( func makeKustomization(t *testing.T) *types.Kustomization { fakeFS := fs.MakeFakeFS() - fakeFS.WriteFile(constants.KustomizationFileName, []byte(kustomizationContent)) - kf, err := newKustomizationFile(constants.KustomizationFileName, fakeFS) + fakeFS.WriteTestKustomization() + kf, err := kustfile.NewKustomizationFile(constants.KustomizationFileName, fakeFS) if err != nil { t.Errorf("unexpected new error %v", err) } - m, err := kf.read() + m, err := kf.Read() if err != nil { t.Errorf("unexpected read error %v", err) } @@ -92,7 +93,7 @@ func TestAddAnnotationInvalidFormat(t *testing.T) { func TestAddAnnotationManyArgs(t *testing.T) { fakeFS := fs.MakeFakeFS() - fakeFS.WriteFile(constants.KustomizationFileName, []byte(kustomizationContent)) + fakeFS.WriteTestKustomization() v := validators.MakeHappyMapValidator(t) cmd := newCmdAddAnnotation(fakeFS, v.Validator) args := []string{"k1:v1,k2:v2,k3:v3,k4:v5"} @@ -135,7 +136,7 @@ func TestAddAnnotationTooManyColons(t *testing.T) { func TestAddAnnotationNoValue(t *testing.T) { fakeFS := fs.MakeFakeFS() - fakeFS.WriteFile(constants.KustomizationFileName, []byte(kustomizationContent)) + fakeFS.WriteTestKustomization() v := validators.MakeHappyMapValidator(t) cmd := newCmdAddAnnotation(fakeFS, v.Validator) args := []string{"no:,value"} @@ -148,7 +149,7 @@ func TestAddAnnotationNoValue(t *testing.T) { func TestAddAnnotationMultipleArgs(t *testing.T) { fakeFS := fs.MakeFakeFS() - fakeFS.WriteFile(constants.KustomizationFileName, []byte(kustomizationContent)) + fakeFS.WriteTestKustomization() v := validators.MakeHappyMapValidator(t) cmd := newCmdAddAnnotation(fakeFS, v.Validator) args := []string{"this:annotation", "has:spaces"} @@ -245,7 +246,7 @@ func TestAddLabelTooManyColons(t *testing.T) { func TestAddLabelNoValue(t *testing.T) { fakeFS := fs.MakeFakeFS() - fakeFS.WriteFile(constants.KustomizationFileName, []byte(kustomizationContent)) + fakeFS.WriteTestKustomization() v := validators.MakeHappyMapValidator(t) cmd := newCmdAddLabel(fakeFS, v.Validator) args := []string{"no,value:"} @@ -258,7 +259,7 @@ func TestAddLabelNoValue(t *testing.T) { func TestAddLabelMultipleArgs(t *testing.T) { fakeFS := fs.MakeFakeFS() - fakeFS.WriteFile(constants.KustomizationFileName, []byte(kustomizationContent)) + fakeFS.WriteTestKustomization() v := validators.MakeHappyMapValidator(t) cmd := newCmdAddLabel(fakeFS, v.Validator) args := []string{"this:input", "has:spaces"} diff --git a/pkg/commands/addpatch.go b/pkg/commands/edit/add/addpatch.go similarity index 89% rename from pkg/commands/addpatch.go rename to pkg/commands/edit/add/addpatch.go index 3b307089f..659f5017b 100644 --- a/pkg/commands/addpatch.go +++ b/pkg/commands/edit/add/addpatch.go @@ -14,14 +14,14 @@ See the License for the specific language governing permissions and limitations under the License. */ -package commands +package add import ( "errors" "log" "github.com/spf13/cobra" - + "sigs.k8s.io/kustomize/pkg/commands/kustfile" "sigs.k8s.io/kustomize/pkg/constants" "sigs.k8s.io/kustomize/pkg/fs" "sigs.k8s.io/kustomize/pkg/patch" @@ -79,23 +79,23 @@ func (o *addPatchOptions) RunAddPatch(fsys fs.FileSystem) error { return nil } - mf, err := newKustomizationFile(constants.KustomizationFileName, fsys) + mf, err := kustfile.NewKustomizationFile(constants.KustomizationFileName, fsys) if err != nil { return err } - m, err := mf.read() + m, err := mf.Read() if err != nil { return err } for _, p := range patches { - if patch.Exist(m.PatchesStrategicMerge, p) || stringInSlice(p, m.Patches) { + if patch.Exist(m.PatchesStrategicMerge, p) || kustfile.StringInSlice(p, m.Patches) { log.Printf("patch %s already in kustomization file", p) continue } m.PatchesStrategicMerge = patch.Append(m.PatchesStrategicMerge, p) } - return mf.write(m) + return mf.Write(m) } diff --git a/pkg/commands/addpatch_test.go b/pkg/commands/edit/add/addpatch_test.go similarity index 92% rename from pkg/commands/addpatch_test.go rename to pkg/commands/edit/add/addpatch_test.go index 711936d8b..4d6f81690 100644 --- a/pkg/commands/addpatch_test.go +++ b/pkg/commands/edit/add/addpatch_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package commands +package add import ( "testing" @@ -37,7 +37,7 @@ func TestAddPatchHappyPath(t *testing.T) { fakeFS := fs.MakeFakeFS() fakeFS.WriteFile(patchFileName, []byte(patchFileContent)) fakeFS.WriteFile(patchFileName+"another", []byte(patchFileContent)) - fakeFS.WriteFile(constants.KustomizationFileName, []byte(kustomizationContent)) + fakeFS.WriteTestKustomization() cmd := newCmdAddPatch(fakeFS) args := []string{patchFileName + "*"} @@ -60,7 +60,7 @@ func TestAddPatchHappyPath(t *testing.T) { func TestAddPatchAlreadyThere(t *testing.T) { fakeFS := fs.MakeFakeFS() fakeFS.WriteFile(patchFileName, []byte(patchFileContent)) - fakeFS.WriteFile(constants.KustomizationFileName, []byte(kustomizationContent)) + fakeFS.WriteTestKustomization() cmd := newCmdAddPatch(fakeFS) args := []string{patchFileName} diff --git a/pkg/commands/addresource.go b/pkg/commands/edit/add/addresource.go similarity index 90% rename from pkg/commands/addresource.go rename to pkg/commands/edit/add/addresource.go index 966179a1b..30b30b121 100644 --- a/pkg/commands/addresource.go +++ b/pkg/commands/edit/add/addresource.go @@ -14,14 +14,14 @@ See the License for the specific language governing permissions and limitations under the License. */ -package commands +package add import ( "errors" "log" "github.com/spf13/cobra" - + "sigs.k8s.io/kustomize/pkg/commands/kustfile" "sigs.k8s.io/kustomize/pkg/constants" "sigs.k8s.io/kustomize/pkg/fs" ) @@ -78,23 +78,23 @@ func (o *addResourceOptions) RunAddResource(fsys fs.FileSystem) error { return nil } - mf, err := newKustomizationFile(constants.KustomizationFileName, fsys) + mf, err := kustfile.NewKustomizationFile(constants.KustomizationFileName, fsys) if err != nil { return err } - m, err := mf.read() + m, err := mf.Read() if err != nil { return err } for _, resource := range resources { - if stringInSlice(resource, m.Resources) { + if kustfile.StringInSlice(resource, m.Resources) { log.Printf("resource %s already in kustomization file", resource) continue } m.Resources = append(m.Resources, resource) } - return mf.write(m) + return mf.Write(m) } diff --git a/pkg/commands/addresource_test.go b/pkg/commands/edit/add/addresource_test.go similarity index 75% rename from pkg/commands/addresource_test.go rename to pkg/commands/edit/add/addresource_test.go index 3b2f77822..b3c972a8f 100644 --- a/pkg/commands/addresource_test.go +++ b/pkg/commands/edit/add/addresource_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package commands +package add import ( "strings" @@ -29,22 +29,6 @@ const ( resourceFileContent = ` Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. -` - kustomizationContent = `namePrefix: some-prefix -# Labels to add to all objects and selectors. -# These labels would also be used to form the selector for apply --prune -# Named differently than “labels” to avoid confusion with metadata for this object -commonLabels: - app: helloworld -commonAnnotations: - note: This is an example annotation -resources: [] -#- service.yaml -#- ../some-dir/ -# There could also be configmaps in Base, which would make these overlays -configMapGenerator: [] -# There could be secrets in Base, if just using a fork/rebase workflow -secretGenerator: [] ` ) @@ -52,7 +36,7 @@ func TestAddResourceHappyPath(t *testing.T) { fakeFS := fs.MakeFakeFS() fakeFS.WriteFile(resourceFileName, []byte(resourceFileContent)) fakeFS.WriteFile(resourceFileName+"another", []byte(resourceFileContent)) - fakeFS.WriteFile(constants.KustomizationFileName, []byte(kustomizationContent)) + fakeFS.WriteTestKustomization() cmd := newCmdAddResource(fakeFS) args := []string{resourceFileName + "*"} @@ -75,7 +59,7 @@ func TestAddResourceHappyPath(t *testing.T) { func TestAddResourceAlreadyThere(t *testing.T) { fakeFS := fs.MakeFakeFS() fakeFS.WriteFile(resourceFileName, []byte(resourceFileContent)) - fakeFS.WriteFile(constants.KustomizationFileName, []byte(kustomizationContent)) + fakeFS.WriteTestKustomization() cmd := newCmdAddResource(fakeFS) args := []string{resourceFileName} diff --git a/pkg/commands/edit/add/all.go b/pkg/commands/edit/add/all.go new file mode 100644 index 000000000..ac269d607 --- /dev/null +++ b/pkg/commands/edit/add/all.go @@ -0,0 +1,62 @@ +/* +Copyright 2017 The Kubernetes 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. +*/ + +package add + +import ( + "github.com/spf13/cobra" + "sigs.k8s.io/kustomize/pkg/fs" + "sigs.k8s.io/kustomize/pkg/ifc" +) + +// NewCmdAdd returns an instance of 'add' subcommand. +func NewCmdAdd(fsys fs.FileSystem, v ifc.Validator) *cobra.Command { + c := &cobra.Command{ + Use: "add", + Short: "Adds configmap/resource/patch/base to the kustomization file.", + Long: "", + Example: ` + # Adds a configmap to the kustomization file + kustomize edit add configmap NAME --from-literal=k=v + + # Adds a resource to the kustomization + kustomize edit add resource + + # Adds a patch to the kustomization + kustomize edit add patch + + # Adds one or more base directories to the kustomization + kustomize edit add base + kustomize edit add base ,, + + # Adds one or more commonLabels to the kustomization + kustomize edit add label {labelKey1:labelValue1},{labelKey2:labelValue2} + + # Adds one or more commonAnnotations to the kustomization + kustomize edit add annotation {annotationKey1:annotationValue1},{annotationKey2:annotationValue2} +`, + Args: cobra.MinimumNArgs(1), + } + c.AddCommand( + newCmdAddResource(fsys), + newCmdAddPatch(fsys), + newCmdAddConfigMap(fsys), + newCmdAddBase(fsys), + newCmdAddLabel(fsys, v.MakeLabelValidator()), + newCmdAddAnnotation(fsys, v.MakeAnnotationValidator()), + ) + return c +} diff --git a/pkg/commands/cmapflagsandargs.go b/pkg/commands/edit/add/cmapflagsandargs.go similarity index 99% rename from pkg/commands/cmapflagsandargs.go rename to pkg/commands/edit/add/cmapflagsandargs.go index 666f2094b..6575d2bde 100644 --- a/pkg/commands/cmapflagsandargs.go +++ b/pkg/commands/edit/add/cmapflagsandargs.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package commands +package add import ( "fmt" diff --git a/pkg/commands/cmapflagsandargs_test.go b/pkg/commands/edit/add/cmapflagsandargs_test.go similarity index 99% rename from pkg/commands/cmapflagsandargs_test.go rename to pkg/commands/edit/add/cmapflagsandargs_test.go index cd1cece1c..ce5ed57ee 100644 --- a/pkg/commands/cmapflagsandargs_test.go +++ b/pkg/commands/edit/add/cmapflagsandargs_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package commands +package add import ( "reflect" diff --git a/pkg/commands/configmap.go b/pkg/commands/edit/add/configmap.go similarity index 94% rename from pkg/commands/configmap.go rename to pkg/commands/edit/add/configmap.go index 5baceae29..d9c7dadc4 100644 --- a/pkg/commands/configmap.go +++ b/pkg/commands/edit/add/configmap.go @@ -14,13 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -package commands +package add import ( "fmt" "github.com/spf13/cobra" - + "sigs.k8s.io/kustomize/pkg/commands/kustfile" "sigs.k8s.io/kustomize/pkg/configmapandsecret" "sigs.k8s.io/kustomize/pkg/constants" "sigs.k8s.io/kustomize/pkg/fs" @@ -28,6 +28,7 @@ import ( "sigs.k8s.io/kustomize/pkg/types" ) +// newCmdAddConfigMap returns a new command. func newCmdAddConfigMap(fSys fs.FileSystem) *cobra.Command { var flagsAndArgs cMapFlagsAndArgs cmd := &cobra.Command{ @@ -56,12 +57,12 @@ func newCmdAddConfigMap(fSys fs.FileSystem) *cobra.Command { } // Load the kustomization file. - mf, err := newKustomizationFile(constants.KustomizationFileName, fSys) + mf, err := kustfile.NewKustomizationFile(constants.KustomizationFileName, fSys) if err != nil { return err } - kustomization, err := mf.read() + kustomization, err := mf.Read() if err != nil { return err } @@ -76,7 +77,7 @@ func newCmdAddConfigMap(fSys fs.FileSystem) *cobra.Command { } // Write out the kustomization file with added configmap. - return mf.write(kustomization) + return mf.Write(kustomization) }, } diff --git a/pkg/commands/configmap_test.go b/pkg/commands/edit/add/configmap_test.go similarity index 99% rename from pkg/commands/configmap_test.go rename to pkg/commands/edit/add/configmap_test.go index 682db05e0..5dc212a83 100644 --- a/pkg/commands/configmap_test.go +++ b/pkg/commands/edit/add/configmap_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package commands +package add import ( "testing" diff --git a/pkg/commands/util.go b/pkg/commands/edit/add/util.go similarity index 98% rename from pkg/commands/util.go rename to pkg/commands/edit/add/util.go index 4ffd28dbb..684439d9a 100644 --- a/pkg/commands/util.go +++ b/pkg/commands/edit/add/util.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package commands +package add import ( "log" diff --git a/pkg/commands/edit/all.go b/pkg/commands/edit/all.go new file mode 100644 index 000000000..791bd90da --- /dev/null +++ b/pkg/commands/edit/all.go @@ -0,0 +1,47 @@ +/* +Copyright 2017 The Kubernetes 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. +*/ + +package edit + +import ( + "github.com/spf13/cobra" + "sigs.k8s.io/kustomize/pkg/commands/edit/add" + "sigs.k8s.io/kustomize/pkg/commands/edit/set" + "sigs.k8s.io/kustomize/pkg/fs" + "sigs.k8s.io/kustomize/pkg/ifc" +) + +// NewCmdEdit returns an instance of 'edit' subcommand. +func NewCmdEdit(fsys fs.FileSystem, v ifc.Validator) *cobra.Command { + c := &cobra.Command{ + Use: "edit", + Short: "Edits a kustomization file", + Long: "", + Example: ` + # Adds a configmap to the kustomization file + kustomize edit add configmap NAME --from-literal=k=v + + # Sets the nameprefix field + kustomize edit set nameprefix +`, + Args: cobra.MinimumNArgs(1), + } + c.AddCommand( + add.NewCmdAdd(fsys, v), + set.NewCmdSet(fsys, v), + ) + return c +} diff --git a/pkg/commands/edit/set/all.go b/pkg/commands/edit/set/all.go new file mode 100644 index 000000000..466b0c74d --- /dev/null +++ b/pkg/commands/edit/set/all.go @@ -0,0 +1,44 @@ +/* +Copyright 2017 The Kubernetes 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. +*/ + +package set + +import ( + "github.com/spf13/cobra" + "sigs.k8s.io/kustomize/pkg/fs" + "sigs.k8s.io/kustomize/pkg/ifc" +) + +// NewCmdSet returns an instance of 'set' subcommand. +func NewCmdSet(fsys fs.FileSystem, v ifc.Validator) *cobra.Command { + c := &cobra.Command{ + Use: "set", + Short: "Sets the value of different fields in kustomization file.", + Long: "", + Example: ` + # Sets the nameprefix field + kustomize edit set nameprefix +`, + Args: cobra.MinimumNArgs(1), + } + + c.AddCommand( + newCmdSetNamePrefix(fsys), + newCmdSetNamespace(fsys, v), + newCmdSetImageTag(fsys), + ) + return c +} diff --git a/pkg/commands/set_name_prefix.go b/pkg/commands/edit/set/set_name_prefix.go similarity index 92% rename from pkg/commands/set_name_prefix.go rename to pkg/commands/edit/set/set_name_prefix.go index 0b361af25..4da3a84b5 100644 --- a/pkg/commands/set_name_prefix.go +++ b/pkg/commands/edit/set/set_name_prefix.go @@ -14,13 +14,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -package commands +package set import ( "errors" "github.com/spf13/cobra" - + "sigs.k8s.io/kustomize/pkg/commands/kustfile" "sigs.k8s.io/kustomize/pkg/constants" "sigs.k8s.io/kustomize/pkg/fs" ) @@ -74,14 +74,14 @@ func (o *setNamePrefixOptions) Complete(cmd *cobra.Command, args []string) error // RunSetNamePrefix runs setNamePrefix command (does real work). func (o *setNamePrefixOptions) RunSetNamePrefix(fsys fs.FileSystem) error { - mf, err := newKustomizationFile(constants.KustomizationFileName, fsys) + mf, err := kustfile.NewKustomizationFile(constants.KustomizationFileName, fsys) if err != nil { return err } - m, err := mf.read() + m, err := mf.Read() if err != nil { return err } m.NamePrefix = o.prefix - return mf.write(m) + return mf.Write(m) } diff --git a/pkg/commands/set_name_prefix_test.go b/pkg/commands/edit/set/set_name_prefix_test.go similarity index 93% rename from pkg/commands/set_name_prefix_test.go rename to pkg/commands/edit/set/set_name_prefix_test.go index c6a08c6e7..a863771bc 100644 --- a/pkg/commands/set_name_prefix_test.go +++ b/pkg/commands/edit/set/set_name_prefix_test.go @@ -14,12 +14,11 @@ See the License for the specific language governing permissions and limitations under the License. */ -package commands +package set import ( - "testing" - "strings" + "testing" "sigs.k8s.io/kustomize/pkg/constants" "sigs.k8s.io/kustomize/pkg/fs" @@ -31,7 +30,7 @@ const ( func TestSetNamePrefixHappyPath(t *testing.T) { fakeFS := fs.MakeFakeFS() - fakeFS.WriteFile(constants.KustomizationFileName, []byte(kustomizationContent)) + fakeFS.WriteTestKustomization() cmd := newCmdSetNamePrefix(fakeFS) args := []string{goodPrefixValue} diff --git a/pkg/commands/setimagetag.go b/pkg/commands/edit/set/setimagetag.go similarity index 94% rename from pkg/commands/setimagetag.go rename to pkg/commands/edit/set/setimagetag.go index e6cd40a84..818227cdb 100644 --- a/pkg/commands/setimagetag.go +++ b/pkg/commands/edit/set/setimagetag.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package commands +package set import ( "errors" @@ -23,7 +23,7 @@ import ( "strings" "github.com/spf13/cobra" - + "sigs.k8s.io/kustomize/pkg/commands/kustfile" "sigs.k8s.io/kustomize/pkg/constants" "sigs.k8s.io/kustomize/pkg/fs" "sigs.k8s.io/kustomize/pkg/types" @@ -100,11 +100,11 @@ func (o *setImageTagOptions) Validate(args []string) error { // RunSetImageTags runs setImageTags command (does real work). func (o *setImageTagOptions) RunSetImageTags(fsys fs.FileSystem) error { - mf, err := newKustomizationFile(constants.KustomizationFileName, fsys) + mf, err := kustfile.NewKustomizationFile(constants.KustomizationFileName, fsys) if err != nil { return err } - m, err := mf.read() + m, err := mf.Read() if err != nil { return err } @@ -127,5 +127,5 @@ func (o *setImageTagOptions) RunSetImageTags(fsys fs.FileSystem) error { m.ImageTags = imageTags - return mf.write(m) + return mf.Write(m) } diff --git a/pkg/commands/setimagetag_test.go b/pkg/commands/edit/set/setimagetag_test.go similarity index 93% rename from pkg/commands/setimagetag_test.go rename to pkg/commands/edit/set/setimagetag_test.go index 6e49cce3b..e1f387022 100644 --- a/pkg/commands/setimagetag_test.go +++ b/pkg/commands/edit/set/setimagetag_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package commands +package set import ( "strings" @@ -26,7 +26,7 @@ import ( func TestSetImageTagsHappyPath(t *testing.T) { fakeFS := fs.MakeFakeFS() - fakeFS.WriteFile(constants.KustomizationFileName, []byte(kustomizationContent)) + fakeFS.WriteTestKustomization() cmd := newCmdSetImageTag(fakeFS) args := []string{"image1:tag1", "image2:tag2", "localhost:5000/operator:1.0.0", @@ -57,7 +57,7 @@ imageTags: func TestSetImageTagsOverride(t *testing.T) { fakeFS := fs.MakeFakeFS() - fakeFS.WriteFile(constants.KustomizationFileName, []byte(kustomizationContent)) + fakeFS.WriteTestKustomization() cmd := newCmdSetImageTag(fakeFS) args := []string{"image1:tag1", "image2:tag1"} diff --git a/pkg/commands/setnamespace.go b/pkg/commands/edit/set/setnamespace.go similarity index 92% rename from pkg/commands/setnamespace.go rename to pkg/commands/edit/set/setnamespace.go index 6834ed589..1266e18b5 100644 --- a/pkg/commands/setnamespace.go +++ b/pkg/commands/edit/set/setnamespace.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package commands +package set import ( "errors" @@ -22,6 +22,7 @@ import ( "strings" "github.com/spf13/cobra" + "sigs.k8s.io/kustomize/pkg/commands/kustfile" "sigs.k8s.io/kustomize/pkg/constants" "sigs.k8s.io/kustomize/pkg/fs" "sigs.k8s.io/kustomize/pkg/ifc" @@ -72,14 +73,14 @@ func (o *setNamespaceOptions) Validate(args []string) error { // RunSetNamespace runs setNamespace command (does real work). func (o *setNamespaceOptions) RunSetNamespace(fsys fs.FileSystem) error { - mf, err := newKustomizationFile(constants.KustomizationFileName, fsys) + mf, err := kustfile.NewKustomizationFile(constants.KustomizationFileName, fsys) if err != nil { return err } - m, err := mf.read() + m, err := mf.Read() if err != nil { return err } m.Namespace = o.namespace - return mf.write(m) + return mf.Write(m) } diff --git a/pkg/commands/setnamespace_test.go b/pkg/commands/edit/set/setnamespace_test.go similarity index 91% rename from pkg/commands/setnamespace_test.go rename to pkg/commands/edit/set/setnamespace_test.go index 42ef43e48..5d0729f0e 100644 --- a/pkg/commands/setnamespace_test.go +++ b/pkg/commands/edit/set/setnamespace_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package commands +package set import ( "fmt" @@ -32,7 +32,7 @@ const ( func TestSetNamespaceHappyPath(t *testing.T) { fakeFS := fs.MakeFakeFS() - fakeFS.WriteFile(constants.KustomizationFileName, []byte(kustomizationContent)) + fakeFS.WriteTestKustomization() cmd := newCmdSetNamespace(fakeFS, validators.MakeFakeValidator()) args := []string{goodNamespaceValue} @@ -52,7 +52,7 @@ func TestSetNamespaceHappyPath(t *testing.T) { func TestSetNamespaceOverride(t *testing.T) { fakeFS := fs.MakeFakeFS() - fakeFS.WriteFile(constants.KustomizationFileName, []byte(kustomizationContent)) + fakeFS.WriteTestKustomization() cmd := newCmdSetNamespace(fakeFS, validators.MakeFakeValidator()) args := []string{goodNamespaceValue} @@ -90,7 +90,6 @@ func TestSetNamespaceNoArgs(t *testing.T) { func TestSetNamespaceInvalid(t *testing.T) { fakeFS := fs.MakeFakeFS() - fakeFS.WriteFile(constants.KustomizationFileName, []byte(kustomizationContent)) cmd := newCmdSetNamespace(fakeFS, validators.MakeFakeValidator()) args := []string{"/badnamespace/"} diff --git a/pkg/commands/kustomizationfile.go b/pkg/commands/kustfile/kustomizationfile.go similarity index 93% rename from pkg/commands/kustomizationfile.go rename to pkg/commands/kustfile/kustomizationfile.go index 65f5829c5..89615c25b 100644 --- a/pkg/commands/kustomizationfile.go +++ b/pkg/commands/kustfile/kustomizationfile.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package commands +package kustfile import ( "bytes" @@ -77,7 +77,8 @@ type kustomizationFile struct { originalFields []*commentedField } -func newKustomizationFile(mPath string, fsys fs.FileSystem) (*kustomizationFile, error) { // nolint +// NewKustomizationFile returns a new instance. +func NewKustomizationFile(mPath string, fsys fs.FileSystem) (*kustomizationFile, error) { // nolint mf := &kustomizationFile{path: mPath, fsys: fsys} err := mf.validate() if err != nil { @@ -104,7 +105,7 @@ func (mf *kustomizationFile) validate() error { return nil } -func (mf *kustomizationFile) read() (*types.Kustomization, error) { +func (mf *kustomizationFile) Read() (*types.Kustomization, error) { data, err := mf.fsys.ReadFile(mf.path) if err != nil { return nil, err @@ -121,7 +122,7 @@ func (mf *kustomizationFile) read() (*types.Kustomization, error) { return &kustomization, err } -func (mf *kustomizationFile) write(kustomization *types.Kustomization) error { +func (mf *kustomizationFile) Write(kustomization *types.Kustomization) error { if kustomization == nil { return errors.New("util: kustomization file arg is nil") } @@ -132,7 +133,8 @@ func (mf *kustomizationFile) write(kustomization *types.Kustomization) error { return mf.fsys.WriteFile(mf.path, data) } -func stringInSlice(str string, list []string) bool { +// StringInSlice returns true if the string is in the slice. +func StringInSlice(str string, list []string) bool { for _, v := range list { if v == str { return true diff --git a/pkg/commands/kustomizationfile_test.go b/pkg/commands/kustfile/kustomizationfile_test.go similarity index 87% rename from pkg/commands/kustomizationfile_test.go rename to pkg/commands/kustfile/kustomizationfile_test.go index bc31b9218..3b61616c7 100644 --- a/pkg/commands/kustomizationfile_test.go +++ b/pkg/commands/kustfile/kustomizationfile_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package commands +package kustfile import ( "reflect" @@ -33,16 +33,16 @@ func TestWriteAndRead(t *testing.T) { fsys := fs.MakeFakeFS() fsys.Create(constants.KustomizationFileName) - mf, err := newKustomizationFile(constants.KustomizationFileName, fsys) + mf, err := NewKustomizationFile(constants.KustomizationFileName, fsys) if err != nil { t.Fatalf("Unexpected Error: %v", err) } - if err := mf.write(kustomization); err != nil { + if err := mf.Write(kustomization); err != nil { t.Fatalf("Couldn't write kustomization file: %v\n", err) } - content, err := mf.read() + content, err := mf.Read() if err != nil { t.Fatalf("Couldn't read kustomization file: %v\n", err) } @@ -53,7 +53,7 @@ func TestWriteAndRead(t *testing.T) { func TestEmptyFile(t *testing.T) { fsys := fs.MakeFakeFS() - _, err := newKustomizationFile("", fsys) + _, err := NewKustomizationFile("", fsys) if err == nil { t.Fatalf("Create kustomizationFile from empty filename should fail") } @@ -64,7 +64,7 @@ func TestNewNotExist(t *testing.T) { fakeFS := fs.MakeFakeFS() fakeFS.Mkdir(".") fakeFS.Create(badSuffix) - _, err := newKustomizationFile(constants.KustomizationFileName, fakeFS) + _, err := NewKustomizationFile(constants.KustomizationFileName, fakeFS) if err == nil { t.Fatalf("expect an error") } @@ -72,14 +72,14 @@ func TestNewNotExist(t *testing.T) { if !strings.Contains(err.Error(), contained) { t.Fatalf("expect an error contains %q, but got %v", contained, err) } - _, err = newKustomizationFile(constants.KustomizationFileName, fakeFS) + _, err = NewKustomizationFile(constants.KustomizationFileName, fakeFS) if err == nil { t.Fatalf("expect an error") } if !strings.Contains(err.Error(), contained) { t.Fatalf("expect an error contains %q, but got %v", contained, err) } - _, err = newKustomizationFile(badSuffix, fakeFS) + _, err = NewKustomizationFile(badSuffix, fakeFS) if err == nil { t.Fatalf("expect an error") } @@ -116,15 +116,15 @@ patchesStrategicMerge: fsys := fs.MakeFakeFS() fsys.Create(constants.KustomizationFileName) fsys.WriteFile(constants.KustomizationFileName, kustomizationContentWithComments) - mf, err := newKustomizationFile(constants.KustomizationFileName, fsys) + mf, err := NewKustomizationFile(constants.KustomizationFileName, fsys) if err != nil { t.Fatalf("Unexpected Error: %v", err) } - kustomization, err := mf.read() + kustomization, err := mf.Read() if err != nil { t.Fatalf("Unexpected Error: %v", err) } - if err = mf.write(kustomization); err != nil { + if err = mf.Write(kustomization); err != nil { t.Fatalf("Unexpected Error: %v", err) } bytes, _ := fsys.ReadFile(mf.path) @@ -207,16 +207,16 @@ patchesStrategicMerge: fsys := fs.MakeFakeFS() fsys.Create(constants.KustomizationFileName) fsys.WriteFile(constants.KustomizationFileName, kustomizationContentWithComments) - mf, err := newKustomizationFile(constants.KustomizationFileName, fsys) + mf, err := NewKustomizationFile(constants.KustomizationFileName, fsys) if err != nil { t.Fatalf("Unexpected Error: %v", err) } - kustomization, err := mf.read() + kustomization, err := mf.Read() if err != nil { t.Fatalf("Unexpected Error: %v", err) } - if err = mf.write(kustomization); err != nil { + if err = mf.Write(kustomization); err != nil { t.Fatalf("Unexpected Error: %v", err) } bytes, _ := fsys.ReadFile(mf.path) diff --git a/pkg/commands/config.go b/pkg/commands/misc/config.go similarity index 95% rename from pkg/commands/config.go rename to pkg/commands/misc/config.go index 0132a65d0..b97c5cc3d 100644 --- a/pkg/commands/config.go +++ b/pkg/commands/misc/config.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package commands +package misc import ( "fmt" @@ -26,8 +26,8 @@ import ( "sigs.k8s.io/kustomize/pkg/transformerconfig/defaultconfig" ) -// newCmdConfig returns an instance of 'config' subcommand. -func newCmdConfig(fsys fs.FileSystem) *cobra.Command { +// NewCmdConfig returns an instance of 'config' subcommand. +func NewCmdConfig(fsys fs.FileSystem) *cobra.Command { c := &cobra.Command{ Use: "config", Short: "Config Kustomize transformers", diff --git a/pkg/commands/config_test.go b/pkg/commands/misc/config_test.go similarity index 99% rename from pkg/commands/config_test.go rename to pkg/commands/misc/config_test.go index 1d6caad19..6cb8cbf1c 100644 --- a/pkg/commands/config_test.go +++ b/pkg/commands/misc/config_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package commands +package misc import ( "fmt" diff --git a/pkg/commands/version.go b/pkg/commands/misc/version.go similarity index 96% rename from pkg/commands/version.go rename to pkg/commands/misc/version.go index b66b080db..d71749c5f 100644 --- a/pkg/commands/version.go +++ b/pkg/commands/misc/version.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package commands +package misc import ( "fmt" @@ -63,7 +63,7 @@ func (v version) Print(w io.Writer) { } // NewCmdVersion makes version command. -func newCmdVersion(w io.Writer) *cobra.Command { +func NewCmdVersion(w io.Writer) *cobra.Command { return &cobra.Command{ Use: "version", Short: "Prints the kustomize version", diff --git a/pkg/fs/fakefs.go b/pkg/fs/fakefs.go index 6b67c27fc..0dd10fcad 100644 --- a/pkg/fs/fakefs.go +++ b/pkg/fs/fakefs.go @@ -20,6 +20,8 @@ import ( "fmt" "path/filepath" "sort" + + "sigs.k8s.io/kustomize/pkg/constants" ) var _ FileSystem = &FakeFS{} @@ -34,6 +36,31 @@ func MakeFakeFS() *FakeFS { return &FakeFS{m: map[string]*FakeFile{}} } +// kustomizationContent is used in tests. +const kustomizationContent = `namePrefix: some-prefix +# Labels to add to all objects and selectors. +# These labels would also be used to form the selector for apply --prune +# Named differently than “labels” to avoid confusion with metadata for this object +commonLabels: + app: helloworld +commonAnnotations: + note: This is an example annotation +resources: [] +#- service.yaml +#- ../some-dir/ +# There could also be configmaps in Base, which would make these overlays +configMapGenerator: [] +# There could be secrets in Base, if just using a fork/rebase workflow +secretGenerator: [] +` + +// WriteTestKustomization writes a standard test file. +func (fs *FakeFS) WriteTestKustomization() { + fs.WriteFile( + constants.KustomizationFileName, + []byte(kustomizationContent)) +} + // Create assures a fake file appears in the in-memory file system. func (fs *FakeFS) Create(name string) (File, error) { f := &FakeFile{}