Skip to content

Commit

Permalink
add ignore-errors flag, support none break drain in group
Browse files Browse the repository at this point in the history
add warning msg
  • Loading branch information
yuzhiquan committed Feb 1, 2021
1 parent 1bfa1d4 commit db264ea
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions staging/src/k8s.io/kubectl/pkg/cmd/drain/drain.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ func NewCmdDrain(f cmdutil.Factory, ioStreams genericclioptions.IOStreams) *cobr
}
cmd.Flags().BoolVar(&o.drainer.Force, "force", o.drainer.Force, "Continue even if there are pods not managed by a ReplicationController, ReplicaSet, Job, DaemonSet or StatefulSet.")
cmd.Flags().BoolVar(&o.drainer.IgnoreAllDaemonSets, "ignore-daemonsets", o.drainer.IgnoreAllDaemonSets, "Ignore DaemonSet-managed pods.")
cmd.Flags().BoolVar(&o.drainer.IgnoreErrors, "ignore-errors", o.drainer.IgnoreErrors, "Ignore errors occurred between drain nodes in group.")
cmd.Flags().BoolVar(&o.drainer.DeleteEmptyDirData, "delete-local-data", o.drainer.DeleteEmptyDirData, "Continue even if there are pods using emptyDir (local data that will be deleted when the node is drained).")
cmd.Flags().MarkDeprecated("delete-local-data", "This option is deprecated and will be deleted. Use --delete-emptydir-data.")
cmd.Flags().BoolVar(&o.drainer.DeleteEmptyDirData, "delete-emptydir-data", o.drainer.DeleteEmptyDirData, "Continue even if there are pods using emptyDir (local data that will be deleted when the node is drained).")
Expand Down Expand Up @@ -306,6 +307,13 @@ func (o *DrainCmdOptions) RunDrain() error {
drainedNodes.Insert(info.Name)
printObj(info.Object, o.Out)
} else {
if o.drainer.IgnoreErrors && len(o.nodeInfos) > 1 {
fmt.Fprintf(o.ErrOut, "error: unable to drain node %q due to error:%s, continuing command...\n", info.Name, err)
continue
}
fmt.Fprintf(o.ErrOut, "DEPRECATED WARNING: Aborting the drain command in a list of nodes will be deprecated.\n"+
"The new behavior will make the drain command go through all nodes even if one or more nodes failed during the drain.\n"+
"For now, users can try such experience via: --ignore-errors\n")
fmt.Fprintf(o.ErrOut, "error: unable to drain node %q, aborting command...\n\n", info.Name)
remainingNodes := []string{}
fatal = err
Expand Down
1 change: 1 addition & 0 deletions staging/src/k8s.io/kubectl/pkg/drain/drain.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type Helper struct {
Force bool
GracePeriodSeconds int
IgnoreAllDaemonSets bool
IgnoreErrors bool
Timeout time.Duration
DeleteEmptyDirData bool
Selector string
Expand Down

0 comments on commit db264ea

Please sign in to comment.