Docker Swarm程式碼分析筆記(16)——Node結構體

來源:互聯網
上載者:User
這是一個建立於 的文章,其中的資訊可能已經有所發展或是發生改變。

Docker Swarmscheduler會選擇符合要求的node來建立container

candidates, err := s.selectNodesForContainer(nodes, config, true)

node定義在scheduler/node/node.go

// Node is an abstract type used by the scheduler.type Node struct {    ID         string    IP         string    Addr       string    Name       string    Labels     map[string]string    Containers cluster.Containers    Images     []*cluster.Image    UsedMemory  int64    UsedCpus    int64    TotalMemory int64    TotalCpus   int64    HealthIndicator int64}

Cluster.listNodes方法實現如下:

// listNodes returns all validated engines in the cluster, excluding pendingEngines.func (c *Cluster) listNodes() []*node.Node {    c.RLock()    defer c.RUnlock()    out := make([]*node.Node, 0, len(c.engines))    for _, e := range c.engines {        node := node.NewNode(e)        for _, pc := range c.pendingContainers {            if pc.Engine.ID == e.ID && node.Container(pc.Config.SwarmID()) == nil {                node.AddContainer(pc.ToContainer())            }        }        out = append(out, node)    }    return out}

其實就是從Cluster.engines構建node列表(因為Cluster.pendingEngines還處在待定狀態)。後續scheduler就會從這個node列表中選擇合適的node

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.