Merge pull request #333 from Liujingfang1/new_inflate
Change inflate to use Application interface
This commit is contained in:
commit
a80049d5e6
|
|
@ -20,13 +20,16 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"k8s.io/kubectl/pkg/kinflate/app"
|
||||||
"k8s.io/kubectl/pkg/kinflate/tree"
|
"k8s.io/kubectl/pkg/kinflate/tree"
|
||||||
"k8s.io/kubectl/pkg/kinflate/types"
|
"k8s.io/kubectl/pkg/kinflate/types"
|
||||||
kutil "k8s.io/kubectl/pkg/kinflate/util"
|
kutil "k8s.io/kubectl/pkg/kinflate/util"
|
||||||
"k8s.io/kubectl/pkg/kinflate/util/fs"
|
"k8s.io/kubectl/pkg/kinflate/util/fs"
|
||||||
|
"k8s.io/kubectl/pkg/loader"
|
||||||
)
|
)
|
||||||
|
|
||||||
type inflateOptions struct {
|
type inflateOptions struct {
|
||||||
|
|
@ -83,20 +86,35 @@ func (o *inflateOptions) Complete(cmd *cobra.Command, args []string) error {
|
||||||
|
|
||||||
// runInflate does the real transformation.
|
// runInflate does the real transformation.
|
||||||
func (o *inflateOptions) runInflate(fs fs.FileSystem) (types.KObject, error) {
|
func (o *inflateOptions) runInflate(fs fs.FileSystem) (types.KObject, error) {
|
||||||
// Build a tree of ManifestData.
|
l := loader.Init([]loader.SchemeLoader{loader.NewFileLoader(fs)})
|
||||||
loader := tree.ManifestLoader{FS: fs, InitialPath: o.manifestPath}
|
|
||||||
root, err := loader.LoadManifestDataFromPath()
|
absPath, err := filepath.Abs(o.manifestPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Do the transformation for the tree.
|
rootLoader, err := l.New(absPath)
|
||||||
err = root.Inflate(o.mode)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return types.KObject(root.Resources), nil
|
application, err := app.New(rootLoader)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
allResources := types.ResourceCollection{}
|
||||||
|
switch o.mode {
|
||||||
|
case tree.ModeNormal:
|
||||||
|
allResources, err = application.Resources()
|
||||||
|
case tree.ModeNoop:
|
||||||
|
allResources, err = application.RawResources()
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return types.KObject(allResources), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunInflate runs inflate command (do real work).
|
// RunInflate runs inflate command (do real work).
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue