@@ -179,26 +179,33 @@ func getOverlayUpperAndWorkDir(options []string) (string, string, error) {
179
179
}
180
180
181
181
// Internal only function which creates the Rootfs for default internal
182
- // pause image, configures the Rootfs in the Container and returns
183
- // the mount-point for the /catatonit. This mount-point should be added
184
- // to the Container spec.
185
- func (c * Container ) prepareInitRootfs () (spec.Mount , error ) {
186
- newMount := spec.Mount {
187
- Type : define .TypeBind ,
188
- Source : "" ,
189
- Destination : "" ,
190
- Options : append (bindOptions , "ro" , "nosuid" , "nodev" ),
191
- }
192
-
182
+ // pause image and configures the Rootfs in the Container.
183
+ func (c * Container ) createInitRootfs () error {
193
184
tmpDir , err := c .runtime .TmpDir ()
194
185
if err != nil {
195
- return newMount , fmt .Errorf ("getting runtime temporary directory: %w" , err )
186
+ return fmt .Errorf ("getting runtime temporary directory: %w" , err )
196
187
}
197
188
tmpDir = filepath .Join (tmpDir , "infra-container" )
198
189
err = os .MkdirAll (tmpDir , 0755 )
199
190
if err != nil {
200
- return newMount , fmt .Errorf ("creating infra container temporary directory: %w" , err )
191
+ return fmt .Errorf ("creating infra container temporary directory: %w" , err )
192
+ }
193
+
194
+ c .config .Rootfs = tmpDir
195
+ c .config .RootfsOverlay = true
196
+ return nil
197
+ }
198
+
199
+ // Internal only function which returns the mount-point for the /catatonit.
200
+ // This mount-point should be added to the Container spec.
201
+ func (c * Container ) prepareCatatonitMount () (spec.Mount , error ) {
202
+ newMount := spec.Mount {
203
+ Type : define .TypeBind ,
204
+ Source : "" ,
205
+ Destination : "" ,
206
+ Options : append (bindOptions , "ro" , "nosuid" , "nodev" ),
201
207
}
208
+
202
209
// Also look into the path as some distributions install catatonit in
203
210
// /usr/bin.
204
211
catatonitPath , err := c .runtime .config .FindInitBinary ()
@@ -213,8 +220,6 @@ func (c *Container) prepareInitRootfs() (spec.Mount, error) {
213
220
newMount .Source = catatonitPath
214
221
newMount .Destination = "/" + filepath .Base (catatonitPath )
215
222
216
- c .config .Rootfs = tmpDir
217
- c .config .RootfsOverlay = true
218
223
if len (c .config .Entrypoint ) == 0 {
219
224
c .config .Entrypoint = []string {"/" + filepath .Base (catatonitPath ), "-P" }
220
225
c .config .Spec .Process .Args = c .config .Entrypoint
@@ -426,7 +431,7 @@ func (c *Container) generateSpec(ctx context.Context) (s *spec.Spec, cleanupFunc
426
431
c .setMountLabel (& g )
427
432
428
433
if c .IsDefaultInfra () || c .IsService () {
429
- newMount , err := c .prepareInitRootfs ()
434
+ newMount , err := c .prepareCatatonitMount ()
430
435
if err != nil {
431
436
return nil , nil , err
432
437
}
0 commit comments