Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
iSulad
提交
423aeff2
I
iSulad
项目概览
openeuler
/
iSulad
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
I
iSulad
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
423aeff2
编写于
3月 02, 2020
作者:
O
openeuler-ci-bot
提交者:
Gitee
3月 02, 2020
浏览文件
操作
浏览文件
下载
差异文件
!80 add --label && --label-file interface
Merge pull request !80 from JingWoo/label
上级
4327f540
ffb7907d
变更
10
显示空白变更内容
内联
并排
Showing
10 changed file
with
249 addition
and
10 deletion
+249
-10
src/cmd/isula/arguments.h
src/cmd/isula/arguments.h
+6
-0
src/cmd/isula/base/create.c
src/cmd/isula/base/create.c
+157
-2
src/cmd/isula/base/create.h
src/cmd/isula/base/create.h
+4
-0
src/libisula.h
src/libisula.h
+3
-0
src/pack_config.c
src/pack_config.c
+71
-0
src/services/cri/cni_network_plugin.cc
src/services/cri/cni_network_plugin.cc
+1
-1
test/cmd/isula/extend/resume/CMakeLists.txt
test/cmd/isula/extend/resume/CMakeLists.txt
+1
-1
test/cmd/isula/infomation/ps/CMakeLists.txt
test/cmd/isula/infomation/ps/CMakeLists.txt
+1
-1
test/cmd/isulad-shim/isulad-shim_llt.cc
test/cmd/isulad-shim/isulad-shim_llt.cc
+4
-4
test/services/execution/execute/execution_extend/CMakeLists.txt
...ervices/execution/execute/execution_extend/CMakeLists.txt
+1
-1
未找到文件。
src/cmd/isula/arguments.h
浏览文件 @
423aeff2
...
...
@@ -43,6 +43,12 @@ struct custom_configs {
/* environment variables file */
char
**
env_file
;
/* label */
char
**
label
;
/* label file */
char
**
label_file
;
/* hugepage limits */
char
**
hugepage_limits
;
...
...
src/cmd/isula/base/create.c
浏览文件 @
423aeff2
...
...
@@ -13,6 +13,7 @@
* Description: provide container create functions
******************************************************************************/
#include <unistd.h>
#include <stdio_ext.h>
#include <regex.h>
#include <sys/types.h>
#include <sys/stat.h>
...
...
@@ -414,6 +415,149 @@ out:
return
ret
;
}
static
bool
validate_label
(
const
char
*
label
)
{
bool
ret
=
true
;
char
**
arr
=
util_string_split_n
(
label
,
'='
,
2
);
if
(
arr
==
NULL
)
{
ERROR
(
"Failed to split label string"
);
ret
=
false
;
goto
out
;
}
if
(
strlen
(
arr
[
0
])
==
0
)
{
ERROR
(
"Invalid label: %s, empty name"
,
label
);
ret
=
false
;
goto
out
;
}
out:
util_free_array
(
arr
);
return
ret
;
}
static
int
request_pack_custom_label
(
struct
client_arguments
*
args
,
isula_container_config_t
*
conf
)
{
int
ret
=
0
;
size_t
i
;
if
(
args
->
custom_conf
.
label
==
NULL
)
{
return
0
;
}
for
(
i
=
0
;
i
<
util_array_len
((
const
char
**
)(
args
->
custom_conf
.
label
));
i
++
)
{
if
(
!
validate_label
(
args
->
custom_conf
.
label
[
i
]))
{
COMMAND_ERROR
(
"Invalid label '%s': empty name"
,
args
->
custom_conf
.
label
[
i
]);
ret
=
-
1
;
goto
out
;
}
if
(
util_array_append
(
&
conf
->
label
,
args
->
custom_conf
.
label
[
i
])
!=
0
)
{
COMMAND_ERROR
(
"Failed to append custom config label list"
);
ret
=
-
1
;
goto
out
;
}
}
util_free_array
(
args
->
custom_conf
.
label
);
args
->
custom_conf
.
label
=
conf
->
label
;
/* make sure args->custom_conf.label point to valid memory. */
conf
->
label_len
=
util_array_len
((
const
char
**
)(
conf
->
label
));
out:
return
ret
;
}
static
int
read_label_from_file
(
const
char
*
path
,
size_t
file_size
,
isula_container_config_t
*
conf
)
{
int
ret
=
0
;
FILE
*
fp
=
NULL
;
char
*
buf
=
NULL
;
size_t
len
;
ssize_t
num
;
if
(
file_size
==
0
)
{
return
0
;
}
fp
=
fopen
(
path
,
"re"
);
if
(
fp
==
NULL
)
{
ERROR
(
"Failed to open '%s'"
,
path
);
return
-
1
;
}
__fsetlocking
(
fp
,
FSETLOCKING_BYCALLER
);
num
=
getline
(
&
buf
,
&
len
,
fp
);
while
(
num
!=
-
1
)
{
size_t
len
=
strlen
(
buf
);
if
(
len
==
1
)
{
num
=
getline
(
&
buf
,
&
len
,
fp
);
continue
;
}
buf
[
len
-
1
]
=
'\0'
;
if
(
!
validate_label
(
buf
))
{
COMMAND_ERROR
(
"Invalid label '%s': empty name"
,
buf
);
ret
=
-
1
;
goto
out
;
}
if
(
util_array_append
(
&
conf
->
label
,
buf
)
!=
0
)
{
ERROR
(
"Failed to append label"
);
ret
=
-
1
;
goto
out
;
}
num
=
getline
(
&
buf
,
&
len
,
fp
);
}
out:
free
(
buf
);
fclose
(
fp
);
return
ret
;
}
static
int
append_labels_to_conf
(
const
char
*
label_file
,
isula_container_config_t
*
conf
)
{
int
ret
=
0
;
size_t
file_size
;
if
(
!
util_file_exists
(
label_file
))
{
COMMAND_ERROR
(
"label file not exists: %s"
,
label_file
);
ret
=
-
1
;
goto
out
;
}
file_size
=
util_file_size
(
label_file
);
if
(
file_size
>
REGULAR_FILE_SIZE
)
{
COMMAND_ERROR
(
"label file '%s', size exceed limit: %lld"
,
label_file
,
REGULAR_FILE_SIZE
);
ret
=
-
1
;
goto
out
;
}
if
(
read_label_from_file
(
label_file
,
file_size
,
conf
)
!=
0
)
{
COMMAND_ERROR
(
"failed to read label from file: %s"
,
label_file
);
ret
=
-
1
;
goto
out
;
}
out:
return
ret
;
}
static
int
request_pack_custom_label_file
(
const
struct
client_arguments
*
args
,
isula_container_config_t
*
conf
)
{
int
ret
=
0
;
size_t
i
;
char
**
label_files
=
args
->
custom_conf
.
label_file
;
size_t
label_files_size
=
util_array_len
((
const
char
**
)
label_files
);
if
(
label_files_size
==
0
)
{
return
0
;
}
for
(
i
=
0
;
i
<
label_files_size
;
i
++
)
{
if
(
append_labels_to_conf
(
label_files
[
i
],
conf
)
!=
0
)
{
ret
=
-
1
;
goto
out
;
}
}
conf
->
label_len
=
util_array_len
((
const
char
**
)(
conf
->
label
));
out:
return
ret
;
}
static
void
request_pack_custom_user
(
const
struct
client_arguments
*
args
,
isula_container_config_t
*
conf
)
{
if
(
args
->
custom_conf
.
user
!=
NULL
)
{
...
...
@@ -577,17 +721,27 @@ static int request_pack_custom_conf(struct client_arguments *args, isula_contain
return
-
1
;
}
/*
M
ake sure --env has higher priority than --env-file */
/*
m
ake sure --env has higher priority than --env-file */
if
(
request_pack_custom_env
(
args
,
conf
)
!=
0
)
{
return
-
1
;
}
/* append labels from label file */
if
(
request_pack_custom_label_file
(
args
,
conf
)
!=
0
)
{
return
-
1
;
}
/* make sure --label has higher priority than --label-file */
if
(
request_pack_custom_label
(
args
,
conf
)
!=
0
)
{
return
-
1
;
}
/* user and group */
request_pack_custom_user
(
args
,
conf
);
request_pack_custom_hostname
(
args
,
conf
);
/* alldevices */
/* all
devices */
request_pack_custom_all_devices
(
args
,
conf
);
/* system container */
...
...
@@ -1225,6 +1379,7 @@ out:
return
ret
;
}
int
callback_annotation
(
command_option_t
*
option
,
const
char
*
value
)
{
struct
client_arguments
*
args
=
(
struct
client_arguments
*
)
option
->
data
;
...
...
src/cmd/isula/base/create.h
浏览文件 @
423aeff2
...
...
@@ -53,6 +53,10 @@ extern "C" {
"Set environment variables", command_append_array }, \
{ CMD_OPT_TYPE_CALLBACK, false, "env-file", 0, &(cmdargs).custom_conf.env_file, \
"Read in a file of environment variables", command_append_array }, \
{ CMD_OPT_TYPE_CALLBACK, false, "label", 'l', &(cmdargs).custom_conf.label, \
"Set metadata on container (default [])", command_append_array }, \
{ CMD_OPT_TYPE_CALLBACK, false, "label-file", 0, &(cmdargs).custom_conf.label_file, \
"Read in a line delimited file of labels (default [])", command_append_array }, \
{ CMD_OPT_TYPE_STRING_DUP, false, "entrypoint", 0, &(cmdargs).custom_conf.entrypoint, \
"Entrypoint to run when starting the container", NULL }, \
{ CMD_OPT_TYPE_STRING, false, "external-rootfs", 0, &(cmdargs).external_rootfs, \
...
...
src/libisula.h
浏览文件 @
423aeff2
...
...
@@ -37,6 +37,9 @@ typedef struct isula_container_config {
char
**
env
;
size_t
env_len
;
char
**
label
;
size_t
label_len
;
char
*
hostname
;
char
*
user
;
...
...
src/pack_config.c
浏览文件 @
423aeff2
...
...
@@ -1928,6 +1928,72 @@ out:
return
ret
;
}
static
int
get_label_key_value
(
const
char
*
label
,
char
**
key
,
char
**
value
)
{
int
ret
=
0
;
char
**
arr
=
util_string_split_n
(
label
,
'='
,
2
);
if
(
arr
==
NULL
)
{
ERROR
(
"Failed to split input label"
);
ret
=
-
1
;
goto
out
;
}
*
key
=
util_strdup_s
(
arr
[
0
]);
if
(
util_array_len
((
const
char
**
)
arr
)
==
1
)
{
*
value
=
util_strdup_s
(
""
);
}
else
{
*
value
=
util_strdup_s
(
arr
[
1
]);
}
out:
util_free_array
(
arr
);
return
ret
;
}
static
int
pack_container_custom_config_labels
(
container_config
*
container_spec
,
const
isula_container_config_t
*
custom_conf
)
{
int
ret
=
0
;
int
i
;
char
*
key
=
NULL
;
char
*
value
=
NULL
;
if
(
custom_conf
->
label_len
==
0
||
custom_conf
->
label
==
NULL
)
{
return
0
;
}
/* labels */
container_spec
->
labels
=
util_common_calloc_s
(
sizeof
(
json_map_string_string
));
if
(
container_spec
->
labels
==
NULL
)
{
ERROR
(
"Out of memory"
);
ret
=
-
1
;
goto
out
;
}
for
(
i
=
0
;
i
<
custom_conf
->
label_len
;
i
++
)
{
if
(
get_label_key_value
(
custom_conf
->
label
[
i
],
&
key
,
&
value
)
!=
0
)
{
ERROR
(
"Failed to get key and value of label"
);
ret
=
-
1
;
goto
out
;
}
if
(
append_json_map_string_string
(
container_spec
->
labels
,
key
,
value
))
{
ERROR
(
"Append map failed"
);
ret
=
-
1
;
goto
out
;
}
free
(
key
);
key
=
NULL
;
free
(
value
);
value
=
NULL
;
}
out:
free
(
key
);
free
(
value
);
return
ret
;
}
static
bool
have_health_check
(
const
isula_container_config_t
*
custom_conf
)
{
bool
have_health_settings
=
false
;
...
...
@@ -2087,6 +2153,11 @@ static int pack_container_custom_config_pre(container_config *container_spec,
goto
out
;
}
ret
=
pack_container_custom_config_labels
(
container_spec
,
custom_conf
);
if
(
ret
!=
0
)
{
goto
out
;
}
ret
=
pack_container_custom_config_health
(
container_spec
,
custom_conf
);
if
(
ret
!=
0
)
{
goto
out
;
...
...
src/services/cri/cni_network_plugin.cc
浏览文件 @
423aeff2
test/cmd/isula/extend/resume/CMakeLists.txt
浏览文件 @
423aeff2
...
...
@@ -52,5 +52,5 @@ target_include_directories(${EXE} PUBLIC
${
CMAKE_BINARY_DIR
}
/json
${
CMAKE_BINARY_DIR
}
/conf
)
target_link_libraries
(
${
EXE
}
${
GTEST_BOTH_LIBRARIES
}
${
GMOCK_LIBRARY
}
${
GMOCK_MAIN_LIBRARY
}
${
CMAKE_THREAD_LIBS_INIT
}
-lgrpc++ -lprotobuf -lcrypto -lyajl -l
securec -l
z
)
target_link_libraries
(
${
EXE
}
${
GTEST_BOTH_LIBRARIES
}
${
GMOCK_LIBRARY
}
${
GMOCK_MAIN_LIBRARY
}
${
CMAKE_THREAD_LIBS_INIT
}
-lgrpc++ -lprotobuf -lcrypto -lyajl -lz
)
test/cmd/isula/infomation/ps/CMakeLists.txt
浏览文件 @
423aeff2
...
...
@@ -51,4 +51,4 @@ target_include_directories(${EXE} PUBLIC
${
CMAKE_BINARY_DIR
}
/json
${
CMAKE_BINARY_DIR
}
/conf
)
target_link_libraries
(
${
EXE
}
${
GTEST_BOTH_LIBRARIES
}
${
GMOCK_LIBRARY
}
${
GMOCK_MAIN_LIBRARY
}
${
CMAKE_THREAD_LIBS_INIT
}
-lgrpc++ -lprotobuf -lcrypto -lyajl -l
securec -l
z
)
target_link_libraries
(
${
EXE
}
${
GTEST_BOTH_LIBRARIES
}
${
GMOCK_LIBRARY
}
${
GMOCK_MAIN_LIBRARY
}
${
CMAKE_THREAD_LIBS_INIT
}
-lgrpc++ -lprotobuf -lcrypto -lyajl -lz
)
test/cmd/isulad-shim/isulad-shim_llt.cc
浏览文件 @
423aeff2
...
...
@@ -41,7 +41,7 @@ public:
TEST_F
(
IsuladShimUnitTest
,
test_new_process
)
{
string
id
=
"aaaabbbbccccdddd"
;
string
id
=
"aaaabbbbccccdddd"
;
string
bundle
=
"/home/isulad/bundle"
;
string
runtime
=
"kata-runtime"
;
...
...
@@ -77,7 +77,7 @@ TEST_F(IsuladShimUnitTest, test_read_write_nointr)
EXPECT_EQ
(
read_nointr
(
0
,
NULL
,
32
),
-
1
);
EXPECT_EQ
(
read_nointr
(
1
,
NULL
,
32
),
-
1
);
fd_wr
=
open_no_inherit
(
test_file
.
c_str
(),
O_CREAT
|
O_RDWR
|
O_APPEND
|
O_SYNC
,
0640
);
fd_wr
=
open_no_inherit
(
test_file
.
c_str
(),
O_CREAT
|
O_RDWR
|
O_APPEND
|
O_SYNC
,
0640
);
EXPECT_GT
(
fd_wr
,
0
);
nwrite
=
write_nointr
(
fd_wr
,
test_string
.
c_str
(),
5
);
EXPECT_EQ
(
nwrite
,
5
);
...
...
test/services/execution/execute/execution_extend/CMakeLists.txt
浏览文件 @
423aeff2
...
...
@@ -79,4 +79,4 @@ target_include_directories(${EXE} PUBLIC
${
CMAKE_CURRENT_SOURCE_DIR
}
/../../../../mocks
${
CMAKE_BINARY_DIR
}
/json
)
target_link_libraries
(
${
EXE
}
${
GTEST_BOTH_LIBRARIES
}
${
GMOCK_LIBRARY
}
${
GMOCK_MAIN_LIBRARY
}
${
CMAKE_THREAD_LIBS_INIT
}
-lgrpc++ -lprotobuf -lcrypto -lyajl -l
securec -l
z
)
target_link_libraries
(
${
EXE
}
${
GTEST_BOTH_LIBRARIES
}
${
GMOCK_LIBRARY
}
${
GMOCK_MAIN_LIBRARY
}
${
CMAKE_THREAD_LIBS_INIT
}
-lgrpc++ -lprotobuf -lcrypto -lyajl -lz
)
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录