Skip to content

Commit

Permalink
Merge pull request #258 from galal-hussein/add_etcd_delete_from_k8s
Browse files Browse the repository at this point in the history
Remove deleted etcd member from k8s and update kube-api with new list of members
  • Loading branch information
ibuildthecloud authored Jan 24, 2018
2 parents 89dec3f + efd9116 commit 1bcaaef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 9 additions & 5 deletions cluster/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -154,14 +154,18 @@ 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 {
if err := services.RemoveEtcdMember(ctx, etcdHost, kubeCluster.EtcdHosts, currentCluster.LocalConnDialerFactory); err != nil {
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)
Expand Down
3 changes: 2 additions & 1 deletion services/kubeapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit 1bcaaef

Please sign in to comment.