Specify runtime configuration for sandbox shims
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
This commit is contained in:
parent
7d3ca170fd
commit
3f331e7d13
@ -86,7 +86,7 @@ func (c *Controller) Start(ctx context.Context, id string) (resp *api.Controller
|
|||||||
return nil, fmt.Errorf("failed to get image from containerd %q: %w", image.ID, err)
|
return nil, fmt.Errorf("failed to get image from containerd %q: %w", image.ID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ociRuntime, err := c.getSandboxRuntime(config, sandboxInfo.Runtime.Name)
|
ociRuntime, err := c.getSandboxRuntime(config, metadata.RuntimeHandler)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get sandbox runtime: %w", err)
|
return nil, fmt.Errorf("failed to get sandbox runtime: %w", err)
|
||||||
}
|
}
|
||||||
@ -263,6 +263,7 @@ func (c *Controller) Start(ctx context.Context, id string) (resp *api.Controller
|
|||||||
SandboxID: id,
|
SandboxID: id,
|
||||||
Pid: task.Pid(),
|
Pid: task.Pid(),
|
||||||
CreatedAt: protobuf.ToTimestamp(info.CreatedAt),
|
CreatedAt: protobuf.ToTimestamp(info.CreatedAt),
|
||||||
|
Labels: labels,
|
||||||
}
|
}
|
||||||
|
|
||||||
return resp, nil
|
return resp, nil
|
||||||
|
@ -86,10 +86,29 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
sandboxInfo := sb.Sandbox{
|
var (
|
||||||
ID: id,
|
err error
|
||||||
// TODO: runtime handler can be an empty string, should use default one and enable back validation of this field in metadata store.
|
sandboxInfo = sb.Sandbox{ID: id}
|
||||||
Runtime: sb.RuntimeOpts{Name: r.GetRuntimeHandler()},
|
)
|
||||||
|
|
||||||
|
ociRuntime, err := c.getSandboxRuntime(config, r.GetRuntimeHandler())
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to get OCI runtime for sandbox %q: %w", id, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
sandboxInfo.Runtime.Name = ociRuntime.Type
|
||||||
|
|
||||||
|
// Retrieve runtime options
|
||||||
|
runtimeOpts, err := generateRuntimeOptions(ociRuntime, c.config)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to generate sandbox runtime options: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if runtimeOpts != nil {
|
||||||
|
sandboxInfo.Runtime.Options, err = typeurl.MarshalAny(runtimeOpts)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to marshal runtime options: %w", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save sandbox name
|
// Save sandbox name
|
||||||
@ -127,11 +146,7 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
var (
|
podNetwork := true
|
||||||
podNetwork = true
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
|
|
||||||
if goruntime.GOOS != "windows" &&
|
if goruntime.GOOS != "windows" &&
|
||||||
config.GetLinux().GetSecurityContext().GetNamespaceOptions().GetNetwork() == runtime.NamespaceMode_NODE {
|
config.GetLinux().GetSecurityContext().GetNamespaceOptions().GetNetwork() == runtime.NamespaceMode_NODE {
|
||||||
// Pod network is not needed on linux with host network.
|
// Pod network is not needed on linux with host network.
|
||||||
@ -143,6 +158,11 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
|||||||
podNetwork = false
|
podNetwork = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// No CNI on darwin yet
|
||||||
|
if goruntime.GOOS == "darwin" {
|
||||||
|
podNetwork = false
|
||||||
|
}
|
||||||
|
|
||||||
if podNetwork {
|
if podNetwork {
|
||||||
netStart := time.Now()
|
netStart := time.Now()
|
||||||
// If it is not in host network namespace then create a namespace and set the sandbox
|
// If it is not in host network namespace then create a namespace and set the sandbox
|
||||||
|
@ -27,14 +27,12 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/containerd/containerd"
|
"github.com/containerd/containerd"
|
||||||
sandboxapi "github.com/containerd/containerd/api/services/sandbox/v1"
|
|
||||||
"github.com/containerd/containerd/oci"
|
"github.com/containerd/containerd/oci"
|
||||||
"github.com/containerd/containerd/pkg/cri/sbserver/podsandbox"
|
"github.com/containerd/containerd/pkg/cri/sbserver/podsandbox"
|
||||||
"github.com/containerd/containerd/pkg/cri/streaming"
|
"github.com/containerd/containerd/pkg/cri/streaming"
|
||||||
"github.com/containerd/containerd/pkg/kmutex"
|
"github.com/containerd/containerd/pkg/kmutex"
|
||||||
"github.com/containerd/containerd/plugin"
|
"github.com/containerd/containerd/plugin"
|
||||||
"github.com/containerd/containerd/sandbox"
|
"github.com/containerd/containerd/sandbox"
|
||||||
"github.com/containerd/containerd/sandbox/proxy"
|
|
||||||
runtime_alpha "github.com/containerd/containerd/third_party/k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
runtime_alpha "github.com/containerd/containerd/third_party/k8s.io/cri-api/pkg/apis/runtime/v1alpha2"
|
||||||
"github.com/containerd/go-cni"
|
"github.com/containerd/go-cni"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@ -191,7 +189,7 @@ func NewCRIService(config criconfig.Config, client *containerd.Client) (CRIServi
|
|||||||
|
|
||||||
// Load all sandbox controllers(pod sandbox controller and remote shim controller)
|
// Load all sandbox controllers(pod sandbox controller and remote shim controller)
|
||||||
c.sandboxControllers[criconfig.ModePodSandbox] = podsandbox.New(config, client, c.sandboxStore, c.os, c, c.baseOCISpecs)
|
c.sandboxControllers[criconfig.ModePodSandbox] = podsandbox.New(config, client, c.sandboxStore, c.os, c, c.baseOCISpecs)
|
||||||
c.sandboxControllers[criconfig.ModeShim] = proxy.NewSandboxController(sandboxapi.NewControllerClient(client.Conn()))
|
c.sandboxControllers[criconfig.ModeShim] = client.SandboxController()
|
||||||
|
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
@ -112,6 +112,7 @@ func (c *controllerLocal) Create(ctx context.Context, in *api.ControllerCreateRe
|
|||||||
Rootfs: in.Rootfs,
|
Rootfs: in.Rootfs,
|
||||||
Options: in.Options,
|
Options: in.Options,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
|
// TODO: Delete sandbox shim here.
|
||||||
return nil, fmt.Errorf("failed to start sandbox %s: %w", in.SandboxID, err)
|
return nil, fmt.Errorf("failed to start sandbox %s: %w", in.SandboxID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user