Skip to content

Commit

Permalink
Merge pull request #1597 from Ace-Tang/refactor_config
Browse files Browse the repository at this point in the history
refactor: move config file from cli into one places
  • Loading branch information
HusterWan authored Jun 27, 2018
2 parents b5b25ae + 2626f26 commit 8175d88
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 27 deletions.
11 changes: 7 additions & 4 deletions cli/blkio.go → apis/opts/config/blkio.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package config

import (
"fmt"
Expand Down Expand Up @@ -61,7 +61,8 @@ func (w *WeightDevice) Type() string {
return "value"
}

func (w *WeightDevice) value() []*types.WeightDevice {
// Value returns all values as type WeightDevice
func (w *WeightDevice) Value() []*types.WeightDevice {
var weightDevice []*types.WeightDevice
for _, v := range w.values {
weightDevice = append(weightDevice, v)
Expand Down Expand Up @@ -118,7 +119,8 @@ func (t *ThrottleBpsDevice) Type() string {
return "value"
}

func (t *ThrottleBpsDevice) value() []*types.ThrottleDevice {
// Value returns all values as type ThrottleDevice
func (t *ThrottleBpsDevice) Value() []*types.ThrottleDevice {
var throttleDevice []*types.ThrottleDevice
for _, v := range t.values {
throttleDevice = append(throttleDevice, v)
Expand Down Expand Up @@ -175,7 +177,8 @@ func (t *ThrottleIOpsDevice) Type() string {
return "value"
}

func (t *ThrottleIOpsDevice) value() []*types.ThrottleDevice {
// Value returns all values
func (t *ThrottleIOpsDevice) Value() []*types.ThrottleDevice {
var throttleDevice []*types.ThrottleDevice
for _, v := range t.values {
throttleDevice = append(throttleDevice, v)
Expand Down
8 changes: 4 additions & 4 deletions cli/blkio_test.go → apis/opts/config/blkio_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package config

import (
"reflect"
Expand Down Expand Up @@ -239,7 +239,7 @@ func TestWeightDevice_value(t *testing.T) {
w := &WeightDevice{
values: tt.fields.values,
}
if got := w.value(); !reflect.DeepEqual(got, tt.want) {
if got := w.Value(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("WeightDevice.value() = %v, want %v", got, tt.want)
}
})
Expand Down Expand Up @@ -462,7 +462,7 @@ func TestThrottleBpsDevice_value(t *testing.T) {
throttleBpsDevice := &ThrottleBpsDevice{
values: tt.fields.values,
}
if got := throttleBpsDevice.value(); !reflect.DeepEqual(got, tt.want) {
if got := throttleBpsDevice.Value(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("ThrottleBpsDevice.value() = %v, want %v", got, tt.want)
}
})
Expand Down Expand Up @@ -685,7 +685,7 @@ func TestThrottleIOpsDevice_value(t *testing.T) {
throttleIOpsDevice := &ThrottleIOpsDevice{
values: tt.fields.values,
}
if got := throttleIOpsDevice.value(); !reflect.DeepEqual(got, tt.want) {
if got := throttleIOpsDevice.Value(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("ThrottleIOpsDevice.value() = %v, want %v", got, tt.want)
}
})
Expand Down
2 changes: 1 addition & 1 deletion config/opt/runtime.go → apis/opts/config/runtime.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package opt
package config

import (
"fmt"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package opt
package config

import (
"testing"
Expand Down
6 changes: 3 additions & 3 deletions cli/ulimit.go → apis/opts/config/ulimit.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package config

import (
"fmt"
Expand Down Expand Up @@ -43,8 +43,8 @@ func (u *Ulimit) Type() string {
return "value"
}

// value return ulimit values as type ResourcesUlimitsItems0
func (u *Ulimit) value() []*types.Ulimit {
// Value return ulimit values as type Ulimit
func (u *Ulimit) Value() []*types.Ulimit {
var ulimit []*types.Ulimit
for _, ul := range u.values {
ulimit = append(ulimit, &types.Ulimit{
Expand Down
25 changes: 13 additions & 12 deletions cli/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"strings"

"github.com/alibaba/pouch/apis/opts"
"github.com/alibaba/pouch/apis/opts/config"
"github.com/alibaba/pouch/apis/types"

strfmt "github.com/go-openapi/strfmt"
Expand All @@ -26,11 +27,11 @@ type container struct {
disableNetworkFiles bool

blkioWeight uint16
blkioWeightDevice WeightDevice
blkioDeviceReadBps ThrottleBpsDevice
blkioDeviceWriteBps ThrottleBpsDevice
blkioDeviceReadIOps ThrottleIOpsDevice
blkioDeviceWriteIOps ThrottleIOpsDevice
blkioWeightDevice config.WeightDevice
blkioDeviceReadBps config.ThrottleBpsDevice
blkioDeviceWriteBps config.ThrottleBpsDevice
blkioDeviceReadIOps config.ThrottleIOpsDevice
blkioDeviceWriteIOps config.ThrottleIOpsDevice

cpushare int64
cpusetcpus string
Expand Down Expand Up @@ -69,7 +70,7 @@ type container struct {
oomScoreAdj int64
specAnnotation []string
cgroupParent string
ulimit Ulimit
ulimit config.Ulimit
pidsLimit int64
shmSize string

Expand Down Expand Up @@ -230,16 +231,16 @@ func (c *container) config() (*types.ContainerCreateConfig, error) {

// blkio
BlkioWeight: c.blkioWeight,
BlkioWeightDevice: c.blkioWeightDevice.value(),
BlkioDeviceReadBps: c.blkioDeviceReadBps.value(),
BlkioDeviceReadIOps: c.blkioDeviceReadIOps.value(),
BlkioDeviceWriteBps: c.blkioDeviceWriteBps.value(),
BlkioDeviceWriteIOps: c.blkioDeviceWriteIOps.value(),
BlkioWeightDevice: c.blkioWeightDevice.Value(),
BlkioDeviceReadBps: c.blkioDeviceReadBps.Value(),
BlkioDeviceReadIOps: c.blkioDeviceReadIOps.Value(),
BlkioDeviceWriteBps: c.blkioDeviceWriteBps.Value(),
BlkioDeviceWriteIOps: c.blkioDeviceWriteIOps.Value(),

Devices: deviceMappings,
IntelRdtL3Cbm: intelRdtL3Cbm,
CgroupParent: c.cgroupParent,
Ulimits: c.ulimit.value(),
Ulimits: c.ulimit.Value(),
PidsLimit: c.pidsLimit,
},
EnableLxcfs: c.enableLxcfs,
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"syscall"
"time"

"github.com/alibaba/pouch/config/opt"
optscfg "github.com/alibaba/pouch/apis/opts/config"
"github.com/alibaba/pouch/daemon"
"github.com/alibaba/pouch/daemon/config"
"github.com/alibaba/pouch/lxcfs"
Expand Down Expand Up @@ -112,7 +112,7 @@ func setupFlags(cmd *cobra.Command) {
flagSet.BoolVar(&cfg.EnableProfiler, "enable-profiler", false, "Set if pouchd setup profiler")
flagSet.StringVar(&cfg.Pidfile, "pidfile", "/var/run/pouch.pid", "Save daemon pid")
flagSet.IntVar(&cfg.OOMScoreAdjust, "oom-score-adj", -500, "Set the oom_score_adj for the daemon")
flagSet.Var(opt.NewRuntime(&cfg.Runtimes), "add-runtime", "register a OCI runtime to daemon")
flagSet.Var(optscfg.NewRuntime(&cfg.Runtimes), "add-runtime", "register a OCI runtime to daemon")

}

Expand Down

0 comments on commit 8175d88

Please sign in to comment.