Merge pull request #333 from Liujingfang1/new_inflate

Change inflate to use Application interface
This commit is contained in:
k8s-ci-robot 2018-03-02 14:08:54 -08:00 committed by GitHub
commit a80049d5e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 24 additions and 6 deletions

View File

@ -20,13 +20,16 @@ import (
"fmt"
"io"
"os"
"path/filepath"
"github.com/spf13/cobra"
"k8s.io/kubectl/pkg/kinflate/app"
"k8s.io/kubectl/pkg/kinflate/tree"
"k8s.io/kubectl/pkg/kinflate/types"
kutil "k8s.io/kubectl/pkg/kinflate/util"
"k8s.io/kubectl/pkg/kinflate/util/fs"
"k8s.io/kubectl/pkg/loader"
)
type inflateOptions struct {
@ -83,20 +86,35 @@ func (o *inflateOptions) Complete(cmd *cobra.Command, args []string) error {
// runInflate does the real transformation.
func (o *inflateOptions) runInflate(fs fs.FileSystem) (types.KObject, error) {
// Build a tree of ManifestData.
loader := tree.ManifestLoader{FS: fs, InitialPath: o.manifestPath}
root, err := loader.LoadManifestDataFromPath()
l := loader.Init([]loader.SchemeLoader{loader.NewFileLoader(fs)})
absPath, err := filepath.Abs(o.manifestPath)
if err != nil {
return nil, err
}
// Do the transformation for the tree.
err = root.Inflate(o.mode)
rootLoader, err := l.New(absPath)
if err != nil {
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).