Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Gopkg.lock

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

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
[[constraint]]
name = "github.com/juju/ratelimit"
version = "v1.0.1"

[[constraint]]
name = "github.com/juju/errors"
revision = "22422dad46e14561a0854ad42497a75af9b61909"
Expand Down
12 changes: 12 additions & 0 deletions docs/docs/configuration/config.yaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,15 @@ To comfortably sync code to a DevSpace, the DevSpace CLI allows to configure rea
- `excludePaths` *string array* paths to exclude files/folders from sync in .gitignore syntax
- `downloadExcludePaths` *string array* paths to exclude files/folders from download in .gitignore syntax
- `uploadExcludePaths` *string array* paths to exclude files/folders from upload in .gitignore syntax
- `bandwidthLimits` *BandwidthLimits* the bandwidth limits to use for the syncpath

In the example above, the entire code within the project would be synchronized with the folder `/app` inside the DevSpace, with the exception of the `node_modules/` folder.

### devspace.sync[].bandwidthLimits
Bandwidth limits for the sync path:
- `upload` *string* kilobytes per second as upper limit to use for uploading files (e.g. 100 means 100 KByte per seconds)
- `download` *string* kilobytes per second as upper limit to use for downloading files (e.g. 100 means 100 KByte per seconds)

## images
This section of the config defines a map of images that can be used in the helm chart that is deployed during `devspace up`.

Expand Down Expand Up @@ -233,6 +239,12 @@ devSpace:
# Exclude node_modules from up and download
excludePaths:
- node_modules/
# Bandwidth limits for this sync path in Kbyte/s
bandwidthLimits:
# limit download speed to 100 Kbyte/s
download: 100
# limit upload speed to 1024 Kbyte/s
upload: 1024
# A map of images that should be build during devspace up
images:
default:
Expand Down
7 changes: 7 additions & 0 deletions pkg/devspace/config/v1/devspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,11 @@ type SyncConfig struct {
ExcludePaths *[]string `yaml:"excludePaths"`
DownloadExcludePaths *[]string `yaml:"downloadExcludePaths"`
UploadExcludePaths *[]string `yaml:"uploadExcludePaths"`
BandwidthLimits *BandwidthLimits `yaml:"bandwidthLimits,omitempty"`
}

// BandwidthLimits defines the struct for specifying the sync bandwidth limits
type BandwidthLimits struct {
Download *int64 `yaml:"download,omitempty"`
Upload *int64 `yaml:"upload,omitempty"`
}
10 changes: 10 additions & 0 deletions pkg/devspace/services/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ func StartSync(client *kubernetes.Clientset, verboseSync bool, log log.Logger) (
syncConfig.UploadExcludePaths = *syncPath.UploadExcludePaths
}

if syncPath.BandwidthLimits != nil {
if syncPath.BandwidthLimits.Download != nil {
syncConfig.DownstreamLimit = *syncPath.BandwidthLimits.Download * 1024
}

if syncPath.BandwidthLimits.Upload != nil {
syncConfig.UpstreamLimit = *syncPath.BandwidthLimits.Upload * 1024
}
}

err = syncConfig.Start()
if err != nil {
log.Fatalf("Sync error: %s", err.Error())
Expand Down
9 changes: 8 additions & 1 deletion pkg/devspace/sync/downstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"time"

"github.com/juju/errors"
"github.com/juju/ratelimit"

"github.com/covexo/devspace/pkg/devspace/kubectl"
)
Expand Down Expand Up @@ -438,8 +439,14 @@ func (d *downstream) downloadArchive(tarSize int64) (string, error) {

defer tempFile.Close()

// Apply rate limit if specified
var downloadReader io.Reader = d.stdoutPipe
if d.config.DownstreamLimit > 0 {
downloadReader = ratelimit.Reader(d.stdoutPipe, ratelimit.NewBucketWithRate(float64(d.config.DownstreamLimit), d.config.DownstreamLimit))
}

// Write From stdout to temp file
bytesRead, err := io.CopyN(tempFile, d.stdoutPipe, tarSize)
bytesRead, err := io.CopyN(tempFile, downloadReader, tarSize)
if err != nil {
return "", errors.Trace(err)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/devspace/sync/sync_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ type SyncConfig struct {
ExcludePaths []string
DownloadExcludePaths []string
UploadExcludePaths []string
UpstreamLimit int64
DownstreamLimit int64
Verbose bool

fileIndex *fileIndex
Expand Down
9 changes: 8 additions & 1 deletion pkg/devspace/sync/upstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/juju/errors"
"github.com/juju/ratelimit"

"github.com/covexo/devspace/pkg/devspace/kubectl"
"github.com/rjeczalik/notify"
Expand Down Expand Up @@ -329,8 +330,14 @@ func (u *upstream) uploadArchive(file *os.File, fileSize string, writtenFiles ma
return errors.Trace(err)
}

// Apply rate limit if specified
var uploadWriter io.Writer = u.stdinPipe
if u.config.UpstreamLimit > 0 {
uploadWriter = ratelimit.Writer(u.stdinPipe, ratelimit.NewBucketWithRate(float64(u.config.UpstreamLimit), u.config.UpstreamLimit))
}

// Send file through stdin to remote
_, err = io.Copy(u.stdinPipe, file)
_, err = io.Copy(uploadWriter, file)
if err != nil {
return errors.Trace(err)
}
Expand Down