add configuration for CDI
Signed-off-by: Ed Bartosh <eduard.bartosh@intel.com>
This commit is contained in:
		| @@ -302,6 +302,13 @@ type PluginConfig struct { | ||||
| 	// and if it is not overwritten by PodSandboxConfig | ||||
| 	// Note that currently default is set to disabled but target change it in future together with EnableUnprivilegedPorts | ||||
| 	EnableUnprivilegedICMP bool `toml:"enable_unprivileged_icmp" json:"enableUnprivilegedICMP"` | ||||
| 	// EnableCDI indicates to enable injection of the Container Device Interface Specifications | ||||
| 	// into the OCI config | ||||
| 	// For more details about CDI and the syntax of CDI Spec files please refer to | ||||
| 	// https://github.com/container-orchestrated-devices/container-device-interface. | ||||
| 	EnableCDI bool `toml:"enable_cdi" json:"enableCDI"` | ||||
| 	// CDISpecDirs is the list of directories to scan for Container Device Interface Specifications | ||||
| 	CDISpecDirs []string `toml:"cdi_spec_dirs" json:"cdiSpecDirs"` | ||||
| } | ||||
|  | ||||
| // X509KeyPairStreaming contains the x509 configuration for streaming | ||||
|   | ||||
| @@ -104,5 +104,7 @@ func DefaultConfig() PluginConfig { | ||||
| 		ImageDecryption: ImageDecryption{ | ||||
| 			KeyModel: KeyModelNode, | ||||
| 		}, | ||||
| 		EnableCDI:   false, | ||||
| 		CDISpecDirs: []string{"/etc/cdi", "/var/run/cdi"}, | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -238,8 +238,12 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta | ||||
| 	if err != nil { | ||||
| 		return nil, fmt.Errorf("failed to get runtime options: %w", err) | ||||
| 	} | ||||
|  | ||||
| 	if c.config.EnableCDI { | ||||
| 		opts = append(opts, containerd.WithCDI(spec, config.Annotations, c.config.CDISpecDirs)) | ||||
| 	} | ||||
|  | ||||
| 	opts = append(opts, | ||||
| 		containerd.WithCDI(spec, config.Annotations), | ||||
| 		containerd.WithSpec(spec, specOpts...), | ||||
| 		containerd.WithRuntime(sandboxInfo.Runtime.Name, runtimeOptions), | ||||
| 		containerd.WithContainerLabels(containerLabels), | ||||
|   | ||||
| @@ -1507,7 +1507,7 @@ func writeFilesToTempDir(tmpDirPattern string, content []string) (string, error) | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	return dir, cdi.GetRegistry(cdi.WithSpecDirs(dir)).Refresh() | ||||
| 	return dir, nil | ||||
| } | ||||
|  | ||||
| func TestCDIInjections(t *testing.T) { | ||||
| @@ -1619,7 +1619,7 @@ containerEdits: | ||||
| 		} | ||||
| 		require.NoError(t, err) | ||||
|  | ||||
| 		injectFun := containerd.WithCDI(spec, test.annotations) | ||||
| 		injectFun := containerd.WithCDI(spec, test.annotations, []string{cdiDir}) | ||||
| 		err = injectFun(nil, nil, nil) | ||||
| 		assert.Equal(t, test.expectError, err != nil) | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Ed Bartosh
					Ed Bartosh