From efd9116b80eb994374ae2c20c26e2b947f3502a6 Mon Sep 17 00:00:00 2001 From: galal-hussein Date: Wed, 24 Jan 2018 05:19:44 +0200 Subject: [PATCH] remove deleted etcd member from k8s and update kube-api with new list --- cluster/reconcile.go | 14 +++++++++----- services/kubeapi.go | 3 ++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/cluster/reconcile.go b/cluster/reconcile.go index 1c975f63e..7cf620959 100644 --- a/cluster/reconcile.go +++ b/cluster/reconcile.go @@ -24,15 +24,15 @@ func ReconcileCluster(ctx context.Context, kubeCluster, currentCluster *Cluster) return nil } - if err := reconcileEtcd(ctx, currentCluster, kubeCluster); err != nil { - return fmt.Errorf("Failed to reconcile etcd plane: %v", err) - } - kubeClient, err := k8s.NewClient(kubeCluster.LocalKubeConfigPath) if err != nil { return fmt.Errorf("Failed to initialize new kubernetes client: %v", err) } + if err := reconcileEtcd(ctx, currentCluster, kubeCluster, kubeClient); err != nil { + return fmt.Errorf("Failed to reconcile etcd plane: %v", err) + } + if err := reconcileWorker(ctx, currentCluster, kubeCluster, kubeClient); err != nil { return err } @@ -154,7 +154,7 @@ func reconcileHost(ctx context.Context, toDeleteHost *hosts.Host, worker, etcd b return nil } -func reconcileEtcd(ctx context.Context, currentCluster, kubeCluster *Cluster) error { +func reconcileEtcd(ctx context.Context, currentCluster, kubeCluster *Cluster, kubeClient *kubernetes.Clientset) error { log.Infof(ctx, "[reconcile] Check etcd hosts to be deleted") etcdToDelete := hosts.GetToDeleteHosts(currentCluster.EtcdHosts, kubeCluster.EtcdHosts) for _, etcdHost := range etcdToDelete { @@ -162,6 +162,10 @@ func reconcileEtcd(ctx context.Context, currentCluster, kubeCluster *Cluster) er log.Warnf(ctx, "[reconcile] %v", err) continue } + if err := hosts.DeleteNode(ctx, etcdHost, kubeClient, etcdHost.IsControl); err != nil { + log.Warnf(ctx, "Failed to delete etcd node %s from cluster", etcdHost.Address) + continue + } // attempting to clean services/files on the host if err := reconcileHost(ctx, etcdHost, false, true, currentCluster.SystemImages[AplineImage], currentCluster.DockerDialerFactory); err != nil { log.Warnf(ctx, "[reconcile] Couldn't clean up etcd node [%s]: %v", etcdHost.Address, err) diff --git a/services/kubeapi.go b/services/kubeapi.go index b746cb9fb..e62a2f673 100644 --- a/services/kubeapi.go +++ b/services/kubeapi.go @@ -41,12 +41,13 @@ func buildKubeAPIConfig(host *hosts.Host, kubeAPIService v3.KubeAPIService, etcd "--runtime-config=batch/v2alpha1", "--runtime-config=authentication.k8s.io/v1beta1=true", "--storage-backend=etcd3", - "--etcd-servers=" + etcdConnString, "--client-ca-file=" + pki.CACertPath, "--tls-cert-file=" + pki.KubeAPICertPath, "--tls-private-key-file=" + pki.KubeAPIKeyPath, "--service-account-key-file=" + pki.KubeAPIKeyPath}, } + imageCfg.Cmd = append(imageCfg.Cmd, "--etcd-servers="+etcdConnString) + if authorizationMode == RBACAuthorizationMode { imageCfg.Cmd = append(imageCfg.Cmd, "--authorization-mode=RBAC") }