@@ -42,7 +42,7 @@ func getUserSpec(user, rootfsPath string) (specs.User, error) {
42
42
}, nil
43
43
}
44
44
45
- func (w * containerdExecutor ) prepareExecutionEnv (ctx context.Context , rootMount executor.Mount , mounts []executor.Mount , meta executor.Meta , details * jobDetails ) (func () , string , string , error ) {
45
+ func (w * containerdExecutor ) prepareExecutionEnv (ctx context.Context , rootMount executor.Mount , mounts []executor.Mount , meta executor.Meta , details * containerState ) (string , string , func () , error ) {
46
46
var releasers []func ()
47
47
releaseAll := func () {
48
48
for i := len (releasers ) - 1 ; i >= 0 ; i -- {
@@ -52,24 +52,28 @@ func (w *containerdExecutor) prepareExecutionEnv(ctx context.Context, rootMount
52
52
53
53
resolvConf , err := oci .GetResolvConf (ctx , w .root , nil , w .dnsConfig )
54
54
if err != nil {
55
- return releaseAll , "" , "" , err
55
+ releaseAll ()
56
+ return "" , "" , nil , err
56
57
}
57
58
58
59
hostsFile , clean , err := oci .GetHostsFile (ctx , w .root , meta .ExtraHosts , nil , meta .Hostname )
59
60
if err != nil {
60
- return releaseAll , "" , "" , err
61
+ releaseAll ()
62
+ return "" , "" , nil , err
61
63
}
62
64
if clean != nil {
63
65
releasers = append (releasers , clean )
64
66
}
65
67
mountable , err := rootMount .Src .Mount (ctx , false )
66
68
if err != nil {
67
- return releaseAll , "" , "" , err
69
+ releaseAll ()
70
+ return "" , "" , nil , err
68
71
}
69
72
70
73
rootMounts , release , err := mountable .Mount ()
71
74
if err != nil {
72
- return releaseAll , "" , "" , err
75
+ releaseAll ()
76
+ return "" , "" , nil , err
73
77
}
74
78
details .rootMounts = rootMounts
75
79
@@ -83,7 +87,8 @@ func (w *containerdExecutor) prepareExecutionEnv(ctx context.Context, rootMount
83
87
lm := snapshot .LocalMounterWithMounts (rootMounts )
84
88
rootfsPath , err := lm .Mount ()
85
89
if err != nil {
86
- return releaseAll , "" , "" , err
90
+ releaseAll ()
91
+ return "" , "" , nil , err
87
92
}
88
93
details .rootfsPath = rootfsPath
89
94
releasers = append (releasers , func () {
@@ -93,26 +98,10 @@ func (w *containerdExecutor) prepareExecutionEnv(ctx context.Context, rootMount
93
98
})
94
99
releasers = append (releasers , executor .MountStubsCleaner (ctx , details .rootfsPath , mounts , meta .RemoveMountStubsRecursive ))
95
100
96
- return releaseAll , resolvConf , hostsFile , nil
101
+ return resolvConf , hostsFile , releaseAll , nil
97
102
}
98
103
99
- func (w * containerdExecutor ) getTaskOpts (ctx context.Context , details * jobDetails ) (containerd.NewTaskOpts , error ) {
100
- rootfs := containerd .WithRootFS ([]mount.Mount {{
101
- Source : details .rootfsPath ,
102
- Type : "bind" ,
103
- Options : []string {"rbind" },
104
- }})
105
- if runtime .GOOS == "freebsd" {
106
- rootfs = containerd .WithRootFS ([]mount.Mount {{
107
- Source : details .rootfsPath ,
108
- Type : "nullfs" ,
109
- Options : []string {},
110
- }})
111
- }
112
- return rootfs , nil
113
- }
114
-
115
- func (w * containerdExecutor ) ensureCWD (ctx context.Context , details * jobDetails , meta executor.Meta ) error {
104
+ func (w * containerdExecutor ) ensureCWD (ctx context.Context , details * containerState , meta executor.Meta ) error {
116
105
newp , err := fs .RootPath (details .rootfsPath , meta .Cwd )
117
106
if err != nil {
118
107
return errors .Wrapf (err , "working dir %s points to invalid target" , newp )
@@ -136,7 +125,7 @@ func (w *containerdExecutor) ensureCWD(ctx context.Context, details *jobDetails,
136
125
return nil
137
126
}
138
127
139
- func (w * containerdExecutor ) getOCISpec (ctx context.Context , id , resolvConf , hostsFile string , namespace network.Namespace , mounts []executor.Mount , meta executor.Meta , details * jobDetails ) (* specs.Spec , func (), error ) {
128
+ func (w * containerdExecutor ) createOCISpec (ctx context.Context , id , resolvConf , hostsFile string , namespace network.Namespace , mounts []executor.Mount , meta executor.Meta , details * containerState ) (* specs.Spec , func (), error ) {
140
129
var releasers []func ()
141
130
releaseAll := func () {
142
131
for i := len (releasers ) - 1 ; i >= 0 ; i -- {
@@ -146,7 +135,8 @@ func (w *containerdExecutor) getOCISpec(ctx context.Context, id, resolvConf, hos
146
135
147
136
uid , gid , sgids , err := oci .GetUser (details .rootfsPath , meta .User )
148
137
if err != nil {
149
- return nil , releaseAll , err
138
+ releaseAll ()
139
+ return nil , nil , err
150
140
}
151
141
152
142
opts := []containerdoci.SpecOpts {oci .WithUIDGID (uid , gid , sgids )}
@@ -157,14 +147,36 @@ func (w *containerdExecutor) getOCISpec(ctx context.Context, id, resolvConf, hos
157
147
processMode := oci .ProcessSandbox // FIXME(AkihiroSuda)
158
148
spec , cleanup , err := oci .GenerateSpec (ctx , meta , mounts , id , resolvConf , hostsFile , namespace , w .cgroupParent , processMode , nil , w .apparmorProfile , w .selinux , w .traceSocket , opts ... )
159
149
if err != nil {
160
- return nil , releaseAll , err
150
+ releaseAll ()
151
+ return nil , nil , err
161
152
}
162
153
releasers = append (releasers , cleanup )
163
154
spec .Process .Terminal = meta .Tty
164
155
if w .rootless {
165
156
if err := rootlessspecconv .ToRootless (spec ); err != nil {
166
- return nil , releaseAll , err
157
+ releaseAll ()
158
+ return nil , nil , err
167
159
}
168
160
}
169
161
return spec , releaseAll , nil
170
162
}
163
+
164
+ func (d * containerState ) getTaskOpts () (containerd.NewTaskOpts , error ) {
165
+ rootfs := containerd .WithRootFS ([]mount.Mount {{
166
+ Source : d .rootfsPath ,
167
+ Type : "bind" ,
168
+ Options : []string {"rbind" },
169
+ }})
170
+ if runtime .GOOS == "freebsd" {
171
+ rootfs = containerd .WithRootFS ([]mount.Mount {{
172
+ Source : d .rootfsPath ,
173
+ Type : "nullfs" ,
174
+ Options : []string {},
175
+ }})
176
+ }
177
+ return rootfs , nil
178
+ }
179
+
180
+ func setArgs (spec * specs.Process , args []string ) {
181
+ spec .Args = args
182
+ }
0 commit comments