forked from rancher/rke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhosts.go
45 lines (41 loc) · 1.22 KB
/
hosts.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
package hosts
import (
"github.com/Sirupsen/logrus"
"github.com/docker/docker/client"
"github.com/rancher/rke/k8s"
"k8s.io/client-go/kubernetes"
)
type Host struct {
IP string `yaml:"ip"`
AdvertiseAddress string `yaml:"advertise_address"`
Role []string `yaml:"role"`
Hostname string `yaml:"hostname"`
User string `yaml:"user"`
DockerSocket string `yaml:"docker_socket"`
DClient *client.Client
}
func ReconcileWorkers(currentWorkers []Host, newWorkers []Host, kClient *kubernetes.Clientset) error {
for _, currentWorker := range currentWorkers {
found := false
for _, newWorker := range newWorkers {
if currentWorker.Hostname == newWorker.Hostname {
found = true
}
}
if !found {
if err := deleteWorkerNode(¤tWorker, kClient); err != nil {
return err
}
}
}
return nil
}
func deleteWorkerNode(workerNode *Host, kClient *kubernetes.Clientset) error {
logrus.Infof("[hosts] Deleting host [%s] from the cluster", workerNode.Hostname)
err := k8s.DeleteNode(kClient, workerNode.Hostname)
if err != nil {
return err
}
logrus.Infof("[hosts] Successfully deleted host [%s] from the cluster", workerNode.Hostname)
return nil
}