forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
schedulable.go
53 lines (44 loc) · 1.09 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
package node
import (
"fmt"
"k8s.io/apimachinery/pkg/types"
kerrors "k8s.io/apimachinery/pkg/util/errors"
)
type SchedulableOptions struct {
Options *NodeOptions
Schedulable bool
}
func NewSchedulableOptions(nodeOpts *NodeOptions) *SchedulableOptions {
return &SchedulableOptions{
Options: nodeOpts,
}
}
func (s *SchedulableOptions) Run() error {
nodes, err := s.Options.GetNodes()
if err != nil {
return err
}
errList := []error{}
unschedulable := !s.Schedulable
for _, node := range nodes {
if node.Spec.Unschedulable != unschedulable {
patch := fmt.Sprintf(`{"spec":{"unschedulable":%t}}`, unschedulable)
node, err = s.Options.KubeClient.CoreV1().Nodes().Patch(node.Name, types.MergePatchType, []byte(patch))
if err != nil {
errList = append(errList, err)
continue
}
}
message := "schedulable"
if unschedulable {
message = "unschedulable"
}
p, err := s.Options.ToPrinter(fmt.Sprintf("marked %s", message))
if err != nil {
errList = append(errList, err)
continue
}
p.PrintObj(node, s.Options.Out)
}
return kerrors.NewAggregate(errList)
}