Skip to content

Commit 641cdaa

Browse files
1gtmEmruz Hossain
andauthored
[cherry-pick] Bring back the wait loop (#418) (#422)
/cherry-pick This was somehow removed in #328 . Signed-off-by: Emruz Hossain <emruz@appscode.com> Co-authored-by: Emruz Hossain <emruz@appscode.com>
1 parent abe44d1 commit 641cdaa

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

pkg/utils.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ package pkg
1919
import (
2020
"fmt"
2121
"path/filepath"
22+
"time"
2223

2324
stash "stash.appscode.dev/apimachinery/client/clientset/versioned"
2425
"stash.appscode.dev/apimachinery/pkg/restic"
2526

2627
"gomodules.xyz/go-sh"
2728
core "k8s.io/api/core/v1"
29+
"k8s.io/apimachinery/pkg/util/wait"
2830
"k8s.io/client-go/kubernetes"
2931
"k8s.io/klog/v2"
3032
"kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1"
@@ -78,5 +80,13 @@ func (opt *mysqlOptions) waitForDBReady(appBinding *v1alpha1.AppBinding, secret
7880

7981
// don't show the output of the query
8082
shell.Stdout = nil
81-
return shell.Command("mysql", args...).Run()
83+
84+
return wait.PollImmediate(5*time.Second, time.Duration(opt.waitTimeout)*time.Second, func() (done bool, err error) {
85+
if err := shell.Command("mysql", args...).Run(); err == nil {
86+
klog.Infoln("Database is accepting connection....")
87+
return true, nil
88+
}
89+
klog.Infof("Unable to connect with the database. Reason: %v.\nRetrying after 5 seconds....", err)
90+
return false, nil
91+
})
8292
}

0 commit comments

Comments
 (0)