Skip to content

Commit 6a8fc43

Browse files
author
gentele
committed
resolve conflicts
2 parents a0d611f + 08ee6a3 commit 6a8fc43

2 files changed

Lines changed: 39 additions & 27 deletions

File tree

cmd/up.go

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ var UpFlagsDefault = &UpCmdFlags{
5858
initRegistry: true,
5959
build: true,
6060
sync: true,
61-
deploy: true,
61+
deploy: false,
6262
portforwarding: true,
6363
noSleep: false,
6464
}
@@ -140,8 +140,10 @@ func (cmd *UpCmd) Run(cobraCmd *cobra.Command, args []string) {
140140
}
141141
}
142142

143+
var shouldRebuild bool
144+
143145
if cmd.flags.build {
144-
shouldRebuild := cmd.shouldRebuild(cobraCmd.Flags().Changed("build"))
146+
shouldRebuild = cmd.shouldRebuild(cobraCmd.Flags().Changed("build"))
145147

146148
if shouldRebuild {
147149
cmd.buildImage()
@@ -154,7 +156,7 @@ func (cmd *UpCmd) Run(cobraCmd *cobra.Command, args []string) {
154156
}
155157
}
156158

157-
if cmd.flags.deploy {
159+
if cmd.flags.deploy || shouldRebuild {
158160
cmd.deployChart()
159161
} else {
160162
// Check if we find a running release pod
@@ -167,14 +169,19 @@ func (cmd *UpCmd) Run(cobraCmd *cobra.Command, args []string) {
167169
cmd.pod = pod
168170
}
169171

170-
if cmd.flags.sync {
171-
cmd.startSync()
172-
}
173-
174172
if cmd.flags.portforwarding {
175173
cmd.startPortForwarding()
176174
}
177175

176+
if cmd.flags.sync {
177+
syncConfigs := cmd.startSync()
178+
defer func() {
179+
for _, v := range syncConfigs {
180+
v.Stop()
181+
}
182+
}()
183+
}
184+
178185
cmd.enterTerminal()
179186
}
180187

@@ -338,14 +345,15 @@ func (cmd *UpCmd) deployChart() {
338345
log.StopWait()
339346
}
340347

341-
func (cmd *UpCmd) startSync() {
348+
func (cmd *UpCmd) startSync() []*synctool.SyncConfig {
342349
config := configutil.GetConfig(false)
350+
syncConfigs := make([]*synctool.SyncConfig, 0, len(config.DevSpace.Sync))
343351

344352
for _, syncPath := range config.DevSpace.Sync {
345353
absLocalPath, err := filepath.Abs(cmd.workdir + *syncPath.LocalSubPath)
346354

347355
if err != nil {
348-
log.Panicf("Unable to resolve localSubPath %s: %s", syncPath.LocalSubPath, err.Error())
356+
log.Panicf("Unable to resolve localSubPath %s: %s", *syncPath.LocalSubPath, err.Error())
349357
} else {
350358
// Retrieve pod from label selector
351359
labels := make([]string, 0, len(syncPath.LabelSelector))
@@ -359,7 +367,7 @@ func (cmd *UpCmd) startSync() {
359367
if err != nil {
360368
log.Panicf("Unable to list devspace pods: %s", err.Error())
361369
} else if pod != nil {
362-
syncConfig := synctool.SyncConfig{
370+
syncConfig := &synctool.SyncConfig{
363371
Kubectl: cmd.kubectl,
364372
Pod: pod,
365373
Container: &pod.Spec.Containers[0],
@@ -368,15 +376,17 @@ func (cmd *UpCmd) startSync() {
368376
}
369377

370378
err = syncConfig.Start()
371-
372379
if err != nil {
373380
log.Fatalf("Sync error: %s", err.Error())
374381
}
375382

376383
log.Donef("Sync started on %s <-> %s", absLocalPath, syncPath.ContainerPath)
384+
syncConfigs = append(syncConfigs, syncConfig)
377385
}
378386
}
379387
}
388+
389+
return syncConfigs
380390
}
381391

382392
func (cmd *UpCmd) startPortForwarding() {

pkg/devspace/sync/sync_config_test.go

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func createTestSyncClient(testLocalPath, testRemotePath string) *SyncConfig {
3737
}
3838
}
3939

40-
func removeFolderAndWait(from, to, postfix string, t *testing.T) error {
40+
func removeFolderAndWait(from, to, postfix string) error {
4141
foldernameFrom := path.Join(from, "testFolder"+postfix)
4242
foldernameTo := path.Join(to, "testFolder"+postfix)
4343

@@ -54,7 +54,7 @@ func removeFolderAndWait(from, to, postfix string, t *testing.T) error {
5454
return fmt.Errorf("Removing folder %s wasn't correctly synced to %s", foldernameFrom, foldernameTo)
5555
}
5656

57-
func removeFileAndWait(from, to, postfix string, t *testing.T) error {
57+
func removeFileAndWait(from, to, postfix string) error {
5858
filenameFrom := path.Join(from, "testFile"+postfix)
5959
filenameTo := path.Join(to, "testFile"+postfix)
6060

@@ -71,7 +71,7 @@ func removeFileAndWait(from, to, postfix string, t *testing.T) error {
7171
return fmt.Errorf("Removing file %s wasn't correctly synced to %s", filenameFrom, filenameTo)
7272
}
7373

74-
func createFolderAndWait(from, to, postfix string, t *testing.T) error {
74+
func createFolderAndWait(from, to, postfix string) error {
7575
foldernameFrom := path.Join(from, "testFolder"+postfix)
7676
foldernameTo := path.Join(to, "testFolder"+postfix)
7777

@@ -92,14 +92,16 @@ func createFolderAndWait(from, to, postfix string, t *testing.T) error {
9292
return fmt.Errorf("Created folder %s wasn't correctly synced to %s", foldernameFrom, foldernameTo)
9393
}
9494

95-
func createFileAndWait(from, to, postfix string, t *testing.T) error {
95+
func createFileAndWait(from, to, postfix string) error {
9696
filenameFrom := path.Join(from, "testFile"+postfix)
9797
filenameTo := path.Join(to, "testFile"+postfix)
9898
fileContents := "testFile" + postfix
9999

100100
ioutil.WriteFile(filenameFrom, []byte(fileContents), 0666)
101101

102102
for i := 0; i < 50; i++ {
103+
time.Sleep(time.Millisecond * 100)
104+
103105
if _, err := os.Stat(filenameTo); err == nil {
104106
data, err := ioutil.ReadFile(filenameTo)
105107
if err != nil {
@@ -111,8 +113,6 @@ func createFileAndWait(from, to, postfix string, t *testing.T) error {
111113

112114
return nil
113115
}
114-
115-
time.Sleep(time.Millisecond * 100)
116116
}
117117

118118
return fmt.Errorf("Created file %s wasn't correctly synced to %s", filenameFrom, filenameTo)
@@ -225,6 +225,7 @@ func TestInitialSync(t *testing.T) {
225225
}
226226
if string(data) != fileContents {
227227
t.Errorf("Wrong file contentsin file %s, got %s, expected %s", localFile, string(data), fileContents)
228+
return
228229
}
229230

230231
data, err = ioutil.ReadFile(remoteFile)
@@ -234,6 +235,7 @@ func TestInitialSync(t *testing.T) {
234235
}
235236
if string(data) != fileContents {
236237
t.Errorf("Wrong file contentsin file %s, got %s, expected %s", remoteFile, string(data), fileContents)
238+
return
237239
}
238240
}
239241

@@ -281,7 +283,7 @@ func TestRunningSync(t *testing.T) {
281283
defer os.RemoveAll(remote)
282284
defer os.RemoveAll(local)
283285

284-
syncClient := createTestSyncClient(remote, local)
286+
syncClient := createTestSyncClient(local, remote)
285287
defer syncClient.Stop()
286288

287289
syncClient.errorChan = make(chan error)
@@ -307,54 +309,54 @@ func TestRunningSync(t *testing.T) {
307309
return
308310
}
309311

310-
// Start sync and do inital sync
312+
// Start sync and do initial sync
311313
syncClient.mainLoop()
312314

313315
// Create
314-
err = createFileAndWait(local, remote, "1", t)
316+
err = createFileAndWait(remote, local, "2")
315317
if err != nil {
316318
t.Error(err)
317319
return
318320
}
319321

320-
err = createFileAndWait(remote, local, "2", t)
322+
err = createFileAndWait(local, remote, "1")
321323
if err != nil {
322324
t.Error(err)
323325
return
324326
}
325327

326-
err = createFolderAndWait(local, remote, "1", t)
328+
err = createFolderAndWait(local, remote, "1")
327329
if err != nil {
328330
t.Error(err)
329331
return
330332
}
331333

332-
err = createFolderAndWait(remote, local, "2", t)
334+
err = createFolderAndWait(remote, local, "2")
333335
if err != nil {
334336
t.Error(err)
335337
return
336338
}
337339

338340
// Remove
339-
err = removeFileAndWait(local, remote, "1", t)
341+
err = removeFileAndWait(local, remote, "1")
340342
if err != nil {
341343
t.Error(err)
342344
return
343345
}
344346

345-
err = removeFileAndWait(remote, local, "2", t)
347+
err = removeFileAndWait(remote, local, "2")
346348
if err != nil {
347349
t.Error(err)
348350
return
349351
}
350352

351-
err = removeFolderAndWait(local, remote, "1", t)
353+
err = removeFolderAndWait(local, remote, "1")
352354
if err != nil {
353355
t.Error(err)
354356
return
355357
}
356358

357-
err = removeFolderAndWait(remote, local, "2", t)
359+
err = removeFolderAndWait(remote, local, "2")
358360
if err != nil {
359361
t.Error(err)
360362
return

0 commit comments

Comments
 (0)