Skip to content

Commit bda4754

Browse files
committed
Fix removal of init node
Removing the initial node from the cluster would previously cause etcd to panic on startup. Fixes to etcd reconcile have stopped that from happening, but now the node will successfully come up and start a new cluster - which is not right either. Require either manual removal of DB files to create a new cluster, or setting server address to join an existing cluster. Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
1 parent 8a8bc55 commit bda4754

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

pkg/etcd/etcd.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,10 @@ func (e *ETCD) Register(handler http.Handler) (http.Handler, error) {
700700
if !e.config.DisableETCD {
701701
tombstoneFile := filepath.Join(dbDir(e.config), "tombstone")
702702
if _, err := os.Stat(tombstoneFile); err == nil {
703-
logrus.Infof("tombstone file has been detected, removing data dir to rejoin the cluster")
703+
if e.config.JoinURL == "" {
704+
return nil, errors.New("tombstone file has been detected but --server is empty: backup and delete ${datadir}/server/db to create a new cluster, or set --server to rejoin the cluster")
705+
}
706+
logrus.Infof("tombstone file has been detected, removing ${datadir}/server/db to rejoin the cluster")
704707
if _, err := backupDirWithRetention(dbDir(e.config), maxBackupRetention); err != nil {
705708
return nil, err
706709
}
@@ -1229,7 +1232,10 @@ func (e *ETCD) manageLearners(ctx context.Context) {
12291232
}
12301233

12311234
// verify if the member is healthy and set the status
1232-
if _, err := e.getETCDStatus(ctx, member.ClientURLs[0]); err != nil {
1235+
if len(member.ClientURLs) == 0 {
1236+
message = "etcd member ClientURLs list is empty"
1237+
status = StatusUnhealthy
1238+
} else if _, err := e.getETCDStatus(ctx, member.ClientURLs[0]); err != nil {
12331239
message = err.Error()
12341240
status = StatusUnhealthy
12351241
}

pkg/etcd/etcd_linux_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ func Test_UnitETCD_Register(t *testing.T) {
213213
testutil.CleanupDataDir(cnf)
214214
return nil
215215
},
216+
wantErr: true,
216217
},
217218
}
218219
for _, tt := range tests {

0 commit comments

Comments
 (0)