Add KustFactory as a wrapper of all factories

This commit is contained in:
Jingfang Liu
2018-10-11 12:15:08 -07:00
parent 6fa110d4fd
commit 40b2bf76ae
6 changed files with 82 additions and 24 deletions

View File

@@ -24,11 +24,9 @@ import (
"github.com/spf13/cobra"
"sigs.k8s.io/kustomize/pkg/constants"
"sigs.k8s.io/kustomize/pkg/fs"
"sigs.k8s.io/kustomize/pkg/ifc"
"sigs.k8s.io/kustomize/pkg/ifc/transformer"
"sigs.k8s.io/kustomize/pkg/loader"
"sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/resource"
"sigs.k8s.io/kustomize/pkg/target"
"sigs.k8s.io/kustomize/pkg/transformers/config"
)
@@ -62,7 +60,7 @@ Use different transformer configurations by passing files to kustomize
// NewCmdBuild creates a new build command.
func NewCmdBuild(
out io.Writer, fs fs.FileSystem,
kf ifc.KunstructuredFactory,
rf *resmap.Factory,
ptf transformer.Factory) *cobra.Command {
var o buildOptions
var p string
@@ -77,7 +75,7 @@ func NewCmdBuild(
if err != nil {
return err
}
return o.RunBuild(out, fs, kf, ptf)
return o.RunBuild(out, fs, rf, ptf)
},
}
cmd.Flags().StringVarP(
@@ -122,7 +120,7 @@ func (o *buildOptions) Validate(args []string, p string, fs fs.FileSystem) error
// RunBuild runs build command.
func (o *buildOptions) RunBuild(
out io.Writer, fSys fs.FileSystem,
kf ifc.KunstructuredFactory,
rf *resmap.Factory,
ptf transformer.Factory) error {
rootLoader, err := loader.NewLoader(o.kustomizationPath, "", fSys)
if err != nil {
@@ -135,7 +133,7 @@ func (o *buildOptions) RunBuild(
defer rootLoader.Cleanup()
kt, err := target.NewKustTarget(
rootLoader, fSys,
resmap.NewFactory(resource.NewFactory(kf)),
rf,
ptf, tc)
if err != nil {
return err

View File

@@ -26,8 +26,7 @@ import (
"testing"
"github.com/ghodss/yaml"
"sigs.k8s.io/kustomize/internal/k8sdeps/kunstruct"
"sigs.k8s.io/kustomize/internal/k8sdeps/transformer"
"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"
@@ -129,10 +128,11 @@ func runBuildTestCase(t *testing.T, testcaseName string, updateKustomizeExpected
kustomizationPath: testcase.Filename,
}
buf := bytes.NewBuffer([]byte{})
f := k8sdeps.NewFactory()
err = ops.RunBuild(
buf, fSys,
kunstruct.NewKunstructuredFactoryImpl(),
transformer.NewFactoryImpl())
f.ResmapF,
f.TransformerF)
switch {
case err != nil && len(testcase.ExpectedError) == 0:
t.Errorf("unexpected error: %v", err)