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

