func (pdev podDevices) deviceRunContainerOptions(podUID, contName string) *DeviceRunContainerOptions {
	containers, exists := pdev[podUID]
	if !exists {
		return nil
	}
	resources, exists := containers[contName]
	if !exists {
		return nil
	}
	opts := &DeviceRunContainerOptions{}
	// Maps to detect duplicate settings.
	devsMap := make(map[string]string)
	mountsMap := make(map[string]string)
	envsMap := make(map[string]string)
	annotationsMap := make(map[string]string)
	// Loops through AllocationResponses of all cached device resources.
	for _, devices := range resources {
		resp := devices.allocResp
		// Each Allocate response has the following artifacts.
		// Environment variables
		// Mount points
		// Device files
		// Container annotations
		// These artifacts are per resource per container.
		// Updates RunContainerOptions.Envs.
		for k, v := range resp.Envs {
			if e, ok := envsMap[k]; ok {
				klog.V(4).Infof("Skip existing env %s %s", k, v)
				if e != v {
					klog.Errorf("Environment variable %s has conflicting setting: %s and %s", k, e, v)
				}
				continue
			}
			klog.V(4).Infof("Add env %s %s", k, v)
			envsMap[k] = v
			opts.Envs = append(opts.Envs, kubecontainer.EnvVar{Name: k, Value: v})
		}

		// Updates RunContainerOptions.Devices.
		for _, dev := range resp.Devices {
			if d, ok := devsMap[dev.ContainerPath]; ok {
				klog.V(4).Infof("Skip existing device %s %s", dev.ContainerPath, dev.HostPath)
				if d != dev.HostPath {
					klog.Errorf("Container device %s has conflicting mapping host devices: %s and %s",
						dev.ContainerPath, d, dev.HostPath)
				}
				continue
			}
			klog.V(4).Infof("Add device %s %s", dev.ContainerPath, dev.HostPath)
			devsMap[dev.ContainerPath] = dev.HostPath
			opts.Devices = append(opts.Devices, kubecontainer.DeviceInfo{
				PathOnHost:      dev.HostPath,
				PathInContainer: dev.ContainerPath,
				Permissions:     dev.Permissions,
			})
		}

		// Updates RunContainerOptions.Mounts.
		for _, mount := range resp.Mounts {
			if m, ok := mountsMap[mount.ContainerPath]; ok {
				klog.V(4).Infof("Skip existing mount %s %s", mount.ContainerPath, mount.HostPath)
				if m != mount.HostPath {
					klog.Errorf("Container mount %s has conflicting mapping host mounts: %s and %s",
						mount.ContainerPath, m, mount.HostPath)
				}
				continue
			}
			klog.V(4).Infof("Add mount %s %s", mount.ContainerPath, mount.HostPath)
			mountsMap[mount.ContainerPath] = mount.HostPath
			opts.Mounts = append(opts.Mounts, kubecontainer.Mount{
				Name:          mount.ContainerPath,
				ContainerPath: mount.ContainerPath,
				HostPath:      mount.HostPath,
				ReadOnly:      mount.ReadOnly,
				// TODO: This may need to be part of Device plugin API.
				SELinuxRelabel: false,
			})
		}

		// Updates for Annotations
		for k, v := range resp.Annotations {
			if e, ok := annotationsMap[k]; ok {
				klog.V(4).Infof("Skip existing annotation %s %s", k, v)
				if e != v {
					klog.Errorf("Annotation %s has conflicting setting: %s and %s", k, e, v)
				}
				continue
			}
			klog.V(4).Infof("Add annotation %s %s", k, v)
			annotationsMap[k] = v
			opts.Annotations = append(opts.Annotations, kubecontainer.Annotation{Name: k, Value: v})
		}
	}
	return opts
}
// Returns combined container runtime settings to consume the container's allocated devices.
Returns combined container runtime settings to consume the container's allocated devices.
// Returns combined container runtime settings to consume the container ' s allocated devices .
func (pdev podDevices) deviceRunContainerOptions(podUID, contName string) *DeviceRunContainerOptions {
	containers, exists := pdev[podUID]
	if !exists {
		return nil
	}
	resources, exists := containers[contName]
	if !exists {
		return nil
	}
	opts := &DeviceRunContainerOptions{}
	devsMap := make(map[string]string)
	mountsMap := make(map[string]string)
	envsMap := make(map[string]string)
	annotationsMap := make(map[string]string)
	for _, devices := range resources {
		resp := devices.allocResp
		for k, v := range resp.Envs {
			if e, ok := envsMap[k]; ok {
				klog.V(4).Infof("Skip existing env %s %s", k, v)
				if e != v {
					klog.Errorf("Environment variable %s has conflicting setting: %s and %s", k, e, v)
				}
				continue
			}
			klog.V(4).Infof("Add env %s %s", k, v)
			envsMap[k] = v
			opts.Envs = append(opts.Envs, kubecontainer.EnvVar{Name: k, Value: v})
		}
		for _, dev := range resp.Devices {
			if d, ok := devsMap[dev.ContainerPath]; ok {
				klog.V(4).Infof("Skip existing device %s %s", dev.ContainerPath, dev.HostPath)
				if d != dev.HostPath {
					klog.Errorf("Container device %s has conflicting mapping host devices: %s and %s",
						dev.ContainerPath, d, dev.HostPath)
				}
				continue
			}
			klog.V(4).Infof("Add device %s %s", dev.ContainerPath, dev.HostPath)
			devsMap[dev.ContainerPath] = dev.HostPath
			opts.Devices = append(opts.Devices, kubecontainer.DeviceInfo{
				PathOnHost:      dev.HostPath,
				PathInContainer: dev.ContainerPath,
				Permissions:     dev.Permissions,
			})
		}
		for _, mount := range resp.Mounts {
			if m, ok := mountsMap[mount.ContainerPath]; ok {
				klog.V(4).Infof("Skip existing mount %s %s", mount.ContainerPath, mount.HostPath)
				if m != mount.HostPath {
					klog.Errorf("Container mount %s has conflicting mapping host mounts: %s and %s",
						mount.ContainerPath, m, mount.HostPath)
				}
				continue
			}
			klog.V(4).Infof("Add mount %s %s", mount.ContainerPath, mount.HostPath)
			mountsMap[mount.ContainerPath] = mount.HostPath
			opts.Mounts = append(opts.Mounts, kubecontainer.Mount{
				Name:          mount.ContainerPath,
				ContainerPath: mount.ContainerPath,
				HostPath:      mount.HostPath,
				ReadOnly:      mount.ReadOnly,
				SELinuxRelabel: false,
			})
		}
		for k, v := range resp.Annotations {
			if e, ok := annotationsMap[k]; ok {
				klog.V(4).Infof("Skip existing annotation %s %s", k, v)
				if e != v {
					klog.Errorf("Annotation %s has conflicting setting: %s and %s", k, e, v)
				}
				continue
			}
			klog.V(4).Infof("Add annotation %s %s", k, v)
			annotationsMap[k] = v
			opts.Annotations = append(opts.Annotations, kubecontainer.Annotation{Name: k, Value: v})
		}
	}
	return opts
}
func ( pdev podDevices ) deviceRunContainerOptions ( podUID , contName string ) * DeviceRunContainerOptions { containers , exists := pdev [ podUID ] if ! exists { return nil } resources , exists := containers [ contName ] if ! exists { return nil } opts := & DeviceRunContainerOptions { } devsMap := make ( map [ string ] string ) mountsMap := make ( map [ string ] string ) envsMap := make ( map [ string ] string ) annotationsMap := make ( map [ string ] string ) for _ , devices := range resources { resp := devices . allocResp for k , v := range resp . Envs { if e , ok := envsMap [ k ] ; ok { klog . V ( 4 ) . Infof ( " " , k , v ) if e != v { klog . Errorf ( " " , k , e , v ) } continue } klog . V ( 4 ) . Infof ( " " , k , v ) envsMap [ k ] = v opts . Envs = append ( opts . Envs , kubecontainer . EnvVar { Name : k , Value : v } ) } for _ , dev := range resp . Devices { if d , ok := devsMap [ dev . ContainerPath ] ; ok { klog . V ( 4 ) . Infof ( " " , dev . ContainerPath , dev . HostPath ) if d != dev . HostPath { klog . Errorf ( " " , dev . ContainerPath , d , dev . HostPath ) } continue } klog . V ( 4 ) . Infof ( " " , dev . ContainerPath , dev . HostPath ) devsMap [ dev . ContainerPath ] = dev . HostPath opts . Devices = append ( opts . Devices , kubecontainer . DeviceInfo { PathOnHost : dev . HostPath , PathInContainer : dev . ContainerPath , Permissions : dev . Permissions , } ) } for _ , mount := range resp . Mounts { if m , ok := mountsMap [ mount . ContainerPath ] ; ok { klog . V ( 4 ) . Infof ( " " , mount . ContainerPath , mount . HostPath ) if m != mount . HostPath { klog . Errorf ( " " , mount . ContainerPath , m , mount . HostPath ) } continue } klog . V ( 4 ) . Infof ( " " , mount . ContainerPath , mount . HostPath ) mountsMap [ mount . ContainerPath ] = mount . HostPath opts . Mounts = append ( opts . Mounts , kubecontainer . Mount { Name : mount . ContainerPath , ContainerPath : mount . ContainerPath , HostPath : mount . HostPath , ReadOnly : mount . ReadOnly , SELinuxRelabel : false , } ) } for k , v := range resp . Annotations { if e , ok := annotationsMap [ k ] ; ok { klog . V ( 4 ) . Infof ( " " , k , v ) if e != v { klog . Errorf ( " " , k , e , v ) } continue } klog . V ( 4 ) . Infof ( " " , k , v ) annotationsMap [ k ] = v opts . Annotations = append ( opts . Annotations , kubecontainer . Annotation { Name : k , Value : v } ) } } return opts }
Returns combined container runtime settings to consume the container's allocated devices.
Returns combined container runtime settings to consume the container ' s allocated devices .
// Maps to detect duplicate settings. // Loops through AllocationResponses of all cached device resources. // Each Allocate response has the following artifacts. // Environment variables // Mount points // Device files // Container annotations // These artifacts are per resource per container. // Updates RunContainerOptions.Envs. // Updates RunContainerOptions.Devices. // Updates RunContainerOptions.Mounts. // TODO: This may need to be part of Device plugin API. // Updates for Annotations