@@ -41,7 +41,7 @@ func (d *Driver) pullImage(imageName string) (containerd.Image, error) {
4141 return d .client .Pull (d .ctxContainerd , imageName , containerd .WithPullUnpack )
4242}
4343
44- func (d * Driver ) createContainer (image containerd.Image , containerName , containerSnapshotName , containerdRuntime , netnsPath string , env []string , config * TaskConfig ) (containerd.Container , error ) {
44+ func (d * Driver ) createContainer (image containerd.Image , containerName , containerSnapshotName , containerdRuntime , netnsPath , secretsDir , taskDir string , env []string , config * TaskConfig ) (containerd.Container , error ) {
4545 if config .Command == "" && len (config .Args ) > 0 {
4646 return nil , fmt .Errorf ("Command is empty. Cannot set --args without --command." )
4747 }
@@ -119,14 +119,22 @@ func (d *Driver) createContainer(image containerd.Image, containerName, containe
119119 return nil , fmt .Errorf ("Options cannot be empty for mount type: %s. You need to atleast pass rbind and ro." , mount .Type )
120120 }
121121
122- m := specs.Mount {}
123- m .Type = mount .Type
124- m .Destination = mount .Target
125- m .Source = mount .Source
126- m .Options = mount .Options
122+ m := buildMountpoint (mount .Type , mount .Target , mount .Source , mount .Options )
127123 mounts = append (mounts , m )
128124 }
129125
126+ // Setup "/secrets" (NOMAD_SECRETS_DIR) in the container.
127+ if secretsDir != "" {
128+ secretsMount := buildMountpoint ("bind" , "/secrets" , secretsDir , []string {"rbind" , "ro" })
129+ mounts = append (mounts , secretsMount )
130+ }
131+
132+ // Setup "/local" (NOMAD_TASK_DIR) in the container.
133+ if taskDir != "" {
134+ taskMount := buildMountpoint ("bind" , "/local" , taskDir , []string {"rbind" , "ro" })
135+ mounts = append (mounts , taskMount )
136+ }
137+
130138 if len (mounts ) > 0 {
131139 opts = append (opts , oci .WithMounts (mounts ))
132140 }
@@ -150,6 +158,16 @@ func (d *Driver) createContainer(image containerd.Image, containerName, containe
150158 )
151159}
152160
161+ // buildMountpoint builds the mount point for the container.
162+ func buildMountpoint (mountType , mountTarget , mountSource string , mountOptions []string ) specs.Mount {
163+ m := specs.Mount {}
164+ m .Type = mountType
165+ m .Destination = mountTarget
166+ m .Source = mountSource
167+ m .Options = mountOptions
168+ return m
169+ }
170+
153171func (d * Driver ) loadContainer (id string ) (containerd.Container , error ) {
154172 return d .client .LoadContainer (d .ctxContainerd , id )
155173}
0 commit comments