-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreschdule
66 lines (50 loc) · 2.27 KB
/
reschdule
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
@test "docker run - reschedule with soft-image-affinity" {
start_docker_with_busybox 1
start_docker 1
docker -H ${HOSTS[0]} tag busybox:latest busyboxabcde:latest
swarm_manage
// make sure busyboxabcde exists
run docker_swarm images
[ "$status" -eq 0 ]
[[ "${output}" == *"busyboxabcde"* ]]
// try to create container on node-1 does not have busyboxabcde and will pull it
// but can not find busyboxabcde in dockerhub
// then will retry with soft-image-affinity
docker_swarm run -d -e --name test_container constraint:node==~node-1 busyboxabcde sleep 1000
// check container
run docker_swarm ps
[[ "${output}" == *"node-0/test_container"* ]]
}
// AddSoftImageAffinity
func (c *ContainerConfig) AddSoftImageAffinity(image string) error {
affnities_json := c.Labels[SwarmLabelNamespace+".affinities"]
var affinities []string
json.Unmarshal([]byte(affnities_json), &affinities)
affinities = append(affinities, "image==~"+image)
labels, err := json.Marshal(affinities)
if err != nil {
return err
}
c.Labels[SwarmLabelNamespace+".affinities"] = string(labels)
return nil
}
func TestAddSoftImageAffinity(t *testing.T) {
config := BuildContainerConfig(dockerclient.ContainerConfig{})
assert.Empty(t, config.Affinities())
AddSoftImageAffinity("testimage")
assert.Len(t, config.Affinities(), 1)
}
container, err := c.createContainer(config, name, false)
if err != nil && strings.HasSuffix(err.Error(), "not found") {
// check if the image exists in the cluster
if image := c.Image(config.Image); image != nil{
log.Info("Reschduler Flow")
container, err = c.createContainer(config, name, true)
}
}
return container, err
0.30s$ fgt golint ./...
cluster/config.go:150:1: comment on exported method ContainerConfig.AddSoftImageAffinity should be of the form "AddSoftImageAffinity ..."
cluster/config.go:152:2: don't use underscores in Go names; var affnities_json should be affnitiesJSON
cluster/swarm/cluster.go:105:81: don't use underscores in Go names; method parameter with_soft_image_affinity should be withSoftImageAffinity
cluster/swarm/cluster.go:117:2: don't use underscores in Go names; var config_temp should be configTemp