@@ -3,8 +3,10 @@ package main
3
3
import (
4
4
"context"
5
5
"fmt"
6
+ "io/ioutil"
6
7
"os"
7
8
"os/signal"
9
+ "strings"
8
10
"syscall"
9
11
10
12
docker "github.com/fsouza/go-dockerclient"
@@ -31,12 +33,27 @@ func runOperator() int {
31
33
pflag .StringArrayVar (& containerBinds , "binds" , []string {}, "the directories to bind in the container" )
32
34
pflag .Parse ()
33
35
36
+ filteredBinds := make ([]string , 0 , len (containerBinds ))
37
+ for _ , bind := range containerBinds {
38
+ if bind != "" {
39
+ filteredBinds = append (filteredBinds , bind )
40
+ }
41
+ }
42
+
34
43
args , err := shellquote .Split (containerArgs )
35
44
if err != nil {
36
45
fmt .Println (errors .Wrap (err , "invalid arguments given" ))
37
46
return 42
38
47
}
39
48
49
+ data , err := ioutil .ReadFile ("/proc/self/cpuset" )
50
+ if err != nil {
51
+ fmt .Println (errors .Wrap (err , "cannot read cgroup file" ))
52
+ return 42
53
+ }
54
+ parts := strings .Split (string (data ), "/" )
55
+ selfID := strings .TrimSpace (parts [len (parts )- 1 ])
56
+
40
57
client , err := docker .NewClientFromEnv ()
41
58
if err != nil {
42
59
fmt .Println (errors .Wrap (err , "cannot create client" ))
@@ -78,18 +95,19 @@ func runOperator() int {
78
95
container , err := client .CreateContainer (docker.CreateContainerOptions {
79
96
Name : containerName ,
80
97
Config : & docker.Config {
81
- Cmd : args ,
82
- Hostname : containerName ,
83
- Image : imageName ,
98
+ Cmd : args ,
99
+ Image : imageName ,
84
100
Labels : map [string ]string {
85
101
"com.sourcelair.swarm-dind-operator" : "true" ,
86
102
"com.sourcelair.swarm-dind-operator.name" : containerName ,
87
103
},
88
104
StopTimeout : containerStopTimeout ,
89
105
},
90
106
HostConfig : & docker.HostConfig {
91
- Privileged : true ,
92
- Binds : containerBinds ,
107
+ Privileged : true ,
108
+ Binds : filteredBinds ,
109
+ NetworkMode : fmt .Sprintf ("container:%s" , selfID ),
110
+ PidMode : fmt .Sprintf ("container:%s" , selfID ),
93
111
},
94
112
})
95
113
if err != nil {
0 commit comments