@@ -14,28 +14,22 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
1616
17- package appclone
17+ package sidecar
1818
1919import (
2020 "fmt"
2121 "os"
2222 "os/exec"
2323 "strings"
24-
25- logf "sigs.k8s.io/controller-runtime/pkg/runtime/log"
26-
27- "github.com/presslabs/mysql-operator/pkg/sidecar/app"
2824)
2925
30- var log = logf .Log .WithName ("sidecar.appclone" )
31-
3226// RunCloneCommand clone the data from source.
3327// nolint: gocyclo
34- func RunCloneCommand (cfg * app. BaseConfig ) error {
28+ func RunCloneCommand (cfg * Config ) error {
3529 log .Info ("clonning command" , "host" , cfg .Hostname )
3630
3731 // skip cloning if data exists.
38- if ! app . ShouldBootstrapNode () {
32+ if ! shouldBootstrapNode () {
3933 log .Info ("data exists and is initialized, skipping cloning." )
4034 return nil
4135 }
@@ -49,7 +43,7 @@ func RunCloneCommand(cfg *app.BaseConfig) error {
4943 return fmt .Errorf ("removing lost+found: %s" , err )
5044 }
5145
52- if cfg .NodeRole () == app . MasterNode {
46+ if cfg .NodeRole () == MasterNode {
5347 if len (cfg .InitBucketURL ) == 0 {
5448 log .Info ("skip cloning init bucket uri is not set." )
5549 // let mysqld initialize data dir
@@ -87,15 +81,15 @@ func cloneFromBucket(initBucket string) error {
8781
8882 log .Info ("cloning from bucket" , "bucket" , initBucket )
8983
90- if _ , err := os .Stat (app . RcloneConfigFile ); os .IsNotExist (err ) {
84+ if _ , err := os .Stat (rcloneConfigFile ); os .IsNotExist (err ) {
9185 log .Error (err , "rclone config file does not exists" )
9286 return err
9387 }
9488 // rclone --config={conf file} cat {bucket uri}
9589 // writes to stdout the content of the bucket uri
9690 // nolint: gosec
9791 rclone := exec .Command ("rclone" , "-vv" ,
98- fmt .Sprintf ("--config=%s" , app . RcloneConfigFile ), "cat" , initBucket )
92+ fmt .Sprintf ("--config=%s" , rcloneConfigFile ), "cat" , initBucket )
9993
10094 // gzip reads from stdin decompress and then writes to stdout
10195 // nolint: gosec
@@ -105,7 +99,7 @@ func cloneFromBucket(initBucket string) error {
10599 // extracts files from stdin (-x) and writes them to mysql
106100 // data target dir
107101 // nolint: gosec
108- xbstream := exec .Command ("xbstream" , "-x" , "-C" , app . DataDir )
102+ xbstream := exec .Command ("xbstream" , "-x" , "-C" , dataDir )
109103
110104 var err error
111105 // rclone | gzip | xbstream
@@ -149,10 +143,10 @@ func cloneFromBucket(initBucket string) error {
149143 return nil
150144}
151145
152- func cloneFromSource (cfg * app. BaseConfig , host string ) error {
146+ func cloneFromSource (cfg * Config , host string ) error {
153147 log .Info ("cloning from node" , "host" , host )
154148
155- backupBody , err := app . RequestABackup (cfg , host , app . ServerBackupEndpoint )
149+ backupBody , err := requestABackup (cfg , host , serverBackupEndpoint )
156150 if err != nil {
157151 return fmt .Errorf ("fail to get backup: %s" , err )
158152 }
@@ -161,7 +155,7 @@ func cloneFromSource(cfg *app.BaseConfig, host string) error {
161155 // extracts files from stdin (-x) and writes them to mysql
162156 // data target dir
163157 // nolint: gosec
164- xbstream := exec .Command ("xbstream" , "-x" , "-C" , app . DataDir )
158+ xbstream := exec .Command ("xbstream" , "-x" , "-C" , dataDir )
165159
166160 xbstream .Stdin = backupBody
167161 xbstream .Stderr = os .Stderr
@@ -180,7 +174,7 @@ func cloneFromSource(cfg *app.BaseConfig, host string) error {
180174func xtrabackupPreperData () error {
181175 // nolint: gosec
182176 xtbkCmd := exec .Command ("xtrabackup" , "--prepare" ,
183- fmt .Sprintf ("--target-dir=%s" , app . DataDir ))
177+ fmt .Sprintf ("--target-dir=%s" , dataDir ))
184178
185179 xtbkCmd .Stderr = os .Stderr
186180
@@ -189,7 +183,7 @@ func xtrabackupPreperData() error {
189183
190184// nolint: gosec
191185func checkIfDataExists () bool {
192- path := fmt .Sprintf ("%s/mysql" , app . DataDir )
186+ path := fmt .Sprintf ("%s/mysql" , dataDir )
193187 _ , err := os .Open (path )
194188
195189 if os .IsNotExist (err ) {
@@ -202,6 +196,6 @@ func checkIfDataExists() bool {
202196}
203197
204198func deleteLostFound () error {
205- path := fmt .Sprintf ("%s/lost+found" , app . DataDir )
199+ path := fmt .Sprintf ("%s/lost+found" , dataDir )
206200 return os .RemoveAll (path )
207201}
0 commit comments