mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
remove etcd member if disable etcd is passed
Signed-off-by: galal-hussein <hussein.galal.ahmed.11@gmail.com>
This commit is contained in:
parent
fad2a046c3
commit
d6124981d5
@ -267,8 +267,13 @@ func run(app *cli.Context, cfg *cmds.Server) error {
|
||||
}
|
||||
|
||||
go func() {
|
||||
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)
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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) {
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user