Skip to content

Commit

Permalink
Implement #343
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianKramm committed Apr 25, 2019
1 parent 78e2e86 commit ccbba0c
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 39 deletions.
2 changes: 2 additions & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.devspace
32 changes: 16 additions & 16 deletions examples/minikube/devspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ images:
image: devspace
skipPush: true
deployments:
- name: devspace-app
helm:
chart:
name: ./chart
- name: devspace-app
helm:
chart:
name: ./chart
dev:
overrideImages:
- name: default
entrypoint:
- sleep
- "999999999999"
- name: default
entrypoint:
- sleep
- "999999999999"
ports:
- labelSelector:
app.kubernetes.io/component: default
forward:
- port: 3000
- labelSelector:
app.kubernetes.io/component: default
forward:
- port: 3000
sync:
- labelSelector:
app.kubernetes.io/component: default
excludePaths:
- node_modules
- labelSelector:
app.kubernetes.io/component: default
excludePaths:
- node_modules
cluster:
kubeContext: minikube
namespace: devspace
4 changes: 2 additions & 2 deletions pkg/devspace/builder/kaniko/build_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ func (b *Builder) getBuildPod(options *types.ImageBuildOptions, dockerfilePath s
}

// Extra flags
if b.kanikoOptions.ExtraFlags != nil {
for _, flag := range *b.kanikoOptions.ExtraFlags {
if b.kanikoOptions.Flags != nil {
for _, flag := range *b.kanikoOptions.Flags {
kanikoArgs = append(kanikoArgs, *flag)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/devspace/builder/kaniko/kaniko_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ func TestKanikoBuildWithEntrypointOverride(t *testing.T) {
// 1. Write test dockerfile and context to a temp folder
// 2. Create kubectl client
// 3. Create test namespace test-kaniko-build
// 4. Build image with kaniko, but don't push it (In kaniko options use "--no-push" as extra flag)
// 4. Build image with kaniko, but don't push it (In kaniko options use "--no-push" as flag)
// 5. Delete temp files & test namespace
}
3 changes: 2 additions & 1 deletion pkg/devspace/config/versions/latest/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type DockerConfig struct {
type KanikoConfig struct {
Cache *bool `yaml:"cache"`
SnapshotMode *string `yaml:"snapshotMode,omitempty"`
ExtraFlags *[]*string `yaml:"extraFlags,omitempty"`
Flags *[]*string `yaml:"flags,omitempty"`
Namespace *string `yaml:"namespace,omitempty"`
PullSecret *string `yaml:"pullSecret,omitempty"`
}
Expand Down Expand Up @@ -251,6 +251,7 @@ type SyncConfig struct {
LocalSubPath *string `yaml:"localSubPath,omitempty"`
ContainerPath *string `yaml:"containerPath,omitempty"`
ExcludePaths *[]string `yaml:"excludePaths,omitempty"`
WaitInitialSync *bool `yaml:"waitInitialSync,omitempty"`
DownloadExcludePaths *[]string `yaml:"downloadExcludePaths,omitempty"`
UploadExcludePaths *[]string `yaml:"uploadExcludePaths,omitempty"`
BandwidthLimits *BandwidthLimits `yaml:"bandwidthLimits,omitempty"`
Expand Down
40 changes: 32 additions & 8 deletions pkg/devspace/services/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func StartSyncFromCmd(client *kubernetes.Clientset, cmdParameter targetselector.
containerPath = "."
}

syncDone := make(chan bool)
syncConfig := &sync.SyncConfig{
Kubectl: client,
Pod: pod,
Expand All @@ -48,15 +49,20 @@ func StartSyncFromCmd(client *kubernetes.Clientset, cmdParameter targetselector.
DestPath: containerPath,
ExcludePaths: exclude,
CustomLog: log,
SyncDone: syncDone,
Verbose: false,
}

log.Donef("Sync started on %s <-> %s (Pod: %s/%s)", absLocalPath, containerPath, pod.Namespace, pod.Name)
err = syncConfig.Start(true)

err = syncConfig.Start()
if err != nil {
log.Fatalf("Sync error: %s", err.Error())
}

// Wait till sync is finished
<-syncDone

return nil
}

Expand Down Expand Up @@ -103,13 +109,23 @@ func StartSync(client *kubernetes.Clientset, verboseSync bool, log log.Logger) (
containerPath = *syncPath.ContainerPath
}

var upstreamInitialSyncDone chan bool
var downstreamInitialSyncDone chan bool

if syncPath.WaitInitialSync != nil && *syncPath.WaitInitialSync == true {
upstreamInitialSyncDone = make(chan bool)
downstreamInitialSyncDone = make(chan bool)
}

syncConfig := &sync.SyncConfig{
Kubectl: client,
Pod: pod,
Container: container,
WatchPath: absLocalPath,
DestPath: containerPath,
Verbose: verboseSync,
Kubectl: client,
Pod: pod,
Container: container,
WatchPath: absLocalPath,
DestPath: containerPath,
Verbose: verboseSync,
UpstreamInitialSyncDone: upstreamInitialSyncDone,
DownstreamInitialSyncDone: downstreamInitialSyncDone,
}

if syncPath.ExcludePaths != nil {
Expand All @@ -134,12 +150,20 @@ func StartSync(client *kubernetes.Clientset, verboseSync bool, log log.Logger) (
}
}

err = syncConfig.Start(false)
err = syncConfig.Start()
if err != nil {
log.Fatalf("Sync error: %s", err.Error())
}

log.Donef("Sync started on %s <-> %s (Pod: %s/%s)", absLocalPath, containerPath, pod.Namespace, pod.Name)

if syncPath.WaitInitialSync != nil && *syncPath.WaitInitialSync == true {
log.StartWait("Sync: waiting for intial sync to complete")
<-syncConfig.UpstreamInitialSyncDone
<-syncConfig.DownstreamInitialSyncDone
log.StopWait()
}

syncConfigs = append(syncConfigs, syncConfig)
}

Expand Down
37 changes: 26 additions & 11 deletions pkg/devspace/sync/sync_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ type SyncConfig struct {
UpstreamLimit int64
DownstreamLimit int64
Verbose bool
CustomLog log.Logger

// These channels can be used to listen for certain sync events
DownstreamInitialSyncDone chan bool
UpstreamInitialSyncDone chan bool
SyncDone chan bool

CustomLog log.Logger

fileIndex *fileIndex

Expand Down Expand Up @@ -158,7 +164,7 @@ func (s *SyncConfig) setup() error {
}

// Start starts a new sync instance
func (s *SyncConfig) Start(wait bool) error {
func (s *SyncConfig) Start() error {
err := s.setup()
if err != nil {
return errors.Trace(err)
Expand All @@ -175,11 +181,7 @@ func (s *SyncConfig) Start(wait bool) error {
return errors.Trace(err)
}

if wait {
s.mainLoop()
} else {
go s.mainLoop()
}
go s.mainLoop()

return nil
}
Expand Down Expand Up @@ -222,7 +224,7 @@ func (s *SyncConfig) mainLoop() {
go s.startUpstream()

// Start downstream and do initial sync
func() {
go func() {
defer s.Stop(nil)

err := s.initialSync()
Expand All @@ -234,6 +236,7 @@ func (s *SyncConfig) mainLoop() {
s.Logf("[Sync] Initial sync completed")
s.startDownstream()
}()

}

func (s *SyncConfig) startUpstream() {
Expand Down Expand Up @@ -291,9 +294,14 @@ func (s *SyncConfig) initialSync() error {
return errors.Trace(err)
}

if len(localChanges) > 0 {
go s.sendChangesToUpstream(localChanges)
}
// Upstream initial sync
go func() {
s.sendChangesToUpstream(localChanges)

if s.UpstreamInitialSyncDone != nil {
close(s.UpstreamInitialSyncDone)
}
}()

if len(fileMapClone) > 0 {
remoteChanges := make([]*fileInformation, 0, len(fileMapClone))
Expand All @@ -307,6 +315,10 @@ func (s *SyncConfig) initialSync() error {
}
}

if s.DownstreamInitialSyncDone != nil {
close(s.DownstreamInitialSyncDone)
}

return nil
}

Expand Down Expand Up @@ -485,6 +497,9 @@ func (s *SyncConfig) Stop(fatalError error) {
}

s.Logln("[Sync] Sync stopped")
if s.SyncDone != nil {
close(s.SyncDone)
}

if fatalError != nil {
s.Error(fatalError)
Expand Down

0 comments on commit ccbba0c

Please sign in to comment.