forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schedulable.go
47 lines (39 loc) · 990 Bytes
/
schedulable.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package node
import (
"fmt"
"k8s.io/apimachinery/pkg/types"
kerrors "k8s.io/apimachinery/pkg/util/errors"
kprinters "k8s.io/kubernetes/pkg/printers"
)
type SchedulableOptions struct {
Options *NodeOptions
Schedulable bool
}
func (s *SchedulableOptions) Run() error {
nodes, err := s.Options.GetNodes()
if err != nil {
return err
}
errList := []error{}
var printer kprinters.ResourcePrinter
unschedulable := !s.Schedulable
for _, node := range nodes {
if node.Spec.Unschedulable != unschedulable {
patch := fmt.Sprintf(`{"spec":{"unschedulable":%t}}`, unschedulable)
node, err = s.Options.KubeClient.Core().Nodes().Patch(node.Name, types.MergePatchType, []byte(patch))
if err != nil {
errList = append(errList, err)
continue
}
}
if printer == nil {
p, err := s.Options.GetPrintersByObject(node)
if err != nil {
return err
}
printer = p
}
printer.PrintObj(node, s.Options.Writer)
}
return kerrors.NewAggregate(errList)
}