Skip to content

Commit

Permalink
Minor refactor about variable name
Browse files Browse the repository at this point in the history
  • Loading branch information
Peng Yin committed Nov 16, 2017
1 parent d6511e5 commit 3ed5f1f
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
7 changes: 1 addition & 6 deletions agent/api/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,12 +485,7 @@ func (task *Task) SetConfigHostconfigBasedOnVersion(container *Container, config
return err
}

dockerAPIVersion_1_18, err := docker.NewAPIVersion("1.18")
if err != nil {
seelog.Errorf("Creating docker api version 1.18 failed, err: %v", err)
return err
}

dockerAPIVersion_1_18 := docker.APIVersion([]int{1, 18})
if dockerAPIVersion.GreaterThanOrEqualTo(dockerAPIVersion_1_18) {
// Set the memory and cpu in host config
if hc != nil {
Expand Down
4 changes: 2 additions & 2 deletions agent/api/task_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const (
memorySwappinessDefault = -1
)

var cpus = runtime.NumCPU() * 1024
var cpuShareScaleFactor = runtime.NumCPU() * 1024

// adjustForPlatform makes Windows-specific changes to the task after unmarshal
func (task *Task) adjustForPlatform(cfg *config.Config) {
Expand Down Expand Up @@ -62,7 +62,7 @@ func getCanonicalPath(path string) string {
// passed to Docker API.
func (task *Task) platformHostConfigOverride(hostConfig *docker.HostConfig) error {
task.overrideDefaultMemorySwappiness(hostConfig)
hostConfig.CPUPercent = hostConfig.CPUShares / int64(cpus)
hostConfig.CPUPercent = hostConfig.CPUShares / int64(cpuShareScaleFactor)
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion agent/api/task_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func TestWindowsPlatformHostConfigOverride(t *testing.T) {
hostConfig := &docker.HostConfig{CPUShares: 1024}

task.platformHostConfigOverride(hostConfig)
assert.Equal(t, int64(1024)/int64(cpus), hostConfig.CPUPercent)
assert.Equal(t, int64(1024)/int64(cpuShareScaleFactor), hostConfig.CPUPercent)
assert.EqualValues(t, expectedMemorySwappinessDefault, hostConfig.MemorySwappiness)
}

Expand Down

0 comments on commit 3ed5f1f

Please sign in to comment.