1 Star 0 Fork 43

YIN JIAYI/iSulad

forked from src-openEuler/iSulad 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
0018-clean-code-ignore-list-containers-error.patch 4.54 KB
一键复制 编辑 原始数据 按行查看 历史
From 051be757db25c8ac7e6c4beb1ec219b4fde3641c Mon Sep 17 00:00:00 2001
From: lifeng68 <[email protected]>
Date: Sat, 5 Dec 2020 10:24:58 +0800
Subject: [PATCH 18/18] clean code: ignore list containers error
Signed-off-by: lifeng68 <[email protected]>
---
src/daemon/executor/container_cb/list.c | 82 +++++++++++++++----------
1 file changed, 51 insertions(+), 31 deletions(-)
diff --git a/src/daemon/executor/container_cb/list.c b/src/daemon/executor/container_cb/list.c
index 4c9c9ed..3dea940 100644
--- a/src/daemon/executor/container_cb/list.c
+++ b/src/daemon/executor/container_cb/list.c
@@ -311,44 +311,73 @@ static void dup_id_name(const container_config_v2_common_config *common_config,
}
}
-static int convert_common_config_info(const map_t *map_labels, const container_config_v2_common_config *common_config,
- container_container *isuladinfo)
+static void dup_container_labels(const map_t *map_labels, const container_config_v2_common_config *common_config,
+ container_container *isuladinfo)
{
int ret = 0;
- bool args_err = false;
-
- if (map_labels == NULL || common_config == NULL || isuladinfo == NULL) {
- return -1;
- }
if (common_config->config == NULL) {
- return 0;
+ return;
}
- args_err = (common_config->config->labels != NULL && common_config->config->labels->len != 0);
- if (args_err) {
+
+ if (common_config->config->labels != NULL && common_config->config->labels->len != 0) {
json_map_string_string *labels = common_config->config->labels;
ret = replace_labels(isuladinfo, labels, map_labels);
- if (ret == -1) {
- goto out;
+ if (ret != 0) {
+ ERROR("Failed to dup container %s labels", common_config->id);
}
}
+ return;
+}
+
+static void dup_container_annotations(const container_config_v2_common_config *common_config,
+ container_container *isuladinfo)
+{
+ int ret = 0;
+
+ if (common_config->config == NULL) {
+ return;
+ }
+
ret = replace_annotations(common_config, isuladinfo);
- if (ret == -1) {
- goto out;
+ if (ret != 0) {
+ ERROR("Failed to dup container %s annotations", common_config->id);
}
- dup_id_name(common_config, isuladinfo);
- args_err = (common_config->created != NULL &&
- util_to_unix_nanos_from_str(common_config->created, &isuladinfo->created) != 0);
- if (args_err) {
- ret = -1;
- goto out;
+ return;
+}
+
+static void dup_container_created_time(const container_config_v2_common_config *common_config,
+ container_container *isuladinfo)
+{
+ if (common_config->created != NULL &&
+ util_to_unix_nanos_from_str(common_config->created, &isuladinfo->created) != 0) {
+ ERROR("Failed to dup container %s created time", common_config->id);
+ }
+
+ return;
+}
+
+static int convert_common_config_info(const map_t *map_labels, const container_config_v2_common_config *common_config,
+ container_container *isuladinfo)
+{
+ if (map_labels == NULL || common_config == NULL || isuladinfo == NULL) {
+ return -1;
}
+
+ dup_id_name(common_config, isuladinfo);
+
isuladinfo->restartcount = (uint64_t)common_config->restart_count;
-out:
- return ret;
+
+ dup_container_labels(map_labels, common_config, isuladinfo);
+
+ dup_container_annotations(common_config, isuladinfo);
+
+ dup_container_created_time(common_config, isuladinfo);
+
+ return 0;
}
static int container_info_match(const struct list_context *ctx, const map_t *map_labels,
@@ -413,7 +442,6 @@ static int fill_isuladinfo(container_container *isuladinfo, const container_conf
char *image = NULL;
char *timestr = NULL;
char *defvalue = "-";
- int64_t created_nanos = 0;
ret = convert_common_config_info(map_labels, cont->common_config, isuladinfo);
if (ret != 0) {
@@ -438,14 +466,6 @@ static int fill_isuladinfo(container_container *isuladinfo, const container_conf
isuladinfo->runtime = cont->runtime ? util_strdup_s(cont->runtime) : util_strdup_s("none");
isuladinfo->health_state = container_get_health_state(cont_state);
- if (cont->common_config->created != NULL) {
- ret = util_to_unix_nanos_from_str(cont->common_config->created, &created_nanos);
- if (ret != 0) {
- goto out;
- }
- }
-
- isuladinfo->created = created_nanos;
out:
return ret;
--
2.25.1
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yinjiayi/iSulad.git
[email protected]:yinjiayi/iSulad.git
yinjiayi
iSulad
iSulad
master

搜索帮助