From edb21523aac45aa5628243599a296592a6b84d79 Mon Sep 17 00:00:00 2001 From: zhongtao Date: Wed, 12 Feb 2025 11:18:46 +1400 Subject: [PATCH 192/198] modify save step in run sandbox Signed-off-by: zhongtao --- .../v1/v1_cri_pod_sandbox_manager_service.cc | 55 +++++++------------ 1 file changed, 19 insertions(+), 36 deletions(-) diff --git a/src/daemon/entry/cri/v1/v1_cri_pod_sandbox_manager_service.cc b/src/daemon/entry/cri/v1/v1_cri_pod_sandbox_manager_service.cc index 62464acd..8a7779ad 100644 --- a/src/daemon/entry/cri/v1/v1_cri_pod_sandbox_manager_service.cc +++ b/src/daemon/entry/cri/v1/v1_cri_pod_sandbox_manager_service.cc @@ -325,7 +325,7 @@ void PodSandboxManagerService::StartPodSandboxAndSetupNetowrk(std::shared_ptrCreate(error); if (error.NotEmpty()) { ERROR("Failed to create sandbox: %s", sandboxName.c_str()); @@ -337,7 +337,7 @@ void PodSandboxManagerService::StartPodSandboxAndSetupNetowrk(std::shared_ptrStart(error); if (error.NotEmpty()) { ERROR("Failed to start sandbox: %s", sandboxName.c_str()); return; } - // Step 7.2.4:Setup networking for the sandbox. + // Step 8.2.4:Setup networking for the sandbox. SetupSandboxNetwork(sandbox, network_setting_json, error); if (error.NotEmpty()) { goto stop_sandbox; } - // Step 7.2.5:update Network settings after setup network to update ip info. + // Step 8.2.5:update Network settings after setup network to update ip info. if (namespace_is_cni(networkMode.c_str())) { Errors tmpErr; sandbox->UpdateNetworkSettings(network_setting_json, tmpErr); @@ -378,23 +378,7 @@ void PodSandboxManagerService::StartPodSandboxAndSetupNetowrk(std::shared_ptrSave(error); - if (error.NotEmpty()) { - ERROR("Failed to save sandbox, %s", sandboxName.c_str()); - goto cleanup_network; - } return; - -cleanup_network: - if (namespace_is_cni(sandbox->GetNetMode().c_str())) { - Errors clearErr; - ClearCniNetwork(sandbox, clearErr); - if (clearErr.NotEmpty()) { - ERROR("Failed to clean cni network: %s", clearErr.GetCMessage()); - } - } - stop_sandbox: Errors stopError; CRIHelpers::StopContainerHelper(m_cb, sandbox->GetId(), 0, stopError); @@ -406,21 +390,14 @@ void PodSandboxManagerService::SetupNetowrkAndStartPodSandbox(std::shared_ptrSave(error); - if (error.NotEmpty()) { - ERROR("Failed to save sandbox, %s", sandboxName.c_str()); - goto cleanup_network; - } - - // Step 7.1.3: Call sandbox create. + // Step 8.1.2: Call sandbox create. sandbox->Create(error); if (error.NotEmpty()) { ERROR("Failed to create sandbox: %s", sandboxName.c_str()); @@ -432,7 +409,7 @@ void PodSandboxManagerService::SetupNetowrkAndStartPodSandbox(std::shared_ptrStart(error); if (error.NotEmpty()) { ERROR("Failed to start sandbox: %s", sandboxName.c_str()); // If start failed, sandbox should be NotReady, we cleanup network, but delete sandbox in remove goto cleanup_network; } - return; cleanup_network: @@ -531,15 +507,22 @@ auto PodSandboxManagerService::RunPodSandbox(const runtime::v1::PodSandboxConfig goto clean_ns; } + // Step 7: Save sandbox metadate to disk for sandbox instance create success + sandbox->Save(error); + if (error.NotEmpty()) { + ERROR("Failed to save sandbox, %s", sandboxName.c_str()); + goto clean_ns; + } + CRIHelpers::ProtobufAnnoMapToStd(sandbox->GetSandboxConfig().annotations(), stdAnnos); - // Step 7: According to the annotation and network namespace mode, + // Step 8: According to the annotation and network namespace mode, // determine the order of start sandbox and setup network. // tips: clean sandbox and network in sub function. if (CRIHelpers::SetupNetworkFirst(stdAnnos)) { - // Step 7.1: Setup networking for the sandbox, and then start the sandbox container. + // Step 8.1: Setup networking for the sandbox, and then start the sandbox container. SetupNetowrkAndStartPodSandbox(sandbox, sandboxName, networkMode, error); } else { - // Step 7.2: (Default)Start the sandbox container, and then setup networking for the sandbox. + // Step 8.2: (Default)Start the sandbox container, and then setup networking for the sandbox. // why: Some kata multi-network plane plugins (such as configuring vfio device pass-through) // need to be called after the pod is already running. StartPodSandboxAndSetupNetowrk(sandbox, sandboxKey, sandboxName, networkMode, error); -- 2.34.1