@@ -42,7 +42,7 @@ func getUserSpec(user, rootfsPath string) (specs.User, error) {
4242 }, nil
4343}
4444
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 ) {
4646 var releasers []func ()
4747 releaseAll := func () {
4848 for i := len (releasers ) - 1 ; i >= 0 ; i -- {
@@ -52,24 +52,28 @@ func (w *containerdExecutor) prepareExecutionEnv(ctx context.Context, rootMount
5252
5353 resolvConf , err := oci .GetResolvConf (ctx , w .root , nil , w .dnsConfig )
5454 if err != nil {
55- return releaseAll , "" , "" , err
55+ releaseAll ()
56+ return "" , "" , nil , err
5657 }
5758
5859 hostsFile , clean , err := oci .GetHostsFile (ctx , w .root , meta .ExtraHosts , nil , meta .Hostname )
5960 if err != nil {
60- return releaseAll , "" , "" , err
61+ releaseAll ()
62+ return "" , "" , nil , err
6163 }
6264 if clean != nil {
6365 releasers = append (releasers , clean )
6466 }
6567 mountable , err := rootMount .Src .Mount (ctx , false )
6668 if err != nil {
67- return releaseAll , "" , "" , err
69+ releaseAll ()
70+ return "" , "" , nil , err
6871 }
6972
7073 rootMounts , release , err := mountable .Mount ()
7174 if err != nil {
72- return releaseAll , "" , "" , err
75+ releaseAll ()
76+ return "" , "" , nil , err
7377 }
7478 details .rootMounts = rootMounts
7579
@@ -83,7 +87,8 @@ func (w *containerdExecutor) prepareExecutionEnv(ctx context.Context, rootMount
8387 lm := snapshot .LocalMounterWithMounts (rootMounts )
8488 rootfsPath , err := lm .Mount ()
8589 if err != nil {
86- return releaseAll , "" , "" , err
90+ releaseAll ()
91+ return "" , "" , nil , err
8792 }
8893 details .rootfsPath = rootfsPath
8994 releasers = append (releasers , func () {
@@ -93,26 +98,10 @@ func (w *containerdExecutor) prepareExecutionEnv(ctx context.Context, rootMount
9398 })
9499 releasers = append (releasers , executor .MountStubsCleaner (ctx , details .rootfsPath , mounts , meta .RemoveMountStubsRecursive ))
95100
96- return releaseAll , resolvConf , hostsFile , nil
101+ return resolvConf , hostsFile , releaseAll , nil
97102}
98103
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 {
116105 newp , err := fs .RootPath (details .rootfsPath , meta .Cwd )
117106 if err != nil {
118107 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,
136125 return nil
137126}
138127
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 ) {
140129 var releasers []func ()
141130 releaseAll := func () {
142131 for i := len (releasers ) - 1 ; i >= 0 ; i -- {
@@ -146,7 +135,8 @@ func (w *containerdExecutor) getOCISpec(ctx context.Context, id, resolvConf, hos
146135
147136 uid , gid , sgids , err := oci .GetUser (details .rootfsPath , meta .User )
148137 if err != nil {
149- return nil , releaseAll , err
138+ releaseAll ()
139+ return nil , nil , err
150140 }
151141
152142 opts := []containerdoci.SpecOpts {oci .WithUIDGID (uid , gid , sgids )}
@@ -157,14 +147,36 @@ func (w *containerdExecutor) getOCISpec(ctx context.Context, id, resolvConf, hos
157147 processMode := oci .ProcessSandbox // FIXME(AkihiroSuda)
158148 spec , cleanup , err := oci .GenerateSpec (ctx , meta , mounts , id , resolvConf , hostsFile , namespace , w .cgroupParent , processMode , nil , w .apparmorProfile , w .selinux , w .traceSocket , opts ... )
159149 if err != nil {
160- return nil , releaseAll , err
150+ releaseAll ()
151+ return nil , nil , err
161152 }
162153 releasers = append (releasers , cleanup )
163154 spec .Process .Terminal = meta .Tty
164155 if w .rootless {
165156 if err := rootlessspecconv .ToRootless (spec ); err != nil {
166- return nil , releaseAll , err
157+ releaseAll ()
158+ return nil , nil , err
167159 }
168160 }
169161 return spec , releaseAll , nil
170162}
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