add parameter to allow the setting of running user for container (#120)

* add parameter to allow the setting of running user for container
* use task level user param as source param
This commit is contained in:
n-marton 2022-01-14 00:21:27 +01:00 committed by GitHub
parent e2430d9373
commit c08ed981d7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 0 deletions

View File

@ -49,6 +49,7 @@ type ContainerConfig struct {
MemoryLimit int64 MemoryLimit int64
MemoryHardLimit int64 MemoryHardLimit int64
CPUShares int64 CPUShares int64
User string
} }
func (d *Driver) isContainerdRunning() (bool, error) { func (d *Driver) isContainerdRunning() (bool, error) {
@ -321,6 +322,10 @@ func (d *Driver) createContainer(containerConfig *ContainerConfig, config *TaskC
opts = append(opts, oci.WithLinuxNamespace(specs.LinuxNamespace{Type: specs.NetworkNamespace, Path: containerConfig.NetworkNamespacePath})) opts = append(opts, oci.WithLinuxNamespace(specs.LinuxNamespace{Type: specs.NetworkNamespace, Path: containerConfig.NetworkNamespacePath}))
} }
if containerConfig.User != "" {
opts = append(opts, oci.WithUser(containerConfig.User))
}
ctxWithTimeout, cancel := context.WithTimeout(d.ctxContainerd, 30*time.Second) ctxWithTimeout, cancel := context.WithTimeout(d.ctxContainerd, 30*time.Second)
defer cancel() defer cancel()

View File

@ -469,6 +469,8 @@ func (d *Driver) StartTask(cfg *drivers.TaskConfig) (*drivers.TaskHandle, *drive
containerConfig.MemoryHardLimit = cfg.Resources.NomadResources.Memory.MemoryMaxMB * 1024 * 1024 containerConfig.MemoryHardLimit = cfg.Resources.NomadResources.Memory.MemoryMaxMB * 1024 * 1024
containerConfig.CPUShares = cfg.Resources.LinuxResources.CPUShares containerConfig.CPUShares = cfg.Resources.LinuxResources.CPUShares
containerConfig.User = cfg.User
container, err := d.createContainer(&containerConfig, &driverConfig) container, err := d.createContainer(&containerConfig, &driverConfig)
if err != nil { if err != nil {
return nil, nil, fmt.Errorf("Error in creating container: %v", err) return nil, nil, fmt.Errorf("Error in creating container: %v", err)