sandbox: store endpoint in cri sandboxStore

Signed-off-by: Abel Feng <fshb1988@gmail.com>
This commit is contained in:
Abel Feng
2024-02-02 10:59:31 +08:00
parent f6e0cf1894
commit b1fefccc78
8 changed files with 74 additions and 9 deletions

View File

@@ -118,6 +118,14 @@ func (c *criService) StartContainer(ctx context.Context, r *runtime.StartContain
if ociRuntime.Path != "" {
taskOpts = append(taskOpts, containerd.WithRuntimePath(ociRuntime.Path))
}
// append endpoint to the options so that task manager can get task api endpoint directly
endpoint := sandbox.Endpoint
if endpoint.IsValid() {
taskOpts = append(taskOpts,
containerd.WithTaskApiEndpoint(endpoint.Address, endpoint.Protocol, endpoint.Version))
}
task, err := container.NewTask(ctx, ioCreation, taskOpts...)
if err != nil {
return nil, fmt.Errorf("failed to create containerd task: %w", err)

View File

@@ -113,6 +113,7 @@ func (c *criService) recover(ctx context.Context) error {
var (
state = sandboxstore.StateUnknown
controller = c.client.SandboxController(sbx.Sandboxer)
endpoint sandboxstore.Endpoint
)
status, err := controller.Status(ctx, sbx.ID, false)
@@ -126,6 +127,9 @@ func (c *criService) recover(ctx context.Context) error {
state = sandboxstore.StateNotReady
}
} else {
endpoint.Protocol = status.Protocol
endpoint.Version = status.Version
endpoint.Address = status.Address
if code, ok := runtime.PodSandboxState_value[status.State]; ok {
if code == int32(runtime.PodSandboxState_SANDBOX_READY) {
state = sandboxstore.StateReady
@@ -137,6 +141,7 @@ func (c *criService) recover(ctx context.Context) error {
sb := sandboxstore.NewSandbox(metadata, sandboxstore.Status{State: state})
sb.Sandboxer = sbx.Sandboxer
sb.Endpoint = endpoint
// Load network namespace.
sb.NetNS = getNetNS(&metadata)

View File

@@ -265,6 +265,18 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
return nil, fmt.Errorf("failed to start sandbox %q: %w", id, err)
}
if ctrl.Protocol != "" && ctrl.Address != "" {
sandbox.Endpoint = sandboxstore.Endpoint{
Protocol: ctrl.Protocol,
Version: ctrl.Version,
Address: ctrl.Address,
}
}
if sandboxInfo, err = c.client.SandboxStore().Update(ctx, sandboxInfo, "extensions"); err != nil {
return nil, fmt.Errorf("unable to update extensions for sandbox %q: %w", id, err)
}
if !hostNetwork(config) && userNsEnabled {
// If userns is enabled, then the netns was created by the OCI runtime
// on controller.Start(). The OCI runtime needs to create the netns

View File

@@ -47,6 +47,18 @@ type Sandbox struct {
*store.StopCh
// Stats contains (mutable) stats for the (pause) sandbox container
Stats *stats.ContainerStats
// Endpoint is the sandbox endpoint, for task or streaming api connection
Endpoint Endpoint
}
type Endpoint struct {
Address string
Protocol string
Version uint32
}
func (e *Endpoint) IsValid() bool {
return e.Protocol != "" && e.Address != ""
}
// NewSandbox creates an internally used sandbox type. This functions reminds