diff --git a/pkg/cli/server/server.go b/pkg/cli/server/server.go index 86558ac321..0e19d34ff9 100644 --- a/pkg/cli/server/server.go +++ b/pkg/cli/server/server.go @@ -267,8 +267,13 @@ func run(app *cli.Context, cfg *cmds.Server) error { } go func() { - <-serverConfig.ControlConfig.Runtime.APIServerReady - logrus.Info("Kube API server is now running") + if !serverConfig.ControlConfig.DisableAPIServer { + <-serverConfig.ControlConfig.Runtime.APIServerReady + logrus.Info("Kube API server is now running") + } else { + <-serverConfig.ControlConfig.Runtime.ETCDReady + logrus.Info("ETCD server is now running") + } logrus.Info(version.Program + " is up and running") if notifySocket != "" { os.Setenv("NOTIFY_SOCKET", notifySocket) diff --git a/pkg/cluster/cluster.go b/pkg/cluster/cluster.go index 1ffec23e62..87060129e8 100644 --- a/pkg/cluster/cluster.go +++ b/pkg/cluster/cluster.go @@ -41,7 +41,7 @@ func (c *Cluster) Start(ctx context.Context) (<-chan struct{}, error) { defer close(ready) // try to get /db/info urls first before attempting to use join url - clientURLs, _, err := etcd.ClientURLs(ctx, c.clientAccessInfo) + clientURLs, _, err := etcd.ClientURLs(ctx, c.clientAccessInfo, c.config.PrivateIP) if err != nil { return nil, err } @@ -58,6 +58,12 @@ func (c *Cluster) Start(ctx context.Context) (<-chan struct{}, error) { return nil, err } c.setupEtcdProxy(ctx, etcdProxy) + + // remove etcd member if it exists + if err := c.managedDB.RemoveSelf(ctx); err != nil { + return nil, err + } + return ready, nil } diff --git a/pkg/cluster/managed/drivers.go b/pkg/cluster/managed/drivers.go index ac43c9e2d3..0a6e8f38ee 100644 --- a/pkg/cluster/managed/drivers.go +++ b/pkg/cluster/managed/drivers.go @@ -23,6 +23,7 @@ type Driver interface { EndpointName() string Snapshot(ctx context.Context, config *config.Control) error GetMembersClientURLs(ctx context.Context) ([]string, error) + RemoveSelf(ctx context.Context) error } func RegisterDriver(d Driver) { diff --git a/pkg/etcd/controller.go b/pkg/etcd/controller.go index 5da364aafa..81f46a69c8 100644 --- a/pkg/etcd/controller.go +++ b/pkg/etcd/controller.go @@ -87,5 +87,5 @@ func (h *handler) onRemove(key string, node *v1.Node) (*v1.Node, error) { if !ok { return node, nil } - return node, h.etcd.removePeer(h.ctx, id, address) + return node, h.etcd.removePeer(h.ctx, id, address, false) } diff --git a/pkg/etcd/etcd.go b/pkg/etcd/etcd.go index 971d4aa412..67ec4190fe 100644 --- a/pkg/etcd/etcd.go +++ b/pkg/etcd/etcd.go @@ -245,7 +245,7 @@ func (e *ETCD) Start(ctx context.Context, clientAccessInfo *clientaccess.Info) e // join attempts to add a member to an existing cluster func (e *ETCD) join(ctx context.Context, clientAccessInfo *clientaccess.Info) error { - clientURLs, memberList, err := ClientURLs(ctx, clientAccessInfo) + clientURLs, memberList, err := ClientURLs(ctx, clientAccessInfo, e.config.PrivateIP) if err != nil { return err } @@ -524,7 +524,7 @@ func (e *ETCD) cluster(ctx context.Context, forceNew bool, options executor.Init } // removePeer removes a peer from the cluster. The peer ID and IP address must both match. -func (e *ETCD) removePeer(ctx context.Context, id, address string) error { +func (e *ETCD) removePeer(ctx context.Context, id, address string, removeSelf bool) error { members, err := e.client.MemberList(ctx) if err != nil { return err @@ -540,7 +540,7 @@ func (e *ETCD) removePeer(ctx context.Context, id, address string) error { return err } if u.Hostname() == address { - if e.address == address { + if e.address == address && !removeSelf { return errors.New("node has been deleted from the cluster") } logrus.Infof("Removing name=%s id=%d address=%s from etcd", member.Name, member.ID, address) @@ -687,7 +687,7 @@ func (e *ETCD) setLearnerProgress(ctx context.Context, status *learnerProgress) } // clientURLs returns a list of all non-learner etcd cluster member client access URLs -func ClientURLs(ctx context.Context, clientAccessInfo *clientaccess.Info) ([]string, Members, error) { +func ClientURLs(ctx context.Context, clientAccessInfo *clientaccess.Info, selfIP string) ([]string, Members, error) { var memberList Members resp, err := clientaccess.Get("/db/info", clientAccessInfo) if err != nil { @@ -697,13 +697,22 @@ func ClientURLs(ctx context.Context, clientAccessInfo *clientaccess.Info) ([]str if err := json.Unmarshal(resp, &memberList); err != nil { return nil, memberList, err } - + ip, err := GetAdvertiseAddress(selfIP) + if err != nil { + return nil, memberList, err + } var clientURLs []string +members: for _, member := range memberList.Members { // excluding learner member from the client list if member.IsLearner { continue } + for _, url := range member.ClientURLs { + if strings.Contains(url, ip) { + continue members + } + } clientURLs = append(clientURLs, member.ClientURLs...) } return clientURLs, memberList, nil @@ -941,3 +950,8 @@ func (e *ETCD) GetMembersClientURLs(ctx context.Context) ([]string, error) { } return memberUrls, nil } + +// RemoveSelf will remove the member if it exists in the cluster +func (e *ETCD) RemoveSelf(ctx context.Context) error { + return e.removePeer(ctx, e.name, e.address, true) +}