Skip to content

Commit

Permalink
Addressed review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronfern committed Jul 7, 2022
1 parent 7d0e17e commit 5aae944
Show file tree
Hide file tree
Showing 7 changed files with 306 additions and 377 deletions.
100 changes: 5 additions & 95 deletions pkg/initializer/initializer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package initializer

import (
"context"
"fmt"
"os"
"path/filepath"
Expand Down Expand Up @@ -45,13 +46,14 @@ import (
func (e *EtcdInitializer) Initialize(mode validator.Mode, failBelowRevision int64) error {
start := time.Now()
//Etcd cluster scale-up case
m := member.NewMemberConfig(e.Config.EtcdConnectionConfig)
clusterMember, err := m.IsMemberInCluster(e.Logger)
m := member.NewMemberControl(e.Config.EtcdConnectionConfig)
ctx := context.Background()
clusterMember, err := m.IsMemberInCluster(ctx)
if !clusterMember && err == nil {
retry.OnError(retry.DefaultBackoff, func(err error) bool {
return err != nil
}, func() error {
return m.AddMemberAsLearner(e.Logger)
return m.AddMemberAsLearner(ctx)
})
// return here after adding member as no restoration or validation needed
return nil
Expand Down Expand Up @@ -215,95 +217,3 @@ func (e *EtcdInitializer) removeDir(dirname string) error {
}
return nil
}

// func (r *EtcdInitializer) SingleMemberRestoreCase() bool {
// r.Logger.Info("Starting single member restore case")
// clientSet, err := miscellaneous.GetKubernetesClientSetOrError()
// if err != nil {
// r.Logger.Errorf("failed to create clientset: %v", err)
// return false
// }
// r.Logger.Info("Single member restore case: k8s clientset created")

// //Fetch lease associated with member
// memberLease := &v1.Lease{}
// err = clientSet.Get(context.TODO(), controller_runtime_client.ObjectKey{
// Namespace: os.Getenv("POD_NAMESPACE"),
// Name: os.Getenv("POD_NAME"),
// }, memberLease)
// if err != nil {
// r.Logger.Errorf("error fetching lease: %v", err)
// }
// r.Logger.Info("Single member restore case: fetched lease")

// if memberLease.Spec.HolderIdentity != nil {
// r.Logger.Info("Single member restore case: lease holder ID is not nil")
// //Case of lease already existing
// //Assume case of single member restoration

// //Create etcd client
// clientFactory := etcdutil.NewFactory(brtypes.EtcdConnectionConfig{
// Endpoints: []string{"http://etcd-main-peer.default.svc.cluster.local:2380"},
// InsecureTransport: true,
// })
// cli, _ := clientFactory.NewCluster()
// r.Logger.Info("Single member restore case: created etcd client")

// //remove self from cluster
// ctx3, cancel := context.WithTimeout(context.TODO(), 5*time.Second)
// etcdList, err2 := cli.MemberList(ctx3)
// if err2 != nil {
// r.Logger.Warn("Could not list any etcd members")
// }
// cancel()
// r.Logger.Info("Single member restore case: etcd member list done")
// //mem := make(map[string]uint64)
// var peerURL []string
// for _, y := range etcdList.Members {
// if y.Name == os.Getenv("POD_NAME") {
// peerURL = y.PeerURLs
// cli.MemberRemove(context.TODO(), y.ID)
// r.Logger.Info("Single member restore case: member removed")
// break
// }
// }

// //Add self to the cluster
// ctx4, cancel := context.WithTimeout(context.TODO(), 5*time.Second)
// cli.MemberAdd(ctx4, peerURL)
// cancel()
// r.Logger.Info("Single member restore case: member added")
// return true
// }

// return false
// }

// func (r *EtcdInitializer) IsMemberInCluster() bool {
// //Create etcd client
// clientFactory := etcdutil.NewFactory(brtypes.EtcdConnectionConfig{
// Endpoints: []string{"http://etcd-main-peer.default.svc.cluster.local:2380"}, //TODO: use ETCD_ENDPOINT env var passed by druid
// InsecureTransport: true, //TODO: is it right to use insecure transport?
// })
// cli, _ := clientFactory.NewCluster()
// r.Logger.Info("Etcd client created")

// // List members in cluster
// memListCtx, cancel := context.WithTimeout(context.TODO(), brtypes.DefaultEtcdConnectionTimeout)
// etcdMemberList, err := cli.MemberList(memListCtx)
// cancel()
// if err != nil {
// r.Logger.Warn("Could not list any etcd members", err)
// return true
// }

// for _, y := range etcdMemberList.Members {
// if y.Name == os.Getenv("POD_NAME") {
// return true
// }
// }

// cli.Close()

// return false
// }
264 changes: 0 additions & 264 deletions pkg/member/member_add.go

This file was deleted.

Loading

0 comments on commit 5aae944

Please sign in to comment.