Skip to content
Permalink
Browse files

Make a secret factory.

  • Loading branch information...
monopole committed Jul 20, 2018
1 parent 0197c01 commit 276693cf0e9cf5b83809edac832c5c253f5a941c
@@ -28,6 +28,7 @@ import (

"github.com/kubernetes-sigs/kustomize/pkg/constants"
"github.com/kubernetes-sigs/kustomize/pkg/crds"
"github.com/kubernetes-sigs/kustomize/pkg/fs"
interror "github.com/kubernetes-sigs/kustomize/pkg/internal/error"
"github.com/kubernetes-sigs/kustomize/pkg/loader"
"github.com/kubernetes-sigs/kustomize/pkg/resmap"
@@ -44,10 +45,11 @@ import (
type Application struct {
kustomization *types.Kustomization
loader loader.Loader
fSys fs.FileSystem
}

// NewApplication returns a new instance of Application primed with a Loader.
func NewApplication(loader loader.Loader) (*Application, error) {
func NewApplication(loader loader.Loader, fSys fs.FileSystem) (*Application, error) {
content, err := loader.Load(constants.KustomizationFileName)
if err != nil {
return nil, err
@@ -58,7 +60,7 @@ func NewApplication(loader loader.Loader) (*Application, error) {
if err != nil {
return nil, err
}
return &Application{kustomization: &m, loader: loader}, nil
return &Application{kustomization: &m, loader: loader, fSys: fSys}, nil
}

func unmarshal(y []byte, o interface{}) error {
@@ -139,7 +141,8 @@ func (a *Application) loadCustomizedResMap() (resmap.ResMap, error) {
errs.Append(errors.Wrap(err, "RegisterCRDs"))
}

cms, err := resmap.NewResMapFromConfigMapArgs(a.loader, a.kustomization.ConfigMapGenerator)
cms, err := resmap.NewResMapFromConfigMapArgs(
a.loader, a.fSys, a.kustomization.ConfigMapGenerator)
if err != nil {
errs.Append(errors.Wrap(err, "NewResMapFromConfigMapArgs"))
}
@@ -200,7 +203,7 @@ func (a *Application) loadCustomizedBases() (resmap.ResMap, *interror.Kustomizat
errs.Append(errors.Wrap(err, "couldn't make ldr for "+path))
continue
}
app, err := NewApplication(ldr)
app, err := NewApplication(ldr, a.fSys)
if err != nil {
errs.Append(errors.Wrap(err, "couldn't make app for "+path))
continue
@@ -228,7 +231,7 @@ func (a *Application) loadBasesAsFlatList() ([]*Application, error) {
errs.Append(err)
continue
}
a, err := NewApplication(ldr)
a, err := NewApplication(ldr, a.fSys)
if err != nil {
errs.Append(err)
continue
@@ -22,6 +22,7 @@ import (
"testing"

"github.com/kubernetes-sigs/kustomize/pkg/constants"
"github.com/kubernetes-sigs/kustomize/pkg/fs"
"github.com/kubernetes-sigs/kustomize/pkg/internal/loadertest"
"github.com/kubernetes-sigs/kustomize/pkg/loader"
"github.com/kubernetes-sigs/kustomize/pkg/resmap"
@@ -179,7 +180,7 @@ func TestResources1(t *testing.T) {
}),
}
l := makeLoader1(t)
app, err := NewApplication(l)
app, err := NewApplication(l, fs.MakeFakeFS())
if err != nil {
t.Fatalf("Unexpected construction error %v", err)
}
@@ -214,7 +215,7 @@ func TestRawResources1(t *testing.T) {
}),
}
l := makeLoader1(t)
app, err := NewApplication(l)
app, err := NewApplication(l, fs.MakeFakeFS())
if err != nil {
t.Fatalf("Unexpected construction error %v", err)
}
@@ -324,7 +325,7 @@ func TestRawResources2(t *testing.T) {
}),
}
l := makeLoader2(t)
app, err := NewApplication(l)
app, err := NewApplication(l, fs.MakeFakeFS())
if err != nil {
t.Fatalf("Unexpected construction error %v", err)
}
@@ -69,8 +69,8 @@ func (o *buildOptions) Validate(args []string) error {
}

// RunBuild runs build command.
func (o *buildOptions) RunBuild(out io.Writer, fs fs.FileSystem) error {
l := loader.Init([]loader.SchemeLoader{loader.NewFileLoader(fs)})
func (o *buildOptions) RunBuild(out io.Writer, fSys fs.FileSystem) error {
l := loader.Init([]loader.SchemeLoader{loader.NewFileLoader(fSys)})

absPath, err := filepath.Abs(o.kustomizationPath)
if err != nil {
@@ -82,7 +82,7 @@ func (o *buildOptions) RunBuild(out io.Writer, fs fs.FileSystem) error {
return err
}

application, err := app.NewApplication(rootLoader)
application, err := app.NewApplication(rootLoader, fSys)
if err != nil {
return err
}
@@ -103,7 +103,7 @@ func addConfigMap(k *types.Kustomization, flagsAndArgs cMapFlagsAndArgs, fSys fs
return err
}

factory := configmapandsecret.NewConfigMapFactory(cmArgs, fSys, nil)
factory := configmapandsecret.NewConfigMapFactory(cmArgs, nil, fSys)

// Validate by trying to create corev1.configmap.
_, _, err = factory.MakeUnstructAndGenerateName()
@@ -66,9 +66,9 @@ func (o *diffOptions) Validate(args []string) error {
}

// RunDiff gets the differences between Application.MakeCustomizedResMap() and Application.MakeUncustomizedResMap().
func (o *diffOptions) RunDiff(out, errOut io.Writer, fs fs.FileSystem) error {
func (o *diffOptions) RunDiff(out, errOut io.Writer, fSys fs.FileSystem) error {

l := loader.Init([]loader.SchemeLoader{loader.NewFileLoader(fs)})
l := loader.Init([]loader.SchemeLoader{loader.NewFileLoader(fSys)})

absPath, err := filepath.Abs(o.kustomizationPath)
if err != nil {
@@ -80,7 +80,7 @@ func (o *diffOptions) RunDiff(out, errOut io.Writer, fs fs.FileSystem) error {
return err
}

application, err := app.NewApplication(rootLoader)
application, err := app.NewApplication(rootLoader, fSys)
if err != nil {
return err
}
@@ -46,9 +46,9 @@ type ConfigMapFactory struct {
// NewConfigMapFactory returns a new ConfigMapFactory.
func NewConfigMapFactory(
args *types.ConfigMapArgs,
fSys fs.FileSystem,
l loader.Loader) *ConfigMapFactory {
return &ConfigMapFactory{args: args, fSys: fSys, ldr: l}
l loader.Loader,
fSys fs.FileSystem) *ConfigMapFactory {
return &ConfigMapFactory{args: args, ldr: l, fSys: fSys}
}

// MakeUnstructAndGenerateName returns an configmap and the name appended with a hash.
@@ -136,7 +136,7 @@ func TestConstructConfigMap(t *testing.T) {
for _, tc := range testCases {
// TODO: all tests should use a FakeFs
fSys := fs.MakeRealFS()
f := NewConfigMapFactory(&tc.input, fSys, nil)
f := NewConfigMapFactory(&tc.input, nil, fSys)
cm, err := f.MakeConfigMap1()
if err != nil {
t.Fatalf("unexpected error: %v", err)
@@ -18,20 +18,24 @@ package resmap

import (
"github.com/kubernetes-sigs/kustomize/pkg/configmapandsecret"
"github.com/kubernetes-sigs/kustomize/pkg/fs"
"github.com/kubernetes-sigs/kustomize/pkg/loader"
"github.com/kubernetes-sigs/kustomize/pkg/resource"
"github.com/kubernetes-sigs/kustomize/pkg/types"
)

// NewResMapFromConfigMapArgs returns a Resource slice given a configmap metadata slice from kustomization file.
// NewResMapFromConfigMapArgs returns a Resource slice given
// a configmap metadata slice from kustomization file.
func NewResMapFromConfigMapArgs(
ldr loader.Loader, cmArgsList []types.ConfigMapArgs) (ResMap, error) {
ldr loader.Loader,
fSys fs.FileSystem,
cmArgsList []types.ConfigMapArgs) (ResMap, error) {
var allResources []*resource.Resource
for _, cmArgs := range cmArgsList {
if cmArgs.Behavior == "" {
cmArgs.Behavior = "create"
}
f := configmapandsecret.NewConfigMapFactory(&cmArgs, nil, ldr)
f := configmapandsecret.NewConfigMapFactory(&cmArgs, ldr, fSys)
cm, err := f.MakeConfigMap2()
if err != nil {
return nil, err
@@ -20,6 +20,7 @@ import (
"reflect"
"testing"

"github.com/kubernetes-sigs/kustomize/pkg/fs"
"github.com/kubernetes-sigs/kustomize/pkg/internal/loadertest"
"github.com/kubernetes-sigs/kustomize/pkg/resource"
"github.com/kubernetes-sigs/kustomize/pkg/types"
@@ -130,7 +131,7 @@ BAR=baz
if ferr := l.AddFile(tc.filepath, []byte(tc.content)); ferr != nil {
t.Fatalf("Error adding fake file: %v\n", ferr)
}
r, err := NewResMapFromConfigMapArgs(l, tc.input)
r, err := NewResMapFromConfigMapArgs(l, fs.MakeFakeFS(), tc.input)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}

0 comments on commit 276693c

Please sign in to comment.
You can’t perform that action at this time.