Skip to content

Commit 7b380f0

Browse files
authored
Use port from the AppBinding (#234) (#243)
/cherry-pick Signed-off-by: Emruz Hossain <emruz@appscode.com> Ref: stashed/stash#1272
1 parent 3ea5fc8 commit 7b380f0

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

pkg/backup.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package pkg
1818

1919
import (
2020
"context"
21+
"fmt"
2122
"path/filepath"
2223
"strings"
2324

@@ -212,6 +213,10 @@ func (opt *mysqlOptions) backupMySQL(targetRef api_v1beta1.TargetRef) (*restic.B
212213
"-h", appBinding.Spec.ClientConfig.Service.Name,
213214
},
214215
}
216+
// if port is specified, append port in the arguments
217+
if appBinding.Spec.ClientConfig.Service.Port != 0 {
218+
opt.backupOptions.StdinPipeCommand.Args = append(opt.backupOptions.StdinPipeCommand.Args, fmt.Sprintf("--port=%d", appBinding.Spec.ClientConfig.Service.Port))
219+
}
215220
for _, arg := range strings.Fields(opt.myArgs) {
216221
opt.backupOptions.StdinPipeCommand.Args = append(opt.backupOptions.StdinPipeCommand.Args, arg)
217222
}

pkg/restore.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package pkg
1818

1919
import (
2020
"context"
21+
"fmt"
2122
"path/filepath"
2223
"strings"
2324

@@ -181,6 +182,10 @@ func (opt *mysqlOptions) restoreMySQL(targetRef api_v1beta1.TargetRef) (*restic.
181182
"-h", appBinding.Spec.ClientConfig.Service.Name,
182183
},
183184
}
185+
// if port is specified, append port in the arguments
186+
if appBinding.Spec.ClientConfig.Service.Port != 0 {
187+
opt.dumpOptions.StdoutPipeCommand.Args = append(opt.dumpOptions.StdoutPipeCommand.Args, fmt.Sprintf("--port=%d", appBinding.Spec.ClientConfig.Service.Port))
188+
}
184189
for _, arg := range strings.Fields(opt.myArgs) {
185190
opt.dumpOptions.StdoutPipeCommand.Args = append(opt.dumpOptions.StdoutPipeCommand.Args, arg)
186191
}

pkg/utils.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,8 @@ func waitForDBReady(appBinding *v1alpha1.AppBinding, secret *core.Secret, waitTi
6666
"--user=root",
6767
fmt.Sprintf("--wait=%d", waitTimeout),
6868
}
69+
if appBinding.Spec.ClientConfig.Service.Port != 0 {
70+
args = append(args, fmt.Sprintf("--port=%d", appBinding.Spec.ClientConfig.Service.Port))
71+
}
6972
return shell.Command("mysqladmin", args...).Run()
7073
}

0 commit comments

Comments
 (0)