/
utils.go
67 lines (55 loc) · 1.83 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
Copyright The Stash Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package pkg
import (
"fmt"
"stash.appscode.dev/apimachinery/pkg/restic"
"github.com/appscode/go/log"
"github.com/codeskyblue/go-sh"
core "k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes"
"kmodules.xyz/custom-resources/apis/appcatalog/v1alpha1"
appcatalog_cs "kmodules.xyz/custom-resources/client/clientset/versioned"
)
const (
MySqlUser = "username"
MySqlPassword = "password"
MySqlDumpFile = "dumpfile.sql"
MySqlDumpCMD = "mysqldump"
MySqlRestoreCMD = "mysql"
EnvMySqlPassword = "MYSQL_PWD"
)
type mysqlOptions struct {
kubeClient kubernetes.Interface
catalogClient appcatalog_cs.Interface
namespace string
appBindingName string
myArgs string
waitTimeout int32
outputDir string
setupOptions restic.SetupOptions
backupOptions restic.BackupOptions
dumpOptions restic.DumpOptions
}
func waitForDBReady(appBinding *v1alpha1.AppBinding, secret *core.Secret, waitTimeout int32) error {
log.Infoln("Waiting for the database to be ready.....")
shell := sh.NewSession()
shell.SetEnv(EnvMySqlPassword, string(secret.Data[MySqlPassword]))
args := []interface{}{
"ping",
"--host", appBinding.Spec.ClientConfig.Service.Name,
"--user=root",
fmt.Sprintf("--wait=%d", waitTimeout),
}
return shell.Command("mysqladmin", args...).Run()
}