Skip to content

Commit

Permalink
Merge branch 'main' into feat/better-err-msg-adding-chart-during-init
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwelke committed May 9, 2024
2 parents 514e395 + c133df9 commit 51a6de1
Show file tree
Hide file tree
Showing 16 changed files with 148 additions and 18 deletions.
2 changes: 1 addition & 1 deletion cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func (cmd *RunCmd) LoadCommandsConfig(f factory.Factory, configLoader loader.Con
if client != nil {
// If the current kube context or namespace is different than old,
// show warnings and reset kube client if necessary
client, err = kubectl.CheckKubeContext(client, localCache, false, false, false, log)
client, err = kubectl.CheckKubeContext(client, localCache, cmd.NoWarn, cmd.SwitchContext, false, log)
if err != nil {
log.Debugf("Unable to verify kube context %v", err)
client = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
##### `initialSync` <span className="config-field-required" data-required="false">required</span> <span className="config-field-type">string</span> <span className="config-field-default"></span> <span className="config-field-enum"></span> {#dev-containers-sync-initialSync}

InitialSync defines the initial sync strategy to use when this sync starts. Defaults to mirrorLocal
You can completely disable this using the `initialSync: disabled` option.

</summary>

Expand Down
6 changes: 3 additions & 3 deletions docs/pages/configuration/dev/connections/file-sync.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,10 @@ The `initialSync` option expects a string with an initial sync strategy. The fol
3. resolves all file conflicts (different content on local filesystem than inside the container) by preferring the newest file (i.e. compares last modified timestamps and replaces all outdated files)

`keepAll` merges local and remote filesystem without resolving any conflicts
1. uploads all files which are existing on the local filesystem but are missing within the container
2. downloads all files which are existing inside the container but are missing on the local filesystem

1. uploads all files which are existing on the local filesystem but are missing within the container
2. downloads all files which are existing inside the container but are missing on the local filesystem

`disabled` disabled the initial sync completely

```yaml
deployments:
Expand Down
72 changes: 70 additions & 2 deletions e2e/tests/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package sync

import (
"context"
"github.com/onsi/ginkgo/v2"
"github.com/pkg/errors"
"os"
"path/filepath"
"sync"
"time"

"github.com/onsi/ginkgo/v2"
"github.com/pkg/errors"

"github.com/loft-sh/devspace/cmd"
"github.com/loft-sh/devspace/cmd/flags"
"github.com/loft-sh/devspace/e2e/framework"
Expand Down Expand Up @@ -774,4 +775,71 @@ var _ = DevSpaceDescribe("sync", func() {
// wait for the command to finish
waitGroup.Wait()
})

ginkgo.It("devspace sync should work with initialSync:disabled", func() {
tempDir, err := framework.CopyToTempDir("tests/sync/testdata/sync-initial-disabled")
framework.ExpectNoError(err)
defer framework.CleanupTempDir(initialDir, tempDir)

ns, err := kubeClient.CreateNamespace("sync")
framework.ExpectNoError(err)
defer func() {
err := kubeClient.DeleteNamespace(ns)
framework.ExpectNoError(err)
}()

// deploy app to sync
deployCmd := &cmd.RunPipelineCmd{
GlobalFlags: &flags.GlobalFlags{
NoWarn: true,
Namespace: ns,
ConfigPath: "devspace.yaml",
},
Pipeline: "deploy",
}
err = deployCmd.RunDefault(f)
framework.ExpectNoError(err)

cancelCtx, stop := context.WithCancel(context.Background())
defer stop()

// sync command
syncCmd := &cmd.SyncCmd{
GlobalFlags: &flags.GlobalFlags{
NoWarn: true,
Namespace: ns,
ConfigPath: "devspace.yaml",
},
Wait: true,
Ctx: cancelCtx,
}

// start the command
waitGroup := sync.WaitGroup{}
waitGroup.Add(1)
go func() {
defer ginkgo.GinkgoRecover()
defer waitGroup.Done()
err = syncCmd.Run(f)
framework.ExpectNoError(err)
}()

// check that node_modules folder was not synced
framework.ExpectRemoteFileNotFound("alpine", ns, "/app/node_modules")

// check that included file was not synced
framework.ExpectRemoteFileNotFound("alpine", ns, "/app/syncme/file.txt")

// write a file and check that it got synced
payload := randutil.GenerateRandomString(10000)
err = os.WriteFile(filepath.Join(tempDir, "watching.txt"), []byte(payload), 0666)
framework.ExpectNoError(err)
framework.ExpectRemoteFileContents("alpine", ns, "/app/watching.txt", payload)

// stop command
stop()

// wait for the command to finish
waitGroup.Wait()
})
})
25 changes: 25 additions & 0 deletions e2e/tests/sync/testdata/sync-initial-disabled/devspace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: v2beta1
vars:
IMAGE: alpine
deployments:
test:
helm:
chart:
name: component-chart
repo: https://charts.devspace.sh
values:
containers:
- image: ${IMAGE}
command: ["sleep"]
args: ["999999999999"]
pipelines:
deploy: |-
run_dependencies --all
create_deployments --all
echo "dep2" >> out.txt
dev:
test:
imageSelector: ${IMAGE}
sync:
- path: ./:/app
initialSync: disabled

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I will be synced
1 change: 1 addition & 0 deletions pkg/devspace/config/versions/latest/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,7 @@ const (
InitialSyncStrategyPreferRemote InitialSyncStrategy = "preferRemote"
InitialSyncStrategyPreferNewest InitialSyncStrategy = "preferNewest"
InitialSyncStrategyKeepAll InitialSyncStrategy = "keepAll"
InitialSyncStrategyDisabled InitialSyncStrategy = "disabled"
)

// InitialSyncCompareBy is the type of how a change should be determined during the initial sync
Expand Down
1 change: 1 addition & 0 deletions pkg/devspace/config/versions/v1beta10/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,7 @@ const (
InitialSyncStrategyPreferRemote InitialSyncStrategy = "preferRemote"
InitialSyncStrategyPreferNewest InitialSyncStrategy = "preferNewest"
InitialSyncStrategyKeepAll InitialSyncStrategy = "keepAll"
InitialSyncStrategyDisabled InitialSyncStrategy = "disabled"
)

// InitialSyncCompareBy is the type of how a change should be determined during the initial sync
Expand Down
1 change: 1 addition & 0 deletions pkg/devspace/config/versions/v1beta11/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,7 @@ const (
InitialSyncStrategyPreferRemote InitialSyncStrategy = "preferRemote"
InitialSyncStrategyPreferNewest InitialSyncStrategy = "preferNewest"
InitialSyncStrategyKeepAll InitialSyncStrategy = "keepAll"
InitialSyncStrategyDisabled InitialSyncStrategy = "disabled"
)

// InitialSyncCompareBy is the type of how a change should be determined during the initial sync
Expand Down
1 change: 1 addition & 0 deletions pkg/devspace/config/versions/v1beta7/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ const (
InitialSyncStrategyPreferRemote InitialSyncStrategy = "preferRemote"
InitialSyncStrategyPreferNewest InitialSyncStrategy = "preferNewest"
InitialSyncStrategyKeepAll InitialSyncStrategy = "keepAll"
InitialSyncStrategyDisabled InitialSyncStrategy = "disabled"
)

// BandwidthLimits defines the struct for specifying the sync bandwidth limits
Expand Down
1 change: 1 addition & 0 deletions pkg/devspace/config/versions/v1beta8/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ const (
InitialSyncStrategyPreferRemote InitialSyncStrategy = "preferRemote"
InitialSyncStrategyPreferNewest InitialSyncStrategy = "preferNewest"
InitialSyncStrategyKeepAll InitialSyncStrategy = "keepAll"
InitialSyncStrategyDisabled InitialSyncStrategy = "disabled"
)

// BandwidthLimits defines the struct for specifying the sync bandwidth limits
Expand Down
1 change: 1 addition & 0 deletions pkg/devspace/config/versions/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func ValidInitialSyncStrategy(strategy latest.InitialSyncStrategy) bool {
strategy == latest.InitialSyncStrategyKeepAll ||
strategy == latest.InitialSyncStrategyPreferLocal ||
strategy == latest.InitialSyncStrategyPreferRemote ||
strategy == latest.InitialSyncStrategyDisabled ||
strategy == latest.InitialSyncStrategyPreferNewest
}

Expand Down
14 changes: 9 additions & 5 deletions pkg/devspace/configure/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"context"
"errors"
"fmt"
"mvdan.cc/sh/v3/expand"
"net/http"
"net/url"
"os"
"path"
"path/filepath"
"strings"

"mvdan.cc/sh/v3/expand"

"github.com/loft-sh/devspace/pkg/devspace/deploy/deployer/helm"
"github.com/loft-sh/devspace/pkg/devspace/pipeline/engine"
"github.com/sirupsen/logrus"
Expand All @@ -37,11 +38,14 @@ func (m *manager) AddKubectlDeployment(deploymentName string, isKustomization bo
}

if isKustomization {
stat, err := os.Stat(path.Join(value, "kustomization.yaml"))
if err == nil && !stat.IsDir() {
return nil
fileNames := []string{"kustomization.yaml", "kustomization.yml"}
for _, fileName := range fileNames {
stat, err := os.Stat(path.Join(value, fileName))
if err == nil && !stat.IsDir() {
return nil
}
}
return fmt.Errorf("path `%s` is not a Kustomization (kustomization.yaml missing)", value)
return fmt.Errorf("path `%s` is not a Kustomization (kustomization.yaml or kustomization.yml missing)", value)
} else {
matches, err := filepath.Glob(value)
if err != nil {
Expand Down
11 changes: 6 additions & 5 deletions pkg/devspace/sync/initial.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package sync

import (
"os"
"path"
"path/filepath"

"github.com/loft-sh/devspace/helper/remote"
"github.com/loft-sh/devspace/helper/server/ignoreparser"
"github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
"github.com/loft-sh/devspace/pkg/util/fsutil"
"github.com/loft-sh/devspace/pkg/util/log"
"os"
"path"
"path/filepath"

"github.com/pkg/errors"
)
Expand Down Expand Up @@ -62,7 +63,7 @@ func (i *initialSyncer) Run(remoteState map[string]*FileInformation, localState

// Upstream initial sync
go func() {
if !i.o.UpstreamDisabled {
if !i.o.UpstreamDisabled && i.o.Strategy != latest.InitialSyncStrategyDisabled {
// Remove remote if mirror local
if len(download) > 0 && i.o.Strategy == latest.InitialSyncStrategyMirrorLocal {
deleteRemote := make([]*FileInformation, 0, len(download))
Expand Down Expand Up @@ -103,7 +104,7 @@ func (i *initialSyncer) Run(remoteState map[string]*FileInformation, localState
}()

// Download changes if enabled
if !i.o.DownstreamDisabled {
if !i.o.DownstreamDisabled && i.o.Strategy != latest.InitialSyncStrategyDisabled {
// Remove local if mirror remote
if len(upload) > 0 && i.o.Strategy == latest.InitialSyncStrategyMirrorRemote {
remoteChanges := make([]*remote.Change, 0, len(upload))
Expand Down
12 changes: 10 additions & 2 deletions pkg/devspace/sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,13 +313,21 @@ func (s *Sync) initialSync(onInitUploadDone chan struct{}, onInitDownloadDone ch
}

if onInitUploadDone != nil {
s.log.Info("Upstream - Initial sync completed")
if s.Options.InitialSync == latest.InitialSyncStrategyDisabled {
s.log.Info("Upstream - Initial sync disabled")
} else {
s.log.Info("Upstream - Initial sync completed")
}
close(onInitUploadDone)
}
},
DownstreamDone: func() {
if onInitDownloadDone != nil {
s.log.Info("Downstream - Initial sync completed")
if s.Options.InitialSync == latest.InitialSyncStrategyDisabled {
s.log.Info("Downstream - Initial sync disabled")
} else {
s.log.Info("Downstream - Initial sync completed")
}
close(onInitDownloadDone)
}
},
Expand Down

0 comments on commit 51a6de1

Please sign in to comment.