update taskOptions based on runtimeOptions when creating a task

Signed-off-by: Iceber Gu <caiwei95@hotmail.com>
This commit is contained in:
Iceber Gu
2025-03-19 16:10:33 +08:00
committed by k8s-infra-cherrypick-robot
parent c146996f3f
commit a183b2d232
4 changed files with 54 additions and 52 deletions

View File

@@ -146,6 +146,11 @@ type TaskInfo struct {
// runtime is the runtime name for the container, and cannot be changed.
runtime string
// runtimeOptions is the runtime options for the container, and when task options are set,
// they will be based on the runtimeOptions.
// https://github.com/containerd/containerd/issues/11568
runtimeOptions typeurl.Any
}
// Runtime name for the container
@@ -153,6 +158,29 @@ func (i *TaskInfo) Runtime() string {
return i.runtime
}
// getRuncOptions returns a reference to the runtime options for use by the task.
// If the set of options is not set by the opts passed into the NewTask creation
// this function first attempts to initialize the runtime options with a copy of the runtimeOptions,
// otherwise an empty set of options is assigned and returned
func (i *TaskInfo) getRuncOptions() (*options.Options, error) {
if i.Options != nil {
opts, ok := i.Options.(*options.Options)
if !ok {
return nil, errors.New("invalid runtime v2 options format")
}
return opts, nil
}
opts := &options.Options{}
if i.runtimeOptions != nil && i.runtimeOptions.GetValue() != nil {
if err := typeurl.UnmarshalTo(i.runtimeOptions, opts); err != nil {
return nil, fmt.Errorf("failed to get runtime v2 options: %w", err)
}
}
i.Options = opts
return opts, nil
}
// Task is the executable object within containerd
type Task interface {
Process