diff --git a/src/services/cri/cri_helpers.cc b/src/services/cri/cri_helpers.cc index 2ecef0d93feca1a682795d7eb8c81a77b74c93ba..48589da4f692878e78ef77b0917d7e886b879f02 100644 --- a/src/services/cri/cri_helpers.cc +++ b/src/services/cri/cri_helpers.cc @@ -705,8 +705,4 @@ out: free_cri_checkpoint(criCheckpoint); } -std::string DeterminePodIPBySandboxID(const std::string &podSandboxID) -{ - return ""; -} } // namespace CRIHelpers diff --git a/src/services/cri/cri_helpers.h b/src/services/cri/cri_helpers.h index 43281d2cbf72907fda48c26cf4d2b0e79c4e45bf..8e308c6192db370566ba12fc0ec1716d4faaf6b3 100644 --- a/src/services/cri/cri_helpers.h +++ b/src/services/cri/cri_helpers.h @@ -110,7 +110,6 @@ std::string CreateCheckpoint(cri::PodSandboxCheckpoint &checkpoint, Errors &erro void GetCheckpoint(const std::string &jsonCheckPoint, cri::PodSandboxCheckpoint &checkpoint, Errors &error); -std::string DeterminePodIPBySandboxID(const std::string &podSandboxID); }; // namespace CRIHelpers #endif /* _CRI_HELPERS_H_ */ diff --git a/src/services/cri/cri_sandbox.cc b/src/services/cri/cri_sandbox.cc index 0428b06b4e72567bd4ef4948fe29ec7bac7d8bfa..5c0d0eb835ebeeffd6b356462a786d8e3ca71584 100644 --- a/src/services/cri/cri_sandbox.cc +++ b/src/services/cri/cri_sandbox.cc @@ -35,7 +35,6 @@ #include "container_custom_config.h" #include "checkpoint_handler.h" #include "cri_security_context.h" -#include "cxxutils.h" runtime::v1alpha2::NamespaceMode CRIRuntimeServiceImpl::SharesHostNetwork(container_inspect *inspect) { @@ -967,72 +966,8 @@ void CRIRuntimeServiceImpl::SetSandboxStatusNetwork(container_inspect *inspect, std::unique_ptr &podStatus, Errors &error) { - if (podStatus->annotations_size() == 0) { - return; - } - std::vector ipInfo; - std::string IP; - size_t len = 0; - auto networks = CRIHelpers::GetNetworkPlaneFromPodAnno(*podStatus->mutable_annotations(), &len, error); - if (error.NotEmpty()) { - ERROR("Couldn't get network plane from pod annotations: %s", error.GetCMessage()); - return; - } - bool isDefaultNetDisable = false; - for (size_t i = 0; i < len; i++) { - if (networks[i]->name == nullptr) { - ERROR("Invalid network config, do not have name"); - error.SetError("Invalid networks config"); - goto free_out; - } - if (std::string(networks[i]->name) == Network::POD_DISABLE_DEFAULT_NET_ANNOTATION_KEY) { - isDefaultNetDisable = true; - } - } - - IP = CRIHelpers::DeterminePodIPBySandboxID(podSandboxID); - if (IP.empty() && !isDefaultNetDisable) { - if (len > SIZE_MAX / sizeof(cri_pod_network_element *) - 1) { - ERROR("Too many cri pod network elements!"); - goto free_out; - } - size_t new_size = (len + 1) * sizeof(cri_pod_network_element *); - size_t old_size = len * sizeof(cri_pod_network_element *); - cri_pod_network_element **new_networks; - if (mem_realloc((void **)(&new_networks), new_size, (void *)networks, old_size) != 0) { - ERROR("Failed to realloc memory for append cri pod network element"); - goto free_out; - } - networks = new_networks; - cri_pod_network_element *new_element = - (cri_pod_network_element *)util_common_calloc_s(sizeof(cri_pod_network_element)); - if (new_element == NULL) { - ERROR("Out of memory"); - goto free_out; - } - new_element->interface = util_strdup_s(Network::GetInterfaceName().c_str()); - networks[len] = new_element; - len++; - } - - for (size_t i = 0; i < len; i++) { - std::string iterfaceName { networks[i]->interface != nullptr ? networks[i]->interface : "" }; - std::string interfaceIP = GetIP(podSandboxID, inspect, iterfaceName, error); - if (error.NotEmpty()) { - WARN("get default ip failed: %s", error.GetCMessage()); - error.Clear(); - } - ipInfo.push_back(iterfaceName + ":" + interfaceIP); - } - podStatus->mutable_network()->set_ip(CXXUtils::StringsJoin(ipInfo, ";")); - -free_out: - for (size_t i = 0; i < len; i++) { - free_cri_pod_network_element(networks[i]); - networks[i] = nullptr; - } - - free(networks); + std::string interfaceIP = GetIP(podSandboxID, inspect, Network::DEFAULT_NETWORK_INTERFACE_NAME, error); + podStatus->mutable_network()->set_ip(interfaceIP); } void CRIRuntimeServiceImpl::PodSandboxStatusToGRPC(container_inspect *inspect, const std::string &podSandboxID,