提交 af6a8590 编写于 作者: O openeuler-ci-bot 提交者: Gitee

!202 optimize cni

Merge pull request !202 from haozi007/newwork
......@@ -117,10 +117,19 @@ function default_cni_config()
function new_cni_config()
{
cp ${data_path}/bridge.json /etc/cni/net.d/
# wait cni updated
crictl info
sync;sync;
sleep 2
tail $ISUALD_LOG
# wait cni updated
s=`date "+%s"`
for ((i=0;i<30;i++)); do
sleep 1
cur=`date "+%s"`
let "t=cur-s"
if [ $t -gt 6 ];then
break
fi
done
tail $ISUALD_LOG
do_test_help "10\.2\."
}
......
......@@ -9,7 +9,7 @@ include(cmake/set_build_flags.cmake)
#set(CMAKE_C_COMPILER "gcc" CACHE PATH "c compiler")
set(GIT_COMMIT_HASH "f2a6e59b14e430d166e350cac06ec188fb7ca47e")
set(GIT_COMMIT_HASH "c5d55826dcf94d804412c7ccba7cc2c387df88c0")
message("-- commit id: " ${GIT_COMMIT_HASH})
add_definitions(-DISULAD_GIT_COMMIT="${GIT_COMMIT_HASH}")
......
%global _version 2.0.0
%global _release 20200406.224326.gitf2a6e59b
%global _release 20200421.092611.gitc5d55826
%global is_systemd 1
%global debug_package %{nil}
......
......@@ -101,10 +101,25 @@ void CniNetworkPlugin::SetLoNetwork(std::unique_ptr<CNINetwork> lo)
}
}
void CniNetworkPlugin::SetDefaultNetwork(std::unique_ptr<CNINetwork> network)
void CniNetworkPlugin::SetDefaultNetwork(std::unique_ptr<CNINetwork> network,
std::vector<std::string> &binDirs, Errors &err)
{
if (network != nullptr) {
m_defaultNetwork = std::move(network);
if (network == nullptr) {
return;
}
WLockNetworkMap(err);
if (err.NotEmpty()) {
ERROR("%s", err.GetCMessage());
return;
}
m_defaultNetwork = std::move(network);
m_defaultNetwork->SetPaths(binDirs);
DEBUG("Update new cni network: \"%s\"", m_defaultNetwork->GetName().c_str());
UnlockNetworkMap(err);
if (err.NotEmpty()) {
ERROR("%s", err.GetCMessage());
}
}
......@@ -264,8 +279,7 @@ void CniNetworkPlugin::GetDefaultCNINetwork(const std::string &confDir, std::vec
continue;
}
m_defaultNetwork = std::unique_ptr<CNINetwork>(new (std::nothrow) CNINetwork(n_list->name, n_list));
m_defaultNetwork->SetPaths(binDirs);
SetDefaultNetwork(std::unique_ptr<CNINetwork>(new (std::nothrow) CNINetwork(n_list->name, n_list)), binDirs, err);
found = true;
break;
}
......@@ -294,19 +308,10 @@ void CniNetworkPlugin::CheckInitialized(Errors &err)
void CniNetworkPlugin::SyncNetworkConfig()
{
Errors err;
WLockNetworkMap(err);
if (err.NotEmpty()) {
ERROR("%s", err.GetCMessage());
return;
}
GetDefaultCNINetwork(m_confDir, m_binDirs, err);
if (err.NotEmpty()) {
WARN("Unable to update cni config: %s", err.GetCMessage());
}
UnlockNetworkMap(err);
if (err.NotEmpty()) {
ERROR("%s", err.GetCMessage());
}
}
void CniNetworkPlugin::Init(CRIRuntimeServiceImpl *criImpl, const std::string &hairpinMode,
......@@ -341,8 +346,6 @@ const std::string &CniNetworkPlugin::Name() const
void CniNetworkPlugin::Status(Errors &err)
{
SyncNetworkConfig();
CheckInitialized(err);
}
......@@ -420,34 +423,42 @@ std::map<int, bool> *CniNetworkPlugin::Capabilities()
return m_noop.Capabilities();
}
void CniNetworkPlugin::Event(const std::string &name, std::map<std::string, std::string> &details)
void CniNetworkPlugin::SetPodCidr(const std::string &podCidr)
{
if (name != CRIHelpers::Constants::NET_PLUGIN_EVENT_POD_CIDR_CHANGE) {
return;
}
auto iter = details.find(CRIHelpers::Constants::NET_PLUGIN_EVENT_POD_CIDR_CHANGE_DETAIL_CIDR);
if (iter == details.end()) {
WARN("%s event didn't contain pod CIDR", CRIHelpers::Constants::NET_PLUGIN_EVENT_POD_CIDR_CHANGE.c_str());
return;
}
Errors err;
WLockNetworkMap(err);
if (err.NotEmpty()) {
ERROR("%s", err.GetCMessage());
return;
}
if (m_podCidr.empty()) {
WARN("Ignoring subsequent pod CIDR update to %s", iter->second.c_str());
if (!m_podCidr.empty()) {
WARN("Ignoring subsequent pod CIDR update to %s", podCidr.c_str());
goto unlock_out;
}
m_podCidr = iter->second;
m_podCidr = podCidr;
unlock_out:
UnlockNetworkMap(err);
}
void CniNetworkPlugin::Event(const std::string &name, std::map<std::string, std::string> &details)
{
if (name != CRIHelpers::Constants::NET_PLUGIN_EVENT_POD_CIDR_CHANGE) {
return;
}
auto iter = details.find(CRIHelpers::Constants::NET_PLUGIN_EVENT_POD_CIDR_CHANGE_DETAIL_CIDR);
if (iter == details.end()) {
WARN("%s event didn't contain pod CIDR", CRIHelpers::Constants::NET_PLUGIN_EVENT_POD_CIDR_CHANGE.c_str());
return;
}
SetPodCidr(iter->second);
}
void CniNetworkPlugin::GetPodNetworkStatus(const std::string &ns, const std::string &name,
const std::string &interfaceName, const std::string &podSandboxID,
PodNetworkStatus &status, Errors &err)
......@@ -724,12 +735,14 @@ void CniNetworkPlugin::UnlockNetworkMap(Errors &error)
void CniNetworkPlugin::UpdateDefaultNetwork()
{
#define DEFAULT_SYNC_CONFIG_CNT 50
#define DEFAULT_SYNC_CONFIG_PERIOD 100
const int defaultSyncConfigCnt = 5;
const int defaultSyncConfigPeriod = 1000;
pthread_setname_np(pthread_self(), "CNIUpdater");
while (true) {
for (int i = 0; i < DEFAULT_SYNC_CONFIG_PERIOD; i++) {
std::this_thread::sleep_for(std::chrono::milliseconds(DEFAULT_SYNC_CONFIG_PERIOD));
for (int i = 0; i < defaultSyncConfigCnt; i++) {
std::this_thread::sleep_for(std::chrono::milliseconds(defaultSyncConfigPeriod));
if (m_needFinish) {
return;
}
......
......@@ -115,8 +115,6 @@ public:
virtual void SetLoNetwork(std::unique_ptr<CNINetwork> lo);
virtual void SetDefaultNetwork(std::unique_ptr<CNINetwork> network);
private:
virtual void PlatformInit(Errors &error);
virtual void SyncNetworkConfig();
......@@ -149,6 +147,8 @@ private:
void RLockNetworkMap(Errors &error);
void WLockNetworkMap(Errors &error);
void UnlockNetworkMap(Errors &error);
void SetDefaultNetwork(std::unique_ptr<CNINetwork> network, std::vector<std::string> &binDirs, Errors &err);
void SetPodCidr(const std::string &podCidr);
int GetCNIConfFiles(const std::string &pluginDir, std::vector<std::string> &vect_files, Errors &err);
int LoadCNIConfigFileList(const std::string &elem, struct cni_network_list_conf **n_list);
int InsertConfNameToAllPanes(struct cni_network_list_conf *n_list, std::set<std::string> &allPanes, Errors &err);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册