func (o *DrainCmdOptions) RunCordonOrUncordon(desired bool) error {
	cordonOrUncordon := "cordon"
	if !desired {
		cordonOrUncordon = "un" + cordonOrUncordon
	}

	for _, nodeInfo := range o.nodeInfos {

		printError := func(err error) {
			fmt.Fprintf(o.ErrOut, "error: unable to %s node %q: %v\n", cordonOrUncordon, nodeInfo.Name, err)
		}

		gvk := nodeInfo.ResourceMapping().GroupVersionKind
		if gvk.Kind == "Node" {
			c, err := drain.NewCordonHelperFromRuntimeObject(nodeInfo.Object, scheme.Scheme, gvk)
			if err != nil {
				printError(err)
				continue
			}

			if updateRequired := c.UpdateIfRequired(desired); !updateRequired {
				printObj, err := o.ToPrinter(already(desired))
				if err != nil {
					fmt.Fprintf(o.ErrOut, "error: %v\n", err)
					continue
				}
				printObj(nodeInfo.Object, o.Out)
			} else {
				if o.drainer.DryRunStrategy != cmdutil.DryRunClient {
					if o.drainer.DryRunStrategy == cmdutil.DryRunServer {
						if err := o.drainer.DryRunVerifier.HasSupport(gvk); err != nil {
							printError(err)
							continue
						}
					}
					err, patchErr := c.PatchOrReplace(o.drainer.Client, o.drainer.DryRunStrategy == cmdutil.DryRunServer)
					if patchErr != nil {
						printError(patchErr)
					}
					if err != nil {
						printError(err)
						continue
					}
				}
				printObj, err := o.ToPrinter(changed(desired))
				if err != nil {
					fmt.Fprintf(o.ErrOut, "%v\n", err)
					continue
				}
				printObj(nodeInfo.Object, o.Out)
			}
		} else {
			printObj, err := o.ToPrinter("skipped")
			if err != nil {
				fmt.Fprintf(o.ErrOut, "%v\n", err)
				continue
			}
			printObj(nodeInfo.Object, o.Out)
		}
	}

	return nil
}
// RunCordonOrUncordon runs either Cordon or Uncordon.  The desired value for
// "Unschedulable" is passed as the first arg.
RunCordonOrUncordon runs either Cordon or Uncordon.  The desired value for
"Unschedulable" is passed as the first arg.
// RunCordonOrUncordon runs either Cordon or Uncordon . The desired value for // " Unschedulable " is passed as the first arg .
func (o *DrainCmdOptions) RunCordonOrUncordon(desired bool) error {
	cordonOrUncordon := "cordon"
	if !desired {
		cordonOrUncordon = "un" + cordonOrUncordon
	}
	for _, nodeInfo := range o.nodeInfos {
		printError := func(err error) {
			fmt.Fprintf(o.ErrOut, "error: unable to %s node %q: %v\n", cordonOrUncordon, nodeInfo.Name, err)
		}
		gvk := nodeInfo.ResourceMapping().GroupVersionKind
		if gvk.Kind == "Node" {
			c, err := drain.NewCordonHelperFromRuntimeObject(nodeInfo.Object, scheme.Scheme, gvk)
			if err != nil {
				printError(err)
				continue
			}
			if updateRequired := c.UpdateIfRequired(desired); !updateRequired {
				printObj, err := o.ToPrinter(already(desired))
				if err != nil {
					fmt.Fprintf(o.ErrOut, "error: %v\n", err)
					continue
				}
				printObj(nodeInfo.Object, o.Out)
			} else {
				if o.drainer.DryRunStrategy != cmdutil.DryRunClient {
					if o.drainer.DryRunStrategy == cmdutil.DryRunServer {
						if err := o.drainer.DryRunVerifier.HasSupport(gvk); err != nil {
							printError(err)
							continue
						}
					}
					err, patchErr := c.PatchOrReplace(o.drainer.Client, o.drainer.DryRunStrategy == cmdutil.DryRunServer)
					if patchErr != nil {
						printError(patchErr)
					}
					if err != nil {
						printError(err)
						continue
					}
				}
				printObj, err := o.ToPrinter(changed(desired))
				if err != nil {
					fmt.Fprintf(o.ErrOut, "%v\n", err)
					continue
				}
				printObj(nodeInfo.Object, o.Out)
			}
		} else {
			printObj, err := o.ToPrinter("skipped")
			if err != nil {
				fmt.Fprintf(o.ErrOut, "%v\n", err)
				continue
			}
			printObj(nodeInfo.Object, o.Out)
		}
	}
	return nil
}
func ( o * DrainCmdOptions ) RunCordonOrUncordon ( desired bool ) error { cordonOrUncordon := " " if ! desired { cordonOrUncordon = " " + cordonOrUncordon } for _ , nodeInfo := range o . nodeInfos { printError := func ( err error ) { fmt . Fprintf ( o . ErrOut , " \n " , cordonOrUncordon , nodeInfo . Name , err ) } gvk := nodeInfo . ResourceMapping ( ) . GroupVersionKind if gvk . Kind == " " { c , err := drain . NewCordonHelperFromRuntimeObject ( nodeInfo . Object , scheme . Scheme , gvk ) if err != nil { printError ( err ) continue } if updateRequired := c . UpdateIfRequired ( desired ) ; ! updateRequired { printObj , err := o . ToPrinter ( already ( desired ) ) if err != nil { fmt . Fprintf ( o . ErrOut , " \n " , err ) continue } printObj ( nodeInfo . Object , o . Out ) } else { if o . drainer . DryRunStrategy != cmdutil . DryRunClient { if o . drainer . DryRunStrategy == cmdutil . DryRunServer { if err := o . drainer . DryRunVerifier . HasSupport ( gvk ) ; err != nil { printError ( err ) continue } } err , patchErr := c . PatchOrReplace ( o . drainer . Client , o . drainer . DryRunStrategy == cmdutil . DryRunServer ) if patchErr != nil { printError ( patchErr ) } if err != nil { printError ( err ) continue } } printObj , err := o . ToPrinter ( changed ( desired ) ) if err != nil { fmt . Fprintf ( o . ErrOut , " \n " , err ) continue } printObj ( nodeInfo . Object , o . Out ) } } else { printObj , err := o . ToPrinter ( " " ) if err != nil { fmt . Fprintf ( o . ErrOut , " \n " , err ) continue } printObj ( nodeInfo . Object , o . Out ) } } return nil }
RunCordonOrUncordon runs either Cordon or Uncordon.
RunCordonOrUncordon runs either Cordon or Uncordon .