retry 10 times to avoid isulad unavailable

This commit is contained in:
yangjiaqi 2022-08-17 14:36:56 +08:00
parent 8a7d98fb02
commit f75058a610
2 changed files with 65 additions and 1 deletions

View File

@ -0,0 +1,60 @@
From 77e01d06b90d167f013417455a30eebe22ca3674 Mon Sep 17 00:00:00 2001
From: yangjiaqi <yangjiaqi16@huawei.com>
Date: Mon, 15 Aug 2022 20:30:14 +0800
Subject: [PATCH] retry 10 times to avoid isulad unavailable
---
remountcmd.go | 23 ++++++++++++++++++++---
1 file changed, 20 insertions(+), 3 deletions(-)
diff --git a/remountcmd.go b/remountcmd.go
index 7cf42c6..b3cac19 100644
--- a/remountcmd.go
+++ b/remountcmd.go
@@ -180,7 +180,7 @@ func waitForLxcfs() error {
func remountAll(initMountns, initUserns string) error {
lxcfs_log.Info("begin remount All runing container...")
- out, err := execCommond("isula", []string{"ps", "--format", "{{.ID}} {{.Pid}}"})
+ out, err := getContainerIDAndPid()
if err != nil {
return err
}
@@ -213,6 +213,24 @@ func remountAll(initMountns, initUserns string) error {
return nil
}
+func getContainerIDAndPid() ([]string, error) {
+ var (
+ out []string
+ err error
+ )
+ for i := 0; i < 10; i++ {
+ out, err = execCommond("isula", []string{"ps", "--format", "{{.ID}} {{.Pid}}"})
+ if err == nil {
+ break
+ }
+ time.Sleep(1 * time.Second)
+ }
+ if err != nil {
+ return nil, err
+ }
+ return out, nil
+}
+
func remountToContainer(initMountns, initUserns, containerid string, pid string, isAll bool) error {
if isAll == false {
var err error
@@ -260,8 +278,7 @@ func isContainerExsit(containerid string) (string, error) {
if containerid == "" {
return "", fmt.Errorf("Containerid mustn't be empty")
}
-
- out, err := execCommond("isula", []string{"ps", "--format", "{{.ID}} {{.Pid}}"})
+ out, err := getContainerIDAndPid()
if err != nil {
onfail(err)
}
--
2.30.0

View File

@ -1,7 +1,7 @@
#Basic Information
Name: lxcfs-tools
Version: 0.3
Release: 25
Release: 26
Summary: toolkit for lxcfs to remount a running isulad
License: Mulan PSL v2
URL: https://gitee.com/openeuler/lxcfs-tools
@ -10,6 +10,7 @@ BuildRoot: %{_tmppath}/%{name}-root
Patch1: 0001-lxcfs-tools-build-security-option.patch
Patch2: 0002-enable-external-linkmode-for-cgo-build.patch
Patch3: 0003-retry-10-times-to-avoid-isulad-unavailable.patch
#Dependency
BuildRequires: golang > 1.7
@ -91,6 +92,9 @@ rm -rfv %{buildroot}
%changelog
* Wed Aug 17 2022 vegbir <yangjiaqi16@huawei.com> - 0.3-26
- retry 10 times to avoid isulad unavailable
* Thu Sep 02 2021 zhangsong234 <zhangsong34@huawei.com> - 0.3-25
- enable external linkmode for cgo build