sbserver: save netns in sandbox metadata on create
Port of b41d6f40bb
to sbserver
Signed-off-by: Samuel Karp <samuelkarp@google.com>
This commit is contained in:
parent
085d8e6334
commit
a74f7e902b
@ -170,6 +170,14 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
if err := sandboxInfo.AddExtension(podsandbox.MetadataKey, &sandbox.Metadata); err != nil {
|
||||||
|
return nil, fmt.Errorf("unable to save sandbox %q to store: %w", id, err)
|
||||||
|
}
|
||||||
|
// Save sandbox metadata to store
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
||||||
// Define this defer to teardownPodNetwork prior to the setupPodNetwork function call.
|
// Define this defer to teardownPodNetwork prior to the setupPodNetwork function call.
|
||||||
// This is because in setupPodNetwork the resource is allocated even if it returns error, unlike other resource
|
// This is because in setupPodNetwork the resource is allocated even if it returns error, unlike other resource
|
||||||
// creation functions.
|
// creation functions.
|
||||||
|
@ -141,12 +141,22 @@ type SandboxInfo struct {
|
|||||||
RuntimeType string `json:"runtimeType"`
|
RuntimeType string `json:"runtimeType"`
|
||||||
RuntimeOptions interface{} `json:"runtimeOptions"`
|
RuntimeOptions interface{} `json:"runtimeOptions"`
|
||||||
Config *runtime.PodSandboxConfig `json:"config"`
|
Config *runtime.PodSandboxConfig `json:"config"`
|
||||||
|
// Note: RuntimeSpec may not be populated if the sandbox has not been fully created.
|
||||||
RuntimeSpec *runtimespec.Spec `json:"runtimeSpec"`
|
RuntimeSpec *runtimespec.Spec `json:"runtimeSpec"`
|
||||||
CNIResult *cni.Result `json:"cniResult"`
|
CNIResult *cni.Result `json:"cniResult"`
|
||||||
|
Metadata *sandboxstore.Metadata `json:"sandboxMetadata"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// toCRISandboxInfo converts internal container object information to CRI sandbox status response info map.
|
// toCRISandboxInfo converts internal container object information to CRI sandbox status response info map.
|
||||||
func toCRISandboxInfo(ctx context.Context, sandbox sandboxstore.Sandbox) (map[string]string, error) {
|
func toCRISandboxInfo(ctx context.Context, sandbox sandboxstore.Sandbox) (map[string]string, error) {
|
||||||
|
si := &SandboxInfo{
|
||||||
|
Pid: sandbox.Status.Get().Pid,
|
||||||
|
Config: sandbox.Config,
|
||||||
|
RuntimeHandler: sandbox.RuntimeHandler,
|
||||||
|
CNIResult: sandbox.CNIResult,
|
||||||
|
}
|
||||||
|
|
||||||
|
if sandbox.Container != nil {
|
||||||
container := sandbox.Container
|
container := sandbox.Container
|
||||||
task, err := container.Task(ctx, nil)
|
task, err := container.Task(ctx, nil)
|
||||||
if err != nil && !errdefs.IsNotFound(err) {
|
if err != nil && !errdefs.IsNotFound(err) {
|
||||||
@ -164,29 +174,7 @@ func toCRISandboxInfo(ctx context.Context, sandbox sandboxstore.Sandbox) (map[st
|
|||||||
processStatus = taskStatus.Status
|
processStatus = taskStatus.Status
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
si.Status = string(processStatus)
|
||||||
si := &SandboxInfo{
|
|
||||||
Pid: sandbox.Status.Get().Pid,
|
|
||||||
RuntimeHandler: sandbox.RuntimeHandler,
|
|
||||||
Status: string(processStatus),
|
|
||||||
Config: sandbox.Config,
|
|
||||||
CNIResult: sandbox.CNIResult,
|
|
||||||
}
|
|
||||||
|
|
||||||
if si.Status == "" {
|
|
||||||
// If processStatus is empty, it means that the task is deleted. Apply "deleted"
|
|
||||||
// status which does not exist in containerd.
|
|
||||||
si.Status = "deleted"
|
|
||||||
}
|
|
||||||
|
|
||||||
if sandbox.NetNS != nil {
|
|
||||||
// Add network closed information if sandbox is not using host network.
|
|
||||||
closed, err := sandbox.NetNS.Closed()
|
|
||||||
if err != nil {
|
|
||||||
return nil, fmt.Errorf("failed to check network namespace closed: %w", err)
|
|
||||||
}
|
|
||||||
si.NetNSClosed = closed
|
|
||||||
}
|
|
||||||
|
|
||||||
spec, err := container.Spec(ctx)
|
spec, err := container.Spec(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -211,6 +199,24 @@ func toCRISandboxInfo(ctx context.Context, sandbox sandboxstore.Sandbox) (map[st
|
|||||||
}
|
}
|
||||||
si.RuntimeType = ctrInfo.Runtime.Name
|
si.RuntimeType = ctrInfo.Runtime.Name
|
||||||
si.RuntimeOptions = runtimeOptions
|
si.RuntimeOptions = runtimeOptions
|
||||||
|
}
|
||||||
|
|
||||||
|
if si.Status == "" {
|
||||||
|
// If processStatus is empty, it means that the task is deleted. Apply "deleted"
|
||||||
|
// status which does not exist in containerd.
|
||||||
|
si.Status = "deleted"
|
||||||
|
}
|
||||||
|
|
||||||
|
if sandbox.NetNS != nil {
|
||||||
|
// Add network closed information if sandbox is not using host network.
|
||||||
|
closed, err := sandbox.NetNS.Closed()
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("failed to check network namespace closed: %w", err)
|
||||||
|
}
|
||||||
|
si.NetNSClosed = closed
|
||||||
|
}
|
||||||
|
|
||||||
|
si.Metadata = &sandbox.Metadata
|
||||||
|
|
||||||
infoBytes, err := json.Marshal(si)
|
infoBytes, err := json.Marshal(si)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user