本文整理汇总了Golang中github.com/docker/swarm/scheduler/node.AddContainer函数的典型用法代码示例。如果您正苦于以下问题:Golang AddContainer函数的具体用法?Golang AddContainer怎么用?Golang AddContainer使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了AddContainer函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestSpreadPlaceContainerHuge
func TestSpreadPlaceContainerHuge(t *testing.T) {
s := &SpreadPlacementStrategy{}
nodes := []*node.Node{}
for i := 0; i < 100; i++ {
nodes = append(nodes, createNode(fmt.Sprintf("node-%d", i), 1, 1))
}
// add 100 container 1CPU
for i := 0; i < 100; i++ {
node := selectTopNode(t, s, createConfig(0, 1), nodes)
assert.NoError(t, node.AddContainer(createContainer(fmt.Sprintf("c%d", i), createConfig(0, 1))))
}
// try to add another container 1CPU
_, err := s.RankAndSort(createConfig(0, 1), nodes)
assert.Error(t, err)
// add 100 container 1G
for i := 100; i < 200; i++ {
node := selectTopNode(t, s, createConfig(1, 0), nodes)
assert.NoError(t, node.AddContainer(createContainer(fmt.Sprintf("c%d", i), createConfig(1, 0))))
}
// try to add another container 1G
_, err = s.RankAndSort(createConfig(1, 0), nodes)
assert.Error(t, err)
}
示例2: TestSpreadPlaceEqualWeight
func TestSpreadPlaceEqualWeight(t *testing.T) {
s := &SpreadPlacementStrategy{}
nodes := []*node.Node{}
for i := 0; i < 2; i++ {
nodes = append(nodes, createNode(fmt.Sprintf("node-%d", i), 4, 0))
}
// add 1 container 2G on node1
config := createConfig(2, 0)
assert.NoError(t, nodes[0].AddContainer(createContainer("c1", config)))
assert.Equal(t, nodes[0].UsedMemory, int64(2*1024*1024*1024))
// add 2 containers 1G on node2
config = createConfig(1, 0)
assert.NoError(t, nodes[1].AddContainer(createContainer("c2", config)))
assert.NoError(t, nodes[1].AddContainer(createContainer("c3", config)))
assert.Equal(t, nodes[1].UsedMemory, int64(2*1024*1024*1024))
// add another container 1G
config = createConfig(1, 0)
node := selectTopNode(t, s, config, nodes)
assert.NoError(t, node.AddContainer(createContainer("c4", config)))
assert.Equal(t, node.UsedMemory, int64(3*1024*1024*1024))
// check that the last container ended on the node with the lowest number of containers
assert.Equal(t, node.ID, nodes[0].ID)
assert.Equal(t, len(nodes[0].Containers), len(nodes[1].Containers))
}
示例3: 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 _, c := range c.pendingContainers {
if c.Engine.ID == e.ID && node.Container(c.Config.SwarmID()) == nil {
node.AddContainer(c.ToContainer())
}
}
out = append(out, node)
}
return out
}
示例4: TestSpreadPlaceDifferentNodeSizeCPUs
func TestSpreadPlaceDifferentNodeSizeCPUs(t *testing.T) {
s := &SpreadPlacementStrategy{}
nodes := []*node.Node{
createNode(fmt.Sprintf("node-0"), 64, 21),
createNode(fmt.Sprintf("node-1"), 128, 42),
}
// add 60 containers 1CPU
for i := 0; i < 60; i++ {
config := createConfig(0, 1)
node := selectTopNode(t, s, config, nodes)
assert.NoError(t, node.AddContainer(createContainer(fmt.Sprintf("c%d", i), config)))
}
assert.Equal(t, len(nodes[0].Containers), 20)
assert.Equal(t, len(nodes[1].Containers), 40)
}