Skip to content

Commit 08ee6a3

Browse files
authored
Merge pull request #156 from covexo/stop-sync
Resolve #141
2 parents 41ac78d + 87feb8f commit 08ee6a3

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

cmd/up.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,14 +181,19 @@ func (cmd *UpCmd) Run(cobraCmd *cobra.Command, args []string) {
181181
cmd.pod = pod
182182
}
183183

184-
if cmd.flags.sync {
185-
cmd.startSync()
186-
}
187-
188184
if cmd.flags.portforwarding {
189185
cmd.startPortForwarding()
190186
}
191187

188+
if cmd.flags.sync {
189+
syncConfigs := cmd.startSync()
190+
defer func() {
191+
for _, v := range syncConfigs {
192+
v.Stop()
193+
}
194+
}()
195+
}
196+
192197
cmd.enterTerminal()
193198
}
194199

@@ -360,7 +365,9 @@ func (cmd *UpCmd) deployChart() {
360365
log.StopWait()
361366
}
362367

363-
func (cmd *UpCmd) startSync() {
368+
func (cmd *UpCmd) startSync() []*synctool.SyncConfig {
369+
syncConfigs := make([]*synctool.SyncConfig, 0, len(cmd.dsConfig.SyncPaths))
370+
364371
for _, syncPath := range cmd.dsConfig.SyncPaths {
365372
absLocalPath, err := filepath.Abs(cmd.workdir + syncPath.LocalSubPath)
366373

@@ -379,7 +386,7 @@ func (cmd *UpCmd) startSync() {
379386
if err != nil {
380387
log.Panicf("Unable to list devspace pods: %s", err.Error())
381388
} else if pod != nil {
382-
syncConfig := synctool.SyncConfig{
389+
syncConfig := &synctool.SyncConfig{
383390
Kubectl: cmd.kubectl,
384391
Pod: pod,
385392
Container: &pod.Spec.Containers[0],
@@ -388,15 +395,17 @@ func (cmd *UpCmd) startSync() {
388395
}
389396

390397
err = syncConfig.Start()
391-
392398
if err != nil {
393399
log.Fatalf("Sync error: %s", err.Error())
394400
}
395401

396402
log.Donef("Sync started on %s <-> %s", absLocalPath, syncPath.ContainerPath)
403+
syncConfigs = append(syncConfigs, syncConfig)
397404
}
398405
}
399406
}
407+
408+
return syncConfigs
400409
}
401410

402411
func (cmd *UpCmd) startPortForwarding() {

pkg/devspace/sync/sync_config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,13 @@ func TestRunningSync(t *testing.T) {
313313
syncClient.mainLoop()
314314

315315
// Create
316-
err = createFileAndWait(local, remote, "1")
316+
err = createFileAndWait(remote, local, "2")
317317
if err != nil {
318318
t.Error(err)
319319
return
320320
}
321321

322-
err = createFileAndWait(remote, local, "2")
322+
err = createFileAndWait(local, remote, "1")
323323
if err != nil {
324324
t.Error(err)
325325
return

0 commit comments

Comments
 (0)