Skip to content

Commit

Permalink
Use port from the AppBinding (#234) (#243)
Browse files Browse the repository at this point in the history
/cherry-pick

Signed-off-by: Emruz Hossain <emruz@appscode.com>

Ref: stashed/stash#1272
  • Loading branch information
1gtm authored Dec 17, 2020
1 parent 3ea5fc8 commit 7b380f0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package pkg

import (
"context"
"fmt"
"path/filepath"
"strings"

Expand Down Expand Up @@ -212,6 +213,10 @@ func (opt *mysqlOptions) backupMySQL(targetRef api_v1beta1.TargetRef) (*restic.B
"-h", appBinding.Spec.ClientConfig.Service.Name,
},
}
// if port is specified, append port in the arguments
if appBinding.Spec.ClientConfig.Service.Port != 0 {
opt.backupOptions.StdinPipeCommand.Args = append(opt.backupOptions.StdinPipeCommand.Args, fmt.Sprintf("--port=%d", appBinding.Spec.ClientConfig.Service.Port))
}
for _, arg := range strings.Fields(opt.myArgs) {
opt.backupOptions.StdinPipeCommand.Args = append(opt.backupOptions.StdinPipeCommand.Args, arg)
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package pkg

import (
"context"
"fmt"
"path/filepath"
"strings"

Expand Down Expand Up @@ -181,6 +182,10 @@ func (opt *mysqlOptions) restoreMySQL(targetRef api_v1beta1.TargetRef) (*restic.
"-h", appBinding.Spec.ClientConfig.Service.Name,
},
}
// if port is specified, append port in the arguments
if appBinding.Spec.ClientConfig.Service.Port != 0 {
opt.dumpOptions.StdoutPipeCommand.Args = append(opt.dumpOptions.StdoutPipeCommand.Args, fmt.Sprintf("--port=%d", appBinding.Spec.ClientConfig.Service.Port))
}
for _, arg := range strings.Fields(opt.myArgs) {
opt.dumpOptions.StdoutPipeCommand.Args = append(opt.dumpOptions.StdoutPipeCommand.Args, arg)
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,8 @@ func waitForDBReady(appBinding *v1alpha1.AppBinding, secret *core.Secret, waitTi
"--user=root",
fmt.Sprintf("--wait=%d", waitTimeout),
}
if appBinding.Spec.ClientConfig.Service.Port != 0 {
args = append(args, fmt.Sprintf("--port=%d", appBinding.Spec.ClientConfig.Service.Port))
}
return shell.Command("mysqladmin", args...).Run()
}

0 comments on commit 7b380f0

Please sign in to comment.