92 lines
4.5 KiB
Diff
92 lines
4.5 KiB
Diff
From c24f26ead1803db98fd2cd7e4d95a34239c15221 Mon Sep 17 00:00:00 2001
|
|
From: haozi007 <liuhao27@huawei.com>
|
|
Date: Mon, 26 Oct 2020 11:13:53 +0800
|
|
Subject: [PATCH 11/28] cni: support extension data transmission
|
|
|
|
Signed-off-by: haozi007 <liuhao27@huawei.com>
|
|
---
|
|
src/daemon/entry/cri/cni_network_plugin.cc | 15 +++++++++++++--
|
|
src/daemon/entry/cri/cri_helpers.cc | 2 ++
|
|
src/daemon/entry/cri/cri_helpers.h | 2 ++
|
|
3 files changed, 17 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/src/daemon/entry/cri/cni_network_plugin.cc b/src/daemon/entry/cri/cni_network_plugin.cc
|
|
index c1a4e1e..4676a97 100644
|
|
--- a/src/daemon/entry/cri/cni_network_plugin.cc
|
|
+++ b/src/daemon/entry/cri/cni_network_plugin.cc
|
|
@@ -581,10 +581,11 @@ void CniNetworkPlugin::DeleteFromNetwork(CNINetwork *network, const std::string
|
|
|
|
static void PrepareRuntimeConf(const std::string &podName, const std::string &podNs, const std::string &interfaceName,
|
|
const std::string &podSandboxID, const std::string &podNetnsPath,
|
|
+ const std::map<std::string, std::string> &annotations,
|
|
const std::map<std::string, std::string> &options, struct runtime_conf **cni_rc,
|
|
Errors &err)
|
|
{
|
|
- const size_t defaultLen = 5;
|
|
+ size_t defaultLen = 5;
|
|
if (cni_rc == nullptr) {
|
|
err.Errorf("Invalid arguments");
|
|
ERROR("Invalid arguments");
|
|
@@ -596,6 +597,12 @@ static void PrepareRuntimeConf(const std::string &podName, const std::string &po
|
|
if (iter != options.end()) {
|
|
podUID = iter->second;
|
|
}
|
|
+ std::string cniExtentionVal;
|
|
+ iter = annotations.find(CRIHelpers::Constants::CNI_MUTL_NET_EXTENSION_KEY);
|
|
+ if (iter != annotations.end()) {
|
|
+ cniExtentionVal = iter->second;
|
|
+ defaultLen++;
|
|
+ }
|
|
|
|
struct runtime_conf *rt = (struct runtime_conf *)util_common_calloc_s(sizeof(struct runtime_conf));
|
|
if (rt == nullptr) {
|
|
@@ -625,6 +632,10 @@ static void PrepareRuntimeConf(const std::string &podName, const std::string &po
|
|
rt->args[3][1] = util_strdup_s(podSandboxID.c_str());
|
|
rt->args[4][0] = util_strdup_s("K8S_POD_UID");
|
|
rt->args[4][1] = util_strdup_s(podUID.c_str());
|
|
+ if (defaultLen > 5) {
|
|
+ rt->args[5][0] = util_strdup_s(CRIHelpers::Constants::CNI_MUTL_NET_EXTENSION_ARGS_KEY.c_str());
|
|
+ rt->args[5][1] = util_strdup_s(cniExtentionVal.c_str());
|
|
+ }
|
|
|
|
*cni_rc = rt;
|
|
return;
|
|
@@ -639,7 +650,7 @@ void CniNetworkPlugin::BuildCNIRuntimeConf(const std::string &podName, const std
|
|
const std::map<std::string, std::string> &options,
|
|
struct runtime_conf **cni_rc, Errors &err)
|
|
{
|
|
- PrepareRuntimeConf(podName, podNs, interfaceName, podSandboxID, podNetnsPath, options, cni_rc, err);
|
|
+ PrepareRuntimeConf(podName, podNs, interfaceName, podSandboxID, podNetnsPath, annotations, options, cni_rc, err);
|
|
if (err.NotEmpty()) {
|
|
return;
|
|
}
|
|
diff --git a/src/daemon/entry/cri/cri_helpers.cc b/src/daemon/entry/cri/cri_helpers.cc
|
|
index 8aa939c..4fb9feb 100644
|
|
--- a/src/daemon/entry/cri/cri_helpers.cc
|
|
+++ b/src/daemon/entry/cri/cri_helpers.cc
|
|
@@ -51,6 +51,8 @@ const std::string Constants::CONTAINER_TYPE_ANNOTATION_SANDBOX { "sandbox" };
|
|
const std::string Constants::SANDBOX_ID_ANNOTATION_KEY { "io.kubernetes.cri.sandbox-id" };
|
|
const std::string Constants::NET_PLUGIN_EVENT_POD_CIDR_CHANGE { "pod-cidr-change" };
|
|
const std::string Constants::NET_PLUGIN_EVENT_POD_CIDR_CHANGE_DETAIL_CIDR { "pod-cidr" };
|
|
+const std::string Constants::CNI_MUTL_NET_EXTENSION_KEY { "extension.network.kubernetes.io/cni" };
|
|
+const std::string Constants::CNI_MUTL_NET_EXTENSION_ARGS_KEY { "CNI_MUTLINET_EXTENSION" };
|
|
|
|
const char *InternalLabelKeys[] = { CRIHelpers::Constants::CONTAINER_TYPE_LABEL_KEY.c_str(),
|
|
CRIHelpers::Constants::CONTAINER_LOGPATH_LABEL_KEY.c_str(),
|
|
diff --git a/src/daemon/entry/cri/cri_helpers.h b/src/daemon/entry/cri/cri_helpers.h
|
|
index 9dd3630..824d1a6 100644
|
|
--- a/src/daemon/entry/cri/cri_helpers.h
|
|
+++ b/src/daemon/entry/cri/cri_helpers.h
|
|
@@ -56,6 +56,8 @@ public:
|
|
|
|
static const std::string NET_PLUGIN_EVENT_POD_CIDR_CHANGE;
|
|
static const std::string NET_PLUGIN_EVENT_POD_CIDR_CHANGE_DETAIL_CIDR;
|
|
+ static const std::string CNI_MUTL_NET_EXTENSION_KEY;
|
|
+ static const std::string CNI_MUTL_NET_EXTENSION_ARGS_KEY;
|
|
};
|
|
|
|
auto GetDefaultSandboxImage(Errors &err) -> std::string;
|
|
--
|
|
2.20.1
|
|
|