generate configmap for pruning

This commit is contained in:
Jingfang Liu
2019-04-05 16:13:15 -07:00
parent 4937b1c75e
commit 826affb8dd
17 changed files with 673 additions and 4 deletions

View File

@@ -84,6 +84,8 @@ func NewCmdBuild(
&o.outputPath,
"output", "o", "",
"If specified, write the build output to this path.")
cmd.AddCommand(NewCmdBuildPrune(out, fs, rf, ptf, b))
return cmd
}
@@ -130,3 +132,55 @@ func (o *Options) RunBuild(
_, err = out.Write(res)
return err
}
func (o *Options) RunBuildPrune(
out io.Writer, fSys fs.FileSystem,
rf *resmap.Factory, ptf transformer.Factory,
b bool) error {
ldr, err := loader.NewLoader(o.kustomizationPath, fSys)
if err != nil {
return err
}
defer ldr.Cleanup()
kt, err := target.NewKustTarget(ldr, rf, ptf, b)
if err != nil {
return err
}
allResources, err := kt.MakePruneConfigMap()
if err != nil {
return err
}
// Output the objects.
res, err := allResources.EncodeAsYaml()
if err != nil {
return err
}
if o.outputPath != "" {
return fSys.WriteFile(o.outputPath, res)
}
_, err = out.Write(res)
return err
}
func NewCmdBuildPrune(
out io.Writer, fs fs.FileSystem,
rf *resmap.Factory,
ptf transformer.Factory,
b bool) *cobra.Command {
var o Options
cmd := &cobra.Command{
Use: "prune [path]",
Short: "Print configmap to prune previous applied objects",
Example: examples,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
err := o.Validate(args)
if err != nil {
return err
}
return o.RunBuildPrune(out, fs, rf, ptf, b)
},
}
return cmd
}