Skip to content

Commit b66475f

Browse files
committed
Make mount order predictable - fixes docker tests
1 parent 337cc6b commit b66475f

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

internal/services/executor/driver/docker.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ func (d *DockerDriver) NewPod(ctx context.Context, podConfig *PodConfig, out io.
249249
}
250250
}
251251

252+
sort.Sort(MountSlice(container.Mounts))
253+
252254
seenIndexes[cIndex] = struct{}{}
253255
count++
254256
}
@@ -468,7 +470,7 @@ func (d *DockerDriver) GetPods(ctx context.Context, all bool) ([]Pod, error) {
468470
}
469471
}
470472

471-
// overwrite containers with the right order
473+
sort.Sort(MountSlice(container.Mounts))
472474

473475
// add labels from the container with index 0
474476
if cIndex == 0 {
@@ -736,3 +738,11 @@ func makeEnvSlice(env map[string]string) []string {
736738

737739
return envList
738740
}
741+
742+
type MountSlice []dockertypes.MountPoint
743+
744+
func (p MountSlice) Len() int { return len(p) }
745+
func (p MountSlice) Less(i, j int) bool {
746+
return strings.Compare(p[i].Destination, p[j].Destination) < 0
747+
}
748+
func (p MountSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] }

internal/services/executor/driver/docker_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ package driver
1717
import (
1818
"bytes"
1919
"context"
20-
"io/ioutil"
20+
"io"
2121
"os"
2222
"testing"
2323
"time"
@@ -64,7 +64,7 @@ func TestDockerPod(t *testing.T) {
6464
},
6565
},
6666
InitVolumeDir: "/tmp/agola",
67-
}, ioutil.Discard)
67+
}, io.Discard)
6868
if err != nil {
6969
t.Fatalf("unexpected err: %v", err)
7070
}
@@ -82,7 +82,7 @@ func TestDockerPod(t *testing.T) {
8282
},
8383
},
8484
InitVolumeDir: "/tmp/agola",
85-
}, ioutil.Discard)
85+
}, io.Discard)
8686
if err != nil {
8787
t.Fatalf("unexpected err: %v", err)
8888
}
@@ -121,7 +121,7 @@ func TestDockerPod(t *testing.T) {
121121
},
122122
},
123123
InitVolumeDir: "/tmp/agola",
124-
}, ioutil.Discard)
124+
}, io.Discard)
125125
if err != nil {
126126
t.Fatalf("unexpected err: %v", err)
127127
}
@@ -175,7 +175,7 @@ func TestDockerPod(t *testing.T) {
175175
},
176176
},
177177
InitVolumeDir: "/tmp/agola",
178-
}, ioutil.Discard)
178+
}, io.Discard)
179179
if err != nil {
180180
t.Fatalf("unexpected err: %v", err)
181181
}
@@ -196,7 +196,7 @@ func TestDockerPod(t *testing.T) {
196196
},
197197
},
198198
InitVolumeDir: "/tmp/agola",
199-
}, ioutil.Discard)
199+
}, io.Discard)
200200
if err != nil {
201201
t.Fatalf("unexpected err: %v", err)
202202
}
@@ -232,7 +232,7 @@ func TestDockerPod(t *testing.T) {
232232
},
233233
},
234234
InitVolumeDir: "/tmp/agola",
235-
}, ioutil.Discard)
235+
}, io.Discard)
236236
if err != nil {
237237
t.Fatalf("unexpected err: %v", err)
238238
}
@@ -278,7 +278,7 @@ func TestDockerPod(t *testing.T) {
278278
},
279279
},
280280
InitVolumeDir: "/tmp/agola",
281-
}, ioutil.Discard)
281+
}, io.Discard)
282282
if err != nil {
283283
t.Fatalf("unexpected err: %v", err)
284284
}
@@ -324,7 +324,7 @@ func TestDockerPod(t *testing.T) {
324324
},
325325
},
326326
InitVolumeDir: "/tmp/agola",
327-
}, ioutil.Discard)
327+
}, io.Discard)
328328
if err != nil {
329329
t.Fatalf("unexpected err: %v", err)
330330
}
@@ -382,7 +382,7 @@ func TestDockerPod(t *testing.T) {
382382
},
383383
},
384384
InitVolumeDir: "/tmp/agola",
385-
}, ioutil.Discard)
385+
}, io.Discard)
386386
if err != nil {
387387
t.Fatalf("unexpected err: %v", err)
388388
}
@@ -421,7 +421,7 @@ func TestDockerPod(t *testing.T) {
421421
},
422422
},
423423
InitVolumeDir: "/tmp/agola",
424-
}, ioutil.Discard)
424+
}, io.Discard)
425425
if err != nil {
426426
t.Fatalf("unexpected err: %v", err)
427427
}
@@ -468,7 +468,7 @@ func TestDockerPod(t *testing.T) {
468468
},
469469
},
470470
InitVolumeDir: "/tmp/agola",
471-
}, ioutil.Discard)
471+
}, io.Discard)
472472
if err != nil {
473473
t.Fatalf("unexpected err: %v", err)
474474
}
@@ -513,7 +513,7 @@ func TestDockerPod(t *testing.T) {
513513
},
514514
},
515515
InitVolumeDir: "/tmp/agola",
516-
}, ioutil.Discard)
516+
}, io.Discard)
517517
if err != nil {
518518
t.Fatalf("unexpected err: %v", err)
519519
}

0 commit comments

Comments
 (0)