Skip to content

Commit 1ba0074

Browse files
authored
[cherry-pick] /cherry-pick (#271) (#283)
Signed-off-by: Emruz Hossain <emruz@appscode.com>
1 parent d63cbc1 commit 1ba0074

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,3 +572,10 @@ release:
572572
.PHONY: clean
573573
clean:
574574
rm -rf .go bin
575+
576+
# make and load docker image to kind cluster
577+
.PHONY: push-to-kind
578+
push-to-kind: container
579+
@echo "Loading docker image into kind cluster...."
580+
@kind load docker-image $(REGISTRY)/stash-mysql:$(TAG)
581+
@echo "Image has been pushed successfully into kind cluster."

pkg/utils.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ package pkg
1818

1919
import (
2020
"fmt"
21+
"time"
2122

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

2526
"github.com/codeskyblue/go-sh"
2627
"gomodules.xyz/x/log"
2728
core "k8s.io/api/core/v1"
29+
"k8s.io/apimachinery/pkg/util/wait"
2830
"k8s.io/client-go/kubernetes"
2931
"kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1"
3032
appcatalog_cs "kmodules.xyz/custom-resources/client/clientset/versioned"
@@ -61,13 +63,24 @@ func waitForDBReady(appBinding *v1alpha1.AppBinding, secret *core.Secret, waitTi
6163
shell := sh.NewSession()
6264
shell.SetEnv(EnvMySqlPassword, string(secret.Data[MySqlPassword]))
6365
args := []interface{}{
64-
"ping",
6566
"--host", appBinding.Spec.ClientConfig.Service.Name,
66-
"--user=root",
67-
fmt.Sprintf("--wait=%d", waitTimeout),
67+
"-u", string(secret.Data[MySqlUser]),
6868
}
6969
if appBinding.Spec.ClientConfig.Service.Port != 0 {
7070
args = append(args, fmt.Sprintf("--port=%d", appBinding.Spec.ClientConfig.Service.Port))
7171
}
72-
return shell.Command("mysqladmin", args...).Run()
72+
73+
// Execute "SELECT 1" query to the database. It should return an error when mysqld is not ready.
74+
args = append(args, "-e", "SELECT 1;")
75+
76+
// don't show the output of the query
77+
shell.Stdout = nil
78+
return wait.PollImmediate(5*time.Second, time.Duration(waitTimeout)*time.Second, func() (done bool, err error) {
79+
if err := shell.Command("mysql", args...).Run(); err == nil {
80+
log.Infoln("Database is accepting connection....")
81+
return true, nil
82+
}
83+
log.Infoln("Retrying after 5 seconds....")
84+
return false, nil
85+
})
7386
}

0 commit comments

Comments
 (0)