1
0
mirror of https://github.com/rancher/rke.git synced 2025-07-12 22:58:51 +00:00

Merge pull request #47 from galal-hussein/error_fix

Add error messages for adding/removing nodes while upgrade
This commit is contained in:
Hussein Galal 2017-11-26 22:40:19 +02:00 committed by GitHub
commit e22f6e79de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 0 deletions

View File

@ -89,6 +89,14 @@ func (c *Cluster) SetUpHosts() error {
return nil
}
func CheckEtcdHostsChanged(kubeCluster, currentCluster *Cluster) error {
etcdChanged := hosts.IsHostListChanged(currentCluster.EtcdHosts, kubeCluster.EtcdHosts)
if etcdChanged {
return fmt.Errorf("Adding or removing Etcd nodes is not supported")
}
return nil
}
func checkEncryptedKey(sshKeyPath string) (ssh.Signer, error) {
logrus.Infof("[ssh] Checking private key")
key, err := hosts.ParsePrivateKey(privateKeyPath(sshKeyPath))

View File

@ -3,6 +3,7 @@ package cluster
import (
"fmt"
"github.com/rancher/rke/hosts"
"github.com/rancher/rke/k8s"
"github.com/rancher/rke/services"
"github.com/sirupsen/logrus"
@ -48,3 +49,19 @@ func checkK8sNodesState(localConfigPath string) error {
logrus.Infof("[upgrade] All nodes are Ready")
return nil
}
func CheckHostsChangedOnUpgrade(kubeCluster, currentCluster *Cluster) error {
etcdChanged := hosts.IsHostListChanged(currentCluster.EtcdHosts, kubeCluster.EtcdHosts)
if etcdChanged {
return fmt.Errorf("Adding or removing Etcd nodes while upgrade is not supported")
}
cpChanged := hosts.IsHostListChanged(currentCluster.ControlPlaneHosts, kubeCluster.ControlPlaneHosts)
if cpChanged {
return fmt.Errorf("Adding or removing Control plane nodes while upgrade is not supported")
}
workerChanged := hosts.IsHostListChanged(currentCluster.WorkerHosts, kubeCluster.WorkerHosts)
if workerChanged {
return fmt.Errorf("Adding or removing Worker plane nodes while upgrade is not supported")
}
return nil
}

View File

@ -82,6 +82,10 @@ func ClusterUp(clusterFile string) (string, string, string, string, error) {
return APIURL, caCrt, clientCert, clientKey, err
}
if err := cluster.CheckEtcdHostsChanged(kubeCluster, currentCluster); err != nil {
return APIURL, caCrt, clientCert, clientKey, err
}
err = cluster.SetUpAuthentication(kubeCluster, currentCluster)
if err != nil {
return APIURL, caCrt, clientCert, clientKey, err
@ -148,6 +152,10 @@ func ClusterUpgrade(clusterFile string) (string, string, string, string, error)
if currentCluster == nil {
return APIURL, caCrt, clientCert, clientKey, fmt.Errorf("Failed to get the current state of Kubernetes cluster")
}
// check if user try to add/remove hosts during upgrade
if err := cluster.CheckHostsChangedOnUpgrade(kubeCluster, currentCluster); err != nil {
return APIURL, caCrt, clientCert, clientKey, err
}
/*
kubeCluster is the cluster.yaml definition. It should have updated configuration
currentCluster is the current state fetched from kubernetes