From 0c022db1e6031ed4c3e2b2ef3c3f2050b2d5ab9b Mon Sep 17 00:00:00 2001 From: Sean Sullivan Date: Fri, 24 Jan 2020 15:10:27 -0800 Subject: [PATCH] Connect prune to apply --- cmd/kubectl/kubectlcobra/commands.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cmd/kubectl/kubectlcobra/commands.go b/cmd/kubectl/kubectlcobra/commands.go index ade1205cc..8fe5146f8 100644 --- a/cmd/kubectl/kubectlcobra/commands.go +++ b/cmd/kubectl/kubectlcobra/commands.go @@ -81,6 +81,7 @@ func updateHelp(names []string, c *cobra.Command) { func NewCmdApply(baseName string, f util.Factory, ioStreams genericclioptions.IOStreams) *cobra.Command { o := apply.NewApplyOptions(ioStreams) so := newStatusOptions(f, ioStreams) + // Set up grouping object for this apply; used in subsequent prune. o.PreProcessorFn = PrependGroupingObject(o) cmd := &cobra.Command{ @@ -97,6 +98,9 @@ func NewCmdApply(baseName string, f util.Factory, ioStreams genericclioptions.IO } cmdutil.CheckErr(o.Complete(f, cmd)) + // Default PostProcessor is configured in "Complete" function, + // so the prune must happen after "Complete". + o.PostProcessorFn = prune(f, o) cmdutil.CheckErr(o.Run()) infos, _ := o.GetObjects() if so.wait { @@ -144,3 +148,16 @@ func PrependGroupingObject(o *apply.ApplyOptions) func() error { return nil } } + +// Prune deletes previously applied objects that have been +// omitted in the current apply. The previously applied objects +// are reached through ConfigMap grouping objects. +func prune(f util.Factory, o *apply.ApplyOptions) func() error { + return func() error { + po, err := NewPruneOptions(f, o) + if err != nil { + return err + } + return po.Prune() + } +}