From d33d154e1446dce5e8d383d235b057021b4da984 Mon Sep 17 00:00:00 2001 From: Jingfang Liu Date: Thu, 11 Oct 2018 11:28:08 -0700 Subject: [PATCH] split k8sdeps package into sub packages --- .../{kunstructuredfactory.go => kunstruct/factory.go} | 2 +- .../factory_test.go} | 2 +- .../k8sdeps/{unstructadapter.go => kunstruct/kunstruct.go} | 3 ++- .../kunstruct_test.go} | 2 +- internal/k8sdeps/transformer/hash/namehash_test.go | 4 ++-- internal/k8sdeps/transformer/patch/patch_test.go | 4 ++-- internal/k8sdeps/{ => validator}/validators.go | 3 ++- kustomize.go | 7 ++++--- pkg/commands/build/build_test.go | 4 ++-- pkg/patch/transformer/factory_test.go | 4 ++-- pkg/patch/transformer/patchjson6902json_test.go | 4 ++-- pkg/resmap/resmap_test.go | 4 ++-- pkg/resource/resource_test.go | 4 ++-- pkg/target/kusttarget_test.go | 4 ++-- pkg/transformers/imagetag_test.go | 4 ++-- pkg/transformers/labelsandannotations_test.go | 4 ++-- pkg/transformers/namereference_test.go | 4 ++-- pkg/transformers/namespace_test.go | 4 ++-- pkg/transformers/prefixname_test.go | 4 ++-- 19 files changed, 37 insertions(+), 34 deletions(-) rename internal/k8sdeps/{kunstructuredfactory.go => kunstruct/factory.go} (99%) rename internal/k8sdeps/{kunstructuredfactory_test.go => kunstruct/factory_test.go} (99%) rename internal/k8sdeps/{unstructadapter.go => kunstruct/kunstruct.go} (96%) rename internal/k8sdeps/{unstructadapter_test.go => kunstruct/kunstruct_test.go} (99%) rename internal/k8sdeps/{ => validator}/validators.go (94%) diff --git a/internal/k8sdeps/kunstructuredfactory.go b/internal/k8sdeps/kunstruct/factory.go similarity index 99% rename from internal/k8sdeps/kunstructuredfactory.go rename to internal/k8sdeps/kunstruct/factory.go index ced102428..c1d130f9f 100644 --- a/internal/k8sdeps/kunstructuredfactory.go +++ b/internal/k8sdeps/kunstruct/factory.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package k8sdeps +package kunstruct import ( "bytes" diff --git a/internal/k8sdeps/kunstructuredfactory_test.go b/internal/k8sdeps/kunstruct/factory_test.go similarity index 99% rename from internal/k8sdeps/kunstructuredfactory_test.go rename to internal/k8sdeps/kunstruct/factory_test.go index 71a072b2d..6b273431e 100644 --- a/internal/k8sdeps/kunstructuredfactory_test.go +++ b/internal/k8sdeps/kunstruct/factory_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package k8sdeps +package kunstruct import ( "reflect" diff --git a/internal/k8sdeps/unstructadapter.go b/internal/k8sdeps/kunstruct/kunstruct.go similarity index 96% rename from internal/k8sdeps/unstructadapter.go rename to internal/k8sdeps/kunstruct/kunstruct.go index 94fe72816..968597707 100644 --- a/internal/k8sdeps/unstructadapter.go +++ b/internal/k8sdeps/kunstruct/kunstruct.go @@ -14,7 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ -package k8sdeps +// Package kunstruct provides unstructured from api machinery and factory for creating unstructured +package kunstruct import ( "encoding/json" diff --git a/internal/k8sdeps/unstructadapter_test.go b/internal/k8sdeps/kunstruct/kunstruct_test.go similarity index 99% rename from internal/k8sdeps/unstructadapter_test.go rename to internal/k8sdeps/kunstruct/kunstruct_test.go index 8e339564d..0ecfe8a36 100644 --- a/internal/k8sdeps/unstructadapter_test.go +++ b/internal/k8sdeps/kunstruct/kunstruct_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package k8sdeps +package kunstruct import ( "testing" diff --git a/internal/k8sdeps/transformer/hash/namehash_test.go b/internal/k8sdeps/transformer/hash/namehash_test.go index 9067af09b..57a709a75 100644 --- a/internal/k8sdeps/transformer/hash/namehash_test.go +++ b/internal/k8sdeps/transformer/hash/namehash_test.go @@ -20,7 +20,7 @@ import ( "reflect" "testing" - "sigs.k8s.io/kustomize/internal/k8sdeps" + "sigs.k8s.io/kustomize/internal/k8sdeps/kunstruct" "sigs.k8s.io/kustomize/pkg/ifc" "sigs.k8s.io/kustomize/pkg/resid" "sigs.k8s.io/kustomize/pkg/resmap" @@ -29,7 +29,7 @@ import ( func TestNameHashTransformer(t *testing.T) { rf := resource.NewFactory( - k8sdeps.NewKunstructuredFactoryImpl()) + kunstruct.NewKunstructuredFactoryImpl()) objs := resmap.ResMap{ resid.NewResId(cmap, "cm1"): rf.FromMap( map[string]interface{}{ diff --git a/internal/k8sdeps/transformer/patch/patch_test.go b/internal/k8sdeps/transformer/patch/patch_test.go index 5a6c68b4b..1b4df2583 100644 --- a/internal/k8sdeps/transformer/patch/patch_test.go +++ b/internal/k8sdeps/transformer/patch/patch_test.go @@ -21,7 +21,7 @@ import ( "strings" "testing" - "sigs.k8s.io/kustomize/internal/k8sdeps" + "sigs.k8s.io/kustomize/internal/k8sdeps/kunstruct" "sigs.k8s.io/kustomize/pkg/gvk" "sigs.k8s.io/kustomize/pkg/resid" "sigs.k8s.io/kustomize/pkg/resmap" @@ -29,7 +29,7 @@ import ( ) var rf = resource.NewFactory( - k8sdeps.NewKunstructuredFactoryImpl()) + kunstruct.NewKunstructuredFactoryImpl()) var deploy = gvk.Gvk{Group: "apps", Version: "v1", Kind: "Deployment"} var foo = gvk.Gvk{Group: "example.com", Version: "v1", Kind: "Foo"} diff --git a/internal/k8sdeps/validators.go b/internal/k8sdeps/validator/validators.go similarity index 94% rename from internal/k8sdeps/validators.go rename to internal/k8sdeps/validator/validators.go index e6d50d183..ed09d9b30 100644 --- a/internal/k8sdeps/validators.go +++ b/internal/k8sdeps/validator/validators.go @@ -14,7 +14,8 @@ See the License for the specific language governing permissions and limitations under the License. */ -package k8sdeps +// Package validator provides functions to validate labels, annotations, namespace using apimachinery +package validator import ( "errors" diff --git a/kustomize.go b/kustomize.go index 42c18d0aa..5e90f0d90 100644 --- a/kustomize.go +++ b/kustomize.go @@ -20,8 +20,9 @@ import ( "os" "github.com/golang/glog" - "sigs.k8s.io/kustomize/internal/k8sdeps" + "sigs.k8s.io/kustomize/internal/k8sdeps/kunstruct" "sigs.k8s.io/kustomize/internal/k8sdeps/transformer" + "sigs.k8s.io/kustomize/internal/k8sdeps/validator" "sigs.k8s.io/kustomize/pkg/commands" ) @@ -29,9 +30,9 @@ func main() { defer glog.Flush() if err := commands.NewDefaultCommand( - k8sdeps.NewKunstructuredFactoryImpl(), + kunstruct.NewKunstructuredFactoryImpl(), transformer.NewFactoryImpl(), - k8sdeps.NewKustValidator()).Execute(); err != nil { + validator.NewKustValidator()).Execute(); err != nil { os.Exit(1) } os.Exit(0) diff --git a/pkg/commands/build/build_test.go b/pkg/commands/build/build_test.go index dac7fa8dd..a2798f585 100644 --- a/pkg/commands/build/build_test.go +++ b/pkg/commands/build/build_test.go @@ -26,7 +26,7 @@ import ( "testing" "github.com/ghodss/yaml" - "sigs.k8s.io/kustomize/internal/k8sdeps" + "sigs.k8s.io/kustomize/internal/k8sdeps/kunstruct" "sigs.k8s.io/kustomize/internal/k8sdeps/transformer" "sigs.k8s.io/kustomize/pkg/commands/kustfile" "sigs.k8s.io/kustomize/pkg/constants" @@ -131,7 +131,7 @@ func runBuildTestCase(t *testing.T, testcaseName string, updateKustomizeExpected buf := bytes.NewBuffer([]byte{}) err = ops.RunBuild( buf, fSys, - k8sdeps.NewKunstructuredFactoryImpl(), + kunstruct.NewKunstructuredFactoryImpl(), transformer.NewFactoryImpl()) switch { case err != nil && len(testcase.ExpectedError) == 0: diff --git a/pkg/patch/transformer/factory_test.go b/pkg/patch/transformer/factory_test.go index 1b0b79820..856ac9f35 100644 --- a/pkg/patch/transformer/factory_test.go +++ b/pkg/patch/transformer/factory_test.go @@ -22,7 +22,7 @@ import ( "testing" "gopkg.in/yaml.v2" - "sigs.k8s.io/kustomize/internal/k8sdeps" + "sigs.k8s.io/kustomize/internal/k8sdeps/kunstruct" "sigs.k8s.io/kustomize/pkg/gvk" "sigs.k8s.io/kustomize/pkg/internal/loadertest" "sigs.k8s.io/kustomize/pkg/patch" @@ -32,7 +32,7 @@ import ( ) var rf = resource.NewFactory( - k8sdeps.NewKunstructuredFactoryImpl()) + kunstruct.NewKunstructuredFactoryImpl()) func TestNewPatchJson6902FactoryNoTarget(t *testing.T) { p := patch.Json6902{} diff --git a/pkg/patch/transformer/patchjson6902json_test.go b/pkg/patch/transformer/patchjson6902json_test.go index 4d4782c62..3b23d804d 100644 --- a/pkg/patch/transformer/patchjson6902json_test.go +++ b/pkg/patch/transformer/patchjson6902json_test.go @@ -21,7 +21,7 @@ import ( "testing" "github.com/evanphx/json-patch" - "sigs.k8s.io/kustomize/internal/k8sdeps" + "sigs.k8s.io/kustomize/internal/k8sdeps/kunstruct" "sigs.k8s.io/kustomize/pkg/gvk" "sigs.k8s.io/kustomize/pkg/resid" "sigs.k8s.io/kustomize/pkg/resmap" @@ -32,7 +32,7 @@ var deploy = gvk.Gvk{Group: "apps", Version: "v1", Kind: "Deployment"} func TestJsonPatchJSONTransformer_Transform(t *testing.T) { rf := resource.NewFactory( - k8sdeps.NewKunstructuredFactoryImpl()) + kunstruct.NewKunstructuredFactoryImpl()) id := resid.NewResId(deploy, "deploy1") base := resmap.ResMap{ id: rf.FromMap( diff --git a/pkg/resmap/resmap_test.go b/pkg/resmap/resmap_test.go index 995811360..341c93887 100644 --- a/pkg/resmap/resmap_test.go +++ b/pkg/resmap/resmap_test.go @@ -20,7 +20,7 @@ import ( "reflect" "testing" - "sigs.k8s.io/kustomize/internal/k8sdeps" + "sigs.k8s.io/kustomize/internal/k8sdeps/kunstruct" "sigs.k8s.io/kustomize/pkg/gvk" "sigs.k8s.io/kustomize/pkg/ifc" "sigs.k8s.io/kustomize/pkg/resid" @@ -30,7 +30,7 @@ import ( var deploy = gvk.Gvk{Group: "apps", Version: "v1", Kind: "Deployment"} var statefulset = gvk.Gvk{Group: "apps", Version: "v1", Kind: "StatefulSet"} var rf = resource.NewFactory( - k8sdeps.NewKunstructuredFactoryImpl()) + kunstruct.NewKunstructuredFactoryImpl()) var rmF = NewFactory(rf) func TestEncodeAsYaml(t *testing.T) { diff --git a/pkg/resource/resource_test.go b/pkg/resource/resource_test.go index 4b337a2a9..cc22bb094 100644 --- a/pkg/resource/resource_test.go +++ b/pkg/resource/resource_test.go @@ -19,11 +19,11 @@ package resource import ( "testing" - "sigs.k8s.io/kustomize/internal/k8sdeps" + "sigs.k8s.io/kustomize/internal/k8sdeps/kunstruct" ) var factory = NewFactory( - k8sdeps.NewKunstructuredFactoryImpl()) + kunstruct.NewKunstructuredFactoryImpl()) var testConfigMap = factory.FromMap( map[string]interface{}{ diff --git a/pkg/target/kusttarget_test.go b/pkg/target/kusttarget_test.go index b226926d7..0725bad58 100644 --- a/pkg/target/kusttarget_test.go +++ b/pkg/target/kusttarget_test.go @@ -22,7 +22,7 @@ import ( "strings" "testing" - "sigs.k8s.io/kustomize/internal/k8sdeps" + "sigs.k8s.io/kustomize/internal/k8sdeps/kunstruct" "sigs.k8s.io/kustomize/internal/k8sdeps/transformer" "sigs.k8s.io/kustomize/pkg/constants" "sigs.k8s.io/kustomize/pkg/fs" @@ -89,7 +89,7 @@ metadata: ) var rf = resmap.NewFactory(resource.NewFactory( - k8sdeps.NewKunstructuredFactoryImpl())) + kunstruct.NewKunstructuredFactoryImpl())) func makeKustTarget(t *testing.T, l ifc.Loader) *KustTarget { fakeFs := fs.MakeFakeFS() diff --git a/pkg/transformers/imagetag_test.go b/pkg/transformers/imagetag_test.go index 66239e2da..0449c1a97 100644 --- a/pkg/transformers/imagetag_test.go +++ b/pkg/transformers/imagetag_test.go @@ -20,7 +20,7 @@ import ( "reflect" "testing" - "sigs.k8s.io/kustomize/internal/k8sdeps" + "sigs.k8s.io/kustomize/internal/k8sdeps/kunstruct" "sigs.k8s.io/kustomize/pkg/gvk" "sigs.k8s.io/kustomize/pkg/resid" "sigs.k8s.io/kustomize/pkg/resmap" @@ -30,7 +30,7 @@ import ( func TestImageTagTransformer(t *testing.T) { var rf = resource.NewFactory( - k8sdeps.NewKunstructuredFactoryImpl()) + kunstruct.NewKunstructuredFactoryImpl()) m := resmap.ResMap{ resid.NewResId(deploy, "deploy1"): rf.FromMap( diff --git a/pkg/transformers/labelsandannotations_test.go b/pkg/transformers/labelsandannotations_test.go index 45cdffb23..1ee62acd6 100644 --- a/pkg/transformers/labelsandannotations_test.go +++ b/pkg/transformers/labelsandannotations_test.go @@ -20,7 +20,7 @@ import ( "reflect" "testing" - "sigs.k8s.io/kustomize/internal/k8sdeps" + "sigs.k8s.io/kustomize/internal/k8sdeps/kunstruct" "sigs.k8s.io/kustomize/pkg/gvk" "sigs.k8s.io/kustomize/pkg/resid" "sigs.k8s.io/kustomize/pkg/resmap" @@ -41,7 +41,7 @@ var pvc = gvk.Gvk{Version: "v1", Kind: "PersistentVolumeClaim"} var crb = gvk.Gvk{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRoleBinding"} var sa = gvk.Gvk{Version: "v1", Kind: "ServiceAccount"} var ingress = gvk.Gvk{Kind: "Ingress"} -var rf = resource.NewFactory(k8sdeps.NewKunstructuredFactoryImpl()) +var rf = resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl()) var defaultTransformerConfig = config.NewFactory(nil).DefaultConfig() func TestLabelsRun(t *testing.T) { diff --git a/pkg/transformers/namereference_test.go b/pkg/transformers/namereference_test.go index 1790e4cb4..81ea8a7fb 100644 --- a/pkg/transformers/namereference_test.go +++ b/pkg/transformers/namereference_test.go @@ -20,7 +20,7 @@ import ( "reflect" "testing" - "sigs.k8s.io/kustomize/internal/k8sdeps" + "sigs.k8s.io/kustomize/internal/k8sdeps/kunstruct" "sigs.k8s.io/kustomize/pkg/resid" "sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resource" @@ -28,7 +28,7 @@ import ( func TestNameReferenceRun(t *testing.T) { rf := resource.NewFactory( - k8sdeps.NewKunstructuredFactoryImpl()) + kunstruct.NewKunstructuredFactoryImpl()) m := resmap.ResMap{ resid.NewResId(cmap, "cm1"): rf.FromMap( map[string]interface{}{ diff --git a/pkg/transformers/namespace_test.go b/pkg/transformers/namespace_test.go index af59b1a7a..c9926ee59 100644 --- a/pkg/transformers/namespace_test.go +++ b/pkg/transformers/namespace_test.go @@ -20,7 +20,7 @@ import ( "reflect" "testing" - "sigs.k8s.io/kustomize/internal/k8sdeps" + "sigs.k8s.io/kustomize/internal/k8sdeps/kunstruct" "sigs.k8s.io/kustomize/pkg/resid" "sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resource" @@ -28,7 +28,7 @@ import ( func TestNamespaceRun(t *testing.T) { rf := resource.NewFactory( - k8sdeps.NewKunstructuredFactoryImpl()) + kunstruct.NewKunstructuredFactoryImpl()) m := resmap.ResMap{ resid.NewResId(cmap, "cm1"): rf.FromMap( map[string]interface{}{ diff --git a/pkg/transformers/prefixname_test.go b/pkg/transformers/prefixname_test.go index 8323afcdf..3cacff953 100644 --- a/pkg/transformers/prefixname_test.go +++ b/pkg/transformers/prefixname_test.go @@ -20,7 +20,7 @@ import ( "reflect" "testing" - "sigs.k8s.io/kustomize/internal/k8sdeps" + "sigs.k8s.io/kustomize/internal/k8sdeps/kunstruct" "sigs.k8s.io/kustomize/pkg/resid" "sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resource" @@ -28,7 +28,7 @@ import ( func TestPrefixNameRun(t *testing.T) { rf := resource.NewFactory( - k8sdeps.NewKunstructuredFactoryImpl()) + kunstruct.NewKunstructuredFactoryImpl()) m := resmap.ResMap{ resid.NewResId(cmap, "cm1"): rf.FromMap( map[string]interface{}{