Skip to content

Commit fe712ea

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 084d2f4 commit fe712ea

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
}
@@ -1231,7 +1234,10 @@ func (e *ETCD) manageLearners(ctx context.Context) {
12311234
}
12321235

12331236
// verify if the member is healthy and set the status
1234-
if _, err := e.getETCDStatus(ctx, member.ClientURLs[0]); err != nil {
1237+
if len(member.ClientURLs) == 0 {
1238+
message = "etcd member ClientURLs list is empty"
1239+
status = StatusUnhealthy
1240+
} else if _, err := e.getETCDStatus(ctx, member.ClientURLs[0]); err != nil {
12351241
message = err.Error()
12361242
status = StatusUnhealthy
12371243
}

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)