Merge pull request #168 from mortent/SupportWaitForPrune

Add flags for waiting for pruned resources to be deleted
This commit is contained in:
Kubernetes Prow Robot 2020-05-14 16:50:59 -07:00 committed by GitHub
commit fde6a97711
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 0 deletions

View File

@ -58,6 +58,10 @@ func GetApplyRunner(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *A
"If true, do not prune previously applied objects.")
cmd.Flags().StringVar(&r.prunePropagationPolicy, "prune-propagation-policy",
"Background", "Propagation policy for pruning")
cmd.Flags().BoolVar(&r.waitForPrune, "wait-for-prune", false,
"Wait for all pruned resources to be deleted.")
cmd.Flags().DurationVar(&r.waitForPruneTimeout, "wait-for-prune-timeout", 1*time.Minute,
"Timeout threshold for waiting for all pruned resources to be deleted")
r.command = cmd
return r
@ -78,6 +82,8 @@ type ApplyRunner struct {
timeout time.Duration
noPrune bool
prunePropagationPolicy string
waitForPrune bool
waitForPruneTimeout time.Duration
}
func (r *ApplyRunner) RunE(cmd *cobra.Command, args []string) error {
@ -100,6 +106,8 @@ func (r *ApplyRunner) RunE(cmd *cobra.Command, args []string) error {
NoPrune: r.noPrune,
DryRun: false,
PrunePropagationPolicy: prunePropPolicy,
WaitForPrune: r.waitForPrune,
WaitForPruneTimeout: r.waitForPruneTimeout,
})
// The printer will print updates from the channel. It will block

View File

@ -440,6 +440,8 @@ func (a *Applier) Run(ctx context.Context, options Options) <-chan event.Event {
Prune: !options.NoPrune,
DryRun: options.DryRun,
PrunePropagationPolicy: options.PrunePropagationPolicy,
WaitForPrune: options.WaitForPrune,
WaitForPruneTimeout: options.WaitForPruneTimeout,
})
// Send event to inform the caller about the resources that
@ -504,6 +506,15 @@ type Options struct {
// that should be used for pruning. If this is not provided, the
// default is to use the Background policy.
PrunePropagationPolicy metav1.DeletionPropagation
// WaitForPrune defines whether we should wait for all resources
// to be fully deleted after pruning. This is only effective
// if the PrunePropagationPolicy is set to Forground.
WaitForPrune bool
// WaitForPruneTimeout defines how long we should wait for all
// resources to be deleted after prune before giving up.
WaitForPruneTimeout time.Duration
}
// setDefaults set the options to the default values if they
@ -518,6 +529,9 @@ func setDefaults(o *Options) {
if o.PrunePropagationPolicy == metav1.DeletionPropagation("") {
o.PrunePropagationPolicy = metav1.DeletePropagationBackground
}
if o.WaitForPruneTimeout == time.Duration(0) {
o.WaitForPruneTimeout = time.Minute
}
}
func handleError(eventChannel chan event.Event, err error) {