1
0
mirror of https://github.com/rancher/rke.git synced 2025-05-04 06:16:48 +00:00
rke/hosts/hosts.go

42 lines
1.1 KiB
Go
Raw Normal View History

2017-10-29 09:45:21 +00:00
package hosts
import (
"github.com/docker/docker/client"
"github.com/rancher/rke/k8s"
2017-11-14 18:11:21 +00:00
"github.com/rancher/types/apis/cluster.cattle.io/v1"
2017-11-13 21:28:38 +00:00
"github.com/sirupsen/logrus"
"k8s.io/client-go/kubernetes"
)
2017-10-29 09:45:21 +00:00
type Host struct {
2017-11-09 19:50:49 +00:00
v1.RKEConfigHost
DClient *client.Client
2017-10-29 09:45:21 +00:00
}
func ReconcileWorkers(currentWorkers []Host, newWorkers []Host, kubeClient *kubernetes.Clientset) error {
for _, currentWorker := range currentWorkers {
found := false
for _, newWorker := range newWorkers {
2017-11-14 18:11:21 +00:00
if currentWorker.AdvertisedHostname == newWorker.AdvertisedHostname {
found = true
2017-10-29 09:45:21 +00:00
}
}
if !found {
if err := deleteWorkerNode(&currentWorker, kubeClient); err != nil {
return err
2017-10-29 09:45:21 +00:00
}
}
}
return nil
}
func deleteWorkerNode(workerNode *Host, kubeClient *kubernetes.Clientset) error {
2017-11-14 18:11:21 +00:00
logrus.Infof("[hosts] Deleting host [%s] from the cluster", workerNode.AdvertisedHostname)
err := k8s.DeleteNode(kubeClient, workerNode.AdvertisedHostname)
if err != nil {
return err
}
2017-11-14 18:11:21 +00:00
logrus.Infof("[hosts] Successfully deleted host [%s] from the cluster", workerNode.AdvertisedHostname)
return nil
2017-10-29 09:45:21 +00:00
}