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() {
|
go func() {
|
||||||
<-serverConfig.ControlConfig.Runtime.APIServerReady
|
if !serverConfig.ControlConfig.DisableAPIServer {
|
||||||
logrus.Info("Kube API server is now running")
|
<-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")
|
logrus.Info(version.Program + " is up and running")
|
||||||
if notifySocket != "" {
|
if notifySocket != "" {
|
||||||
os.Setenv("NOTIFY_SOCKET", notifySocket)
|
os.Setenv("NOTIFY_SOCKET", notifySocket)
|
||||||
|
@ -41,7 +41,7 @@ func (c *Cluster) Start(ctx context.Context) (<-chan struct{}, error) {
|
|||||||
defer close(ready)
|
defer close(ready)
|
||||||
|
|
||||||
// try to get /db/info urls first before attempting to use join url
|
// 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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -58,6 +58,12 @@ func (c *Cluster) Start(ctx context.Context) (<-chan struct{}, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
c.setupEtcdProxy(ctx, etcdProxy)
|
c.setupEtcdProxy(ctx, etcdProxy)
|
||||||
|
|
||||||
|
// remove etcd member if it exists
|
||||||
|
if err := c.managedDB.RemoveSelf(ctx); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
return ready, nil
|
return ready, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ type Driver interface {
|
|||||||
EndpointName() string
|
EndpointName() string
|
||||||
Snapshot(ctx context.Context, config *config.Control) error
|
Snapshot(ctx context.Context, config *config.Control) error
|
||||||
GetMembersClientURLs(ctx context.Context) ([]string, error)
|
GetMembersClientURLs(ctx context.Context) ([]string, error)
|
||||||
|
RemoveSelf(ctx context.Context) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func RegisterDriver(d Driver) {
|
func RegisterDriver(d Driver) {
|
||||||
|
@ -87,5 +87,5 @@ func (h *handler) onRemove(key string, node *v1.Node) (*v1.Node, error) {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return node, nil
|
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
|
// join attempts to add a member to an existing cluster
|
||||||
func (e *ETCD) join(ctx context.Context, clientAccessInfo *clientaccess.Info) error {
|
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 {
|
if err != nil {
|
||||||
return err
|
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.
|
// 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)
|
members, err := e.client.MemberList(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -540,7 +540,7 @@ func (e *ETCD) removePeer(ctx context.Context, id, address string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if u.Hostname() == address {
|
if u.Hostname() == address {
|
||||||
if e.address == address {
|
if e.address == address && !removeSelf {
|
||||||
return errors.New("node has been deleted from the cluster")
|
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)
|
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
|
// 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
|
var memberList Members
|
||||||
resp, err := clientaccess.Get("/db/info", clientAccessInfo)
|
resp, err := clientaccess.Get("/db/info", clientAccessInfo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -697,13 +697,22 @@ func ClientURLs(ctx context.Context, clientAccessInfo *clientaccess.Info) ([]str
|
|||||||
if err := json.Unmarshal(resp, &memberList); err != nil {
|
if err := json.Unmarshal(resp, &memberList); err != nil {
|
||||||
return nil, memberList, err
|
return nil, memberList, err
|
||||||
}
|
}
|
||||||
|
ip, err := GetAdvertiseAddress(selfIP)
|
||||||
|
if err != nil {
|
||||||
|
return nil, memberList, err
|
||||||
|
}
|
||||||
var clientURLs []string
|
var clientURLs []string
|
||||||
|
members:
|
||||||
for _, member := range memberList.Members {
|
for _, member := range memberList.Members {
|
||||||
// excluding learner member from the client list
|
// excluding learner member from the client list
|
||||||
if member.IsLearner {
|
if member.IsLearner {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
for _, url := range member.ClientURLs {
|
||||||
|
if strings.Contains(url, ip) {
|
||||||
|
continue members
|
||||||
|
}
|
||||||
|
}
|
||||||
clientURLs = append(clientURLs, member.ClientURLs...)
|
clientURLs = append(clientURLs, member.ClientURLs...)
|
||||||
}
|
}
|
||||||
return clientURLs, memberList, nil
|
return clientURLs, memberList, nil
|
||||||
@ -941,3 +950,8 @@ func (e *ETCD) GetMembersClientURLs(ctx context.Context) ([]string, error) {
|
|||||||
}
|
}
|
||||||
return memberUrls, nil
|
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