Skip to content

Commit

Permalink
Fix reconcile for ros prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
moelsayed authored and Alena Prokharchyk committed Jun 26, 2018
1 parent 74b81a8 commit fdba4f8
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 33 deletions.
3 changes: 1 addition & 2 deletions cluster/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,14 @@ func (c *Cluster) TunnelHosts(ctx context.Context, local bool) error {
c.InactiveHosts = make([]*hosts.Host, 0)
uniqueHosts := hosts.GetUniqueHostList(c.EtcdHosts, c.ControlPlaneHosts, c.WorkerHosts)
for i := range uniqueHosts {
if err := uniqueHosts[i].TunnelUp(ctx, c.DockerDialerFactory); err != nil {
if err := uniqueHosts[i].TunnelUp(ctx, c.DockerDialerFactory, c.PrefixPath); err != nil {
// Unsupported Docker version is NOT a connectivity problem that we can recover! So we bail out on it
if strings.Contains(err.Error(), "Unsupported Docker version found") {
return err
}
log.Warnf(ctx, "Failed to set up SSH tunneling for host [%s]: %v", uniqueHosts[i].Address, err)
c.InactiveHosts = append(c.InactiveHosts, uniqueHosts[i])
}
uniqueHosts[i].PrefixPath = c.getPrefixPath(uniqueHosts[i].DockerInfo.OperatingSystem)
}
for _, host := range c.InactiveHosts {
log.Warnf(ctx, "Removing host [%s] from node lists", host.Address)
Expand Down
25 changes: 1 addition & 24 deletions cluster/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ import (

const (
EtcdPathPrefix = "/registry"
B2DOS = "Boot2Docker"
B2DPrefixPath = "/mnt/sda1/rke"
ROS = "RancherOS"
ROSPrefixPath = "/opt/rke"
CoreOS = "CoreOS"
CoreOSPrefixPath = "/opt/rke"
ContainerNameLabel = "io.rancher.rke.container.name"
CloudConfigSumEnv = "RKE_CLOUD_CONFIG_CHECKSUM"
)
Expand All @@ -49,7 +43,7 @@ func GeneratePlan(ctx context.Context, rkeConfig *v3.RancherKubernetesEngineConf
}

func BuildRKEConfigNodePlan(ctx context.Context, myCluster *Cluster, host *hosts.Host, hostDockerInfo types.Info) v3.RKEConfigNodePlan {
prefixPath := myCluster.getPrefixPath(hostDockerInfo.OperatingSystem)
prefixPath := hosts.GetPrefixPath(hostDockerInfo.OperatingSystem, myCluster.PrefixPath)
processes := map[string]v3.Process{}
portChecks := []v3.PortCheck{}
// Everybody gets a sidecar and a kubelet..
Expand Down Expand Up @@ -681,23 +675,6 @@ func BuildPortChecksFromPortList(host *hosts.Host, portList []string, proto stri
return portChecks
}

func (c *Cluster) getPrefixPath(osType string) string {
var prefixPath string
switch {
case c.PrefixPath != "/":
prefixPath = c.PrefixPath
case strings.Contains(osType, B2DOS):
prefixPath = B2DPrefixPath
case strings.Contains(osType, ROS):
prefixPath = ROSPrefixPath
case strings.Contains(osType, CoreOS):
prefixPath = CoreOSPrefixPath
default:
prefixPath = c.PrefixPath
}
return prefixPath
}

func (c *Cluster) GetKubernetesServicesOptions() v3.KubernetesServicesOptions {
clusterMajorVersion := getTagMajorVersion(c.Version)
NamedkK8sImage, _ := ref.ParseNormalizedNamed(c.SystemImages.Kubernetes)
Expand Down
10 changes: 5 additions & 5 deletions cluster/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func reconcileWorker(ctx context.Context, currentCluster, kubeCluster *Cluster,
return fmt.Errorf("Failed to delete worker node [%s] from cluster: %v", toDeleteHost.Address, err)
}
// attempting to clean services/files on the host
if err := reconcileHost(ctx, toDeleteHost, true, false, currentCluster.SystemImages.Alpine, currentCluster.DockerDialerFactory, currentCluster.PrivateRegistriesMap); err != nil {
if err := reconcileHost(ctx, toDeleteHost, true, false, currentCluster.SystemImages.Alpine, currentCluster.DockerDialerFactory, currentCluster.PrivateRegistriesMap, currentCluster.PrefixPath); err != nil {
log.Warnf(ctx, "[reconcile] Couldn't clean up worker node [%s]: %v", toDeleteHost.Address, err)
continue
}
Expand Down Expand Up @@ -104,7 +104,7 @@ func reconcileControl(ctx context.Context, currentCluster, kubeCluster *Cluster,
return fmt.Errorf("Failed to delete controlplane node [%s] from cluster: %v", toDeleteHost.Address, err)
}
// attempting to clean services/files on the host
if err := reconcileHost(ctx, toDeleteHost, false, false, currentCluster.SystemImages.Alpine, currentCluster.DockerDialerFactory, currentCluster.PrivateRegistriesMap); err != nil {
if err := reconcileHost(ctx, toDeleteHost, false, false, currentCluster.SystemImages.Alpine, currentCluster.DockerDialerFactory, currentCluster.PrivateRegistriesMap, currentCluster.PrefixPath); err != nil {
log.Warnf(ctx, "[reconcile] Couldn't clean up controlplane node [%s]: %v", toDeleteHost.Address, err)
continue
}
Expand All @@ -124,8 +124,8 @@ func reconcileControl(ctx context.Context, currentCluster, kubeCluster *Cluster,
return nil
}

func reconcileHost(ctx context.Context, toDeleteHost *hosts.Host, worker, etcd bool, cleanerImage string, dialerFactory hosts.DialerFactory, prsMap map[string]v3.PrivateRegistry) error {
if err := toDeleteHost.TunnelUp(ctx, dialerFactory); err != nil {
func reconcileHost(ctx context.Context, toDeleteHost *hosts.Host, worker, etcd bool, cleanerImage string, dialerFactory hosts.DialerFactory, prsMap map[string]v3.PrivateRegistry, clusterPrefixPath string) error {
if err := toDeleteHost.TunnelUp(ctx, dialerFactory, clusterPrefixPath); err != nil {
return fmt.Errorf("Not able to reach the host: %v", err)
}
if worker {
Expand Down Expand Up @@ -170,7 +170,7 @@ func reconcileEtcd(ctx context.Context, currentCluster, kubeCluster *Cluster, ku
continue
}
// attempting to clean services/files on the host
if err := reconcileHost(ctx, etcdHost, false, true, currentCluster.SystemImages.Alpine, currentCluster.DockerDialerFactory, currentCluster.PrivateRegistriesMap); err != nil {
if err := reconcileHost(ctx, etcdHost, false, true, currentCluster.SystemImages.Alpine, currentCluster.DockerDialerFactory, currentCluster.PrivateRegistriesMap, currentCluster.PrefixPath); err != nil {
log.Warnf(ctx, "[reconcile] Couldn't clean up etcd node [%s]: %v", etcdHost.Address, err)
continue
}
Expand Down
25 changes: 25 additions & 0 deletions hosts/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"path"
"strings"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
Expand Down Expand Up @@ -47,6 +48,13 @@ const (
ToCleanCalicoRun = "/var/run/calico/"
ToCleanTempCertPath = "/etc/kubernetes/.tmp/"
CleanerContainerName = "kube-cleaner"

B2DOS = "Boot2Docker"
B2DPrefixPath = "/mnt/sda1/rke"
ROS = "RancherOS"
ROSPrefixPath = "/opt/rke"
CoreOS = "CoreOS"
CoreOSPrefixPath = "/opt/rke"
)

func (h *Host) CleanUpAll(ctx context.Context, cleanerImage string, prsMap map[string]v3.PrivateRegistry, externalEtcd bool) error {
Expand Down Expand Up @@ -283,3 +291,20 @@ func GetUniqueHostList(etcdHosts, cpHosts, workerHosts []*Host) []*Host {
}
return uniqHostList
}

func GetPrefixPath(osType, ClusterPrefixPath string) string {
var prefixPath string
switch {
case ClusterPrefixPath != "/":
prefixPath = ClusterPrefixPath
case strings.Contains(osType, B2DOS):
prefixPath = B2DPrefixPath
case strings.Contains(osType, ROS):
prefixPath = ROSPrefixPath
case strings.Contains(osType, CoreOS):
prefixPath = CoreOSPrefixPath
default:
prefixPath = ClusterPrefixPath
}
return prefixPath
}
8 changes: 6 additions & 2 deletions hosts/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const (
K8sVersion = "1.8"
)

func (h *Host) TunnelUp(ctx context.Context, dialerFactory DialerFactory) error {
func (h *Host) TunnelUp(ctx context.Context, dialerFactory DialerFactory, clusterPrefixPath string) error {
if h.DClient != nil {
return nil
}
Expand All @@ -37,7 +37,11 @@ func (h *Host) TunnelUp(ctx context.Context, dialerFactory DialerFactory) error
if err != nil {
return fmt.Errorf("Can't initiate NewClient: %v", err)
}
return checkDockerVersion(ctx, h)
if err := checkDockerVersion(ctx, h); err != nil {
return err
}
h.PrefixPath = GetPrefixPath(h.DockerInfo.OperatingSystem, clusterPrefixPath)
return nil
}

func (h *Host) TunnelUpLocal(ctx context.Context) error {
Expand Down

0 comments on commit fdba4f8

Please sign in to comment.