Use options to pass PodSandboxConfig to shims
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
This commit is contained in:
parent
edb8ebaf07
commit
2b24af8d13
@ -225,7 +225,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
|||||||
|
|
||||||
runtimeStart := time.Now()
|
runtimeStart := time.Now()
|
||||||
|
|
||||||
if err := controller.Create(ctx, id); err != nil {
|
if err := controller.Create(ctx, id, sb.WithOptions(config)); err != nil {
|
||||||
return nil, fmt.Errorf("failed to create sandbox %q: %w", id, err)
|
return nil, fmt.Errorf("failed to create sandbox %q: %w", id, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ package sandbox
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containerd/containerd/api/types"
|
"github.com/containerd/containerd/api/types"
|
||||||
@ -26,23 +27,35 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type CreateOptions struct {
|
type CreateOptions struct {
|
||||||
Rootfs []*types.Mount
|
Rootfs []*types.Mount
|
||||||
|
// Options are used to pass arbitrary options to the shim when creating a new sandbox.
|
||||||
|
// CRI will use this to pass PodSandboxConfig.
|
||||||
|
// Don't confuse this with Runtime options, which are passed at shim instance start
|
||||||
|
// to setup global shim configuration.
|
||||||
Options typeurl.Any
|
Options typeurl.Any
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateOpt func(*CreateOptions)
|
type CreateOpt func(*CreateOptions) error
|
||||||
|
|
||||||
// WithRootFS is used to create a sandbox with the provided rootfs mount
|
// WithRootFS is used to create a sandbox with the provided rootfs mount
|
||||||
// TODO: Switch to mount.Mount once target added
|
// TODO: Switch to mount.Mount once target added
|
||||||
func WithRootFS(m []*types.Mount) CreateOpt {
|
func WithRootFS(m []*types.Mount) CreateOpt {
|
||||||
return func(co *CreateOptions) {
|
return func(co *CreateOptions) error {
|
||||||
co.Rootfs = m
|
co.Rootfs = m
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithOptions(a typeurl.Any) CreateOpt {
|
// WithOptions allows passing arbitrary options when creating a new sandbox.
|
||||||
return func(co *CreateOptions) {
|
func WithOptions(options any) CreateOpt {
|
||||||
co.Options = a
|
return func(co *CreateOptions) error {
|
||||||
|
var err error
|
||||||
|
co.Options, err = typeurl.MarshalAny(options)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to marshal sandbox options: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user