forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schedulable.go
57 lines (49 loc) · 1.25 KB
/
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
48
49
50
51
52
53
54
55
56
57
package node
import (
kapi "github.com/GoogleCloudPlatform/kubernetes/pkg/api"
kerrors "github.com/GoogleCloudPlatform/kubernetes/pkg/util/errors"
)
type SchedulableOptions struct {
Options *NodeOptions
Schedulable bool
}
func (s *SchedulableOptions) Run() error {
nodes, err := s.Options.GetNodes()
if err != nil {
return err
}
errList := []error{}
ignoreHeaders := false
for _, node := range nodes {
err := s.RunSchedulable(node, &ignoreHeaders)
if err != nil {
// Don't bail out if one node fails
errList = append(errList, err)
}
}
return kerrors.NewAggregate(errList)
}
func (s *SchedulableOptions) RunSchedulable(node *kapi.Node, ignoreHeaders *bool) error {
var updatedNode *kapi.Node
var err error
if node.Spec.Unschedulable != !s.Schedulable {
node.Spec.Unschedulable = !s.Schedulable
updatedNode, err = s.Options.Kclient.Nodes().Update(node)
if err != nil {
return err
}
} else {
updatedNode = node
}
printerWithHeaders, printerNoHeaders, err := s.Options.GetPrintersByObject(updatedNode)
if err != nil {
return err
}
if *ignoreHeaders {
printerNoHeaders.PrintObj(updatedNode, s.Options.Writer)
} else {
printerWithHeaders.PrintObj(updatedNode, s.Options.Writer)
*ignoreHeaders = true
}
return nil
}