forked from rancher/rancher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cordonfieldssyncer.go
35 lines (33 loc) · 935 Bytes
/
cordonfieldssyncer.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
package nodesyncer
import (
"github.com/rancher/norman/types/convert"
"github.com/rancher/types/apis/management.cattle.io/v3"
"k8s.io/apimachinery/pkg/labels"
)
func (m *NodesSyncer) syncCordonFields(key string, obj *v3.Node) error {
if obj == nil || obj.DeletionTimestamp != nil || obj.Spec.DesiredNodeUnschedulable == "" {
return nil
}
nodes, err := m.nodeLister.List("", labels.NewSelector())
if err != nil {
return err
}
node, err := m.getNode(obj, nodes)
if err != nil {
return err
}
desiredValue := convert.ToBool(obj.Spec.DesiredNodeUnschedulable)
if node.Spec.Unschedulable != desiredValue {
toUpdate := node.DeepCopy()
toUpdate.Spec.Unschedulable = desiredValue
if _, err := m.nodeClient.Update(toUpdate); err != nil {
return err
}
}
nodeCopy := obj.DeepCopy()
nodeCopy.Spec.DesiredNodeUnschedulable = ""
if _, err := m.machines.Update(nodeCopy); err != nil {
return err
}
return nil
}