mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-07-17 09:49:13 +00:00
Introduce k8sdeps package to isolate k8s deps.
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
"errors"
|
||||
"io"
|
||||
"log"
|
||||
"sigs.k8s.io/kustomize/pkg/ifc"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
@@ -57,7 +58,9 @@ Use different transformer configurations by passing files to kustomize
|
||||
`
|
||||
|
||||
// newCmdBuild creates a new build command.
|
||||
func newCmdBuild(out io.Writer, fs fs.FileSystem) *cobra.Command {
|
||||
func newCmdBuild(
|
||||
out io.Writer, fs fs.FileSystem,
|
||||
decoder ifc.Decoder) *cobra.Command {
|
||||
var o buildOptions
|
||||
var p string
|
||||
|
||||
@@ -71,7 +74,7 @@ func newCmdBuild(out io.Writer, fs fs.FileSystem) *cobra.Command {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return o.RunBuild(out, fs)
|
||||
return o.RunBuild(out, fs, decoder)
|
||||
},
|
||||
}
|
||||
cmd.Flags().StringVarP(
|
||||
@@ -114,14 +117,18 @@ 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) error {
|
||||
func (o *buildOptions) RunBuild(
|
||||
out io.Writer, fSys fs.FileSystem,
|
||||
decoder ifc.Decoder) error {
|
||||
rootLoader, err := loader.NewLoader(o.kustomizationPath, "", fSys)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rootLoader.Cleanup()
|
||||
kt, err := target.NewKustTarget(
|
||||
rootLoader, fSys, makeTransformerconfig(fSys, o.transformerconfigPaths))
|
||||
rootLoader, fSys,
|
||||
makeTransformerconfig(fSys, o.transformerconfigPaths),
|
||||
decoder)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"sigs.k8s.io/kustomize/pkg/internal/k8sdeps"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
@@ -124,7 +125,7 @@ func runBuildTestCase(t *testing.T, testcaseName string, updateKustomizeExpected
|
||||
kustomizationPath: testcase.Filename,
|
||||
}
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
err = ops.RunBuild(buf, fSys)
|
||||
err = ops.RunBuild(buf, fSys, k8sdeps.NewKustDecoder())
|
||||
switch {
|
||||
case err != nil && len(testcase.ExpectedError) == 0:
|
||||
t.Errorf("unexpected error: %v", err)
|
||||
|
||||
@@ -20,6 +20,7 @@ package commands
|
||||
import (
|
||||
"flag"
|
||||
"os"
|
||||
"sigs.k8s.io/kustomize/pkg/internal/k8sdeps"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/pkg/fs"
|
||||
@@ -43,7 +44,7 @@ See https://sigs.k8s.io/kustomize
|
||||
|
||||
c.AddCommand(
|
||||
// TODO: Make consistent API for newCmd* functions.
|
||||
newCmdBuild(stdOut, fsys),
|
||||
newCmdBuild(stdOut, fsys, k8sdeps.NewKustDecoder()),
|
||||
newCmdEdit(fsys),
|
||||
newCmdConfig(fsys),
|
||||
newCmdVersion(stdOut),
|
||||
|
||||
Reference in New Issue
Block a user