diff --git a/apis/opts/cpu.go b/apis/opts/cpu.go deleted file mode 100644 index ea427ffb6..000000000 --- a/apis/opts/cpu.go +++ /dev/null @@ -1,27 +0,0 @@ -package opts - -import ( - "fmt" -) - -// ValidateCPUPeriod validates CPU options for container. -func ValidateCPUPeriod(period int64) error { - if period == 0 { - return nil - } - if period < 1000 || period > 1000000 { - return fmt.Errorf("CPU cfs period %d cannot be less than 1ms (i.e. 1000) or larger than 1s (i.e. 1000000)", period) - } - return nil -} - -// ValidateCPUQuota validates CPU options for container. -func ValidateCPUQuota(quota int64) error { - if quota == 0 { - return nil - } - if quota < 1000 { - return fmt.Errorf("CPU cfs quota %d cannot be less than 1ms (i.e. 1000)", quota) - } - return nil -} diff --git a/apis/opts/cpu_test.go b/apis/opts/cpu_test.go deleted file mode 100644 index f5ad5a775..000000000 --- a/apis/opts/cpu_test.go +++ /dev/null @@ -1,49 +0,0 @@ -package opts - -import ( - "math/rand" - "testing" -) - -func TestValidateCPUPeriod(t *testing.T) { - tests := []struct { - name string - period int64 - wantErr bool - }{ - {name: "test1", period: 0, wantErr: false}, - {name: "test2", period: 999, wantErr: true}, - {name: "test3", period: 1001, wantErr: false}, - {name: "test4", period: 1000001, wantErr: true}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - err := ValidateCPUPeriod(tt.period) - if (err != nil) != tt.wantErr { - t.Errorf("ValidateCPUPeriod() error = %v", err) - } - }) - } -} - -func TestValidateCPUQuota(t *testing.T) { - // TODO - tests := []struct { - name string - period int64 - wantErr bool - }{ - //测试用例 - {name: "test1", period: 0, wantErr: false}, - {name: "test2", period: rand.Int63n(1000), wantErr: true}, - {name: "test2", period: 1001, wantErr: false}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - err := ValidateCPUPeriod(tt.period) - if (err != nil) != tt.wantErr { - t.Errorf("ValidateCPUQuota() error = %v", err) //若不符合预期则报错 - } - }) - } -} diff --git a/apis/opts/intel_rdt.go b/apis/opts/intel_rdt.go index 5a5b33617..fe6eb516d 100644 --- a/apis/opts/intel_rdt.go +++ b/apis/opts/intel_rdt.go @@ -2,8 +2,8 @@ package opts // ParseIntelRdt parses inter-rdt params of container func ParseIntelRdt(intelRdtL3Cbm string) (string, error) { - // FIXME: add Intel RDT L3 Cbm validation + // FIXME(ningzhuo): add Intel RDT L3 Cbm validation return intelRdtL3Cbm, nil } -// TODO: ValidateInterRdt +// TODO(ningzhuo): ValidateInterRdt diff --git a/apis/opts/memory_swap.go b/apis/opts/memory_swap.go index 6ed75fd38..8d23f944c 100644 --- a/apis/opts/memory_swap.go +++ b/apis/opts/memory_swap.go @@ -16,9 +16,3 @@ func ParseMemorySwap(memorySwap string) (int64, error) { } return result, nil } - -// ValidateMemorySwap verifies the correctness of memory-swap. -func ValidateMemorySwap(memorySwap int64) error { - // TODO - return nil -} diff --git a/apis/opts/memory_swappiness.go b/apis/opts/memory_swappiness.go deleted file mode 100644 index 62edcd33c..000000000 --- a/apis/opts/memory_swappiness.go +++ /dev/null @@ -1,13 +0,0 @@ -package opts - -import "fmt" - -// TODO: ParseMemorySwappiness - -// ValidateMemorySwappiness verifies the correctness of memory-swappiness. -func ValidateMemorySwappiness(memorySwappiness int64) error { - if memorySwappiness != -1 && (memorySwappiness < 0 || memorySwappiness > 100) { - return fmt.Errorf("invalid memory swappiness: %d (its range is 0-100)", memorySwappiness) - } - return nil -} diff --git a/apis/opts/memory_swappiness_test.go b/apis/opts/memory_swappiness_test.go deleted file mode 100644 index 02327018b..000000000 --- a/apis/opts/memory_swappiness_test.go +++ /dev/null @@ -1,47 +0,0 @@ -package opts - -import ( - "fmt" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestValidateMemorySwappiness(t *testing.T) { - type TestCase struct { - input int64 - expected error - } - - testCases := []TestCase{ - { - input: -1, - expected: nil, - }, - { - input: 0, - expected: nil, - }, - { - input: 100, - expected: nil, - }, - { - input: 38, - expected: nil, - }, - { - input: -5, - expected: fmt.Errorf("invalid memory swappiness: %d (its range is 0-100)", -5), - }, - { - input: 200, - expected: fmt.Errorf("invalid memory swappiness: %d (its range is 0-100)", 200), - }, - } - - for _, testCase := range testCases { - err := ValidateMemorySwappiness(testCase.input) - assert.Equal(t, testCase.expected, err) - } -} diff --git a/apis/opts/oom_score.go b/apis/opts/oom_score.go deleted file mode 100644 index bc60dc691..000000000 --- a/apis/opts/oom_score.go +++ /dev/null @@ -1,12 +0,0 @@ -package opts - -import "fmt" - -// ValidateOOMScore validates oom score -func ValidateOOMScore(score int64) error { - if score < -1000 || score > 1000 { - return fmt.Errorf("oom-score-adj should be in range [-1000, 1000]") - } - - return nil -} diff --git a/apis/opts/oom_score_test.go b/apis/opts/oom_score_test.go deleted file mode 100644 index 79046a98b..000000000 --- a/apis/opts/oom_score_test.go +++ /dev/null @@ -1,48 +0,0 @@ -package opts - -import ( - "fmt" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestValidateOOMScore(t *testing.T) { - // TODO - type TestCase struct { - input int64 - expected error - } - - testCases := []TestCase{ - { - input: -1000, - expected: nil, - }, - { - input: 1000, - expected: nil, - }, - { - input: 0, - expected: nil, - }, - { - input: -2000, - expected: fmt.Errorf("oom-score-adj should be in range [-1000, 1000]"), - }, - { - input: 2000, - expected: fmt.Errorf("oom-score-adj should be in range [-1000, 1000]"), - }, - { - input: 200, - expected: nil, - }, - } - - for _, testCase := range testCases { - err := ValidateOOMScore(testCase.input) - assert.Equal(t, testCase.expected, err) - } -} diff --git a/apis/opts/spec_annotation.go b/apis/opts/spec_annotation.go index d856e8f1d..7ad54287e 100644 --- a/apis/opts/spec_annotation.go +++ b/apis/opts/spec_annotation.go @@ -20,10 +20,3 @@ func ParseAnnotation(annotations []string) (map[string]string, error) { return specAnnotation, nil } - -// ValidateAnnotation validate the correctness of spec annotation param of a container. -func ValidateAnnotation(annotations map[string]string) error { - // TODO - - return nil -} diff --git a/cli/container.go b/cli/container.go index 7ccd1834a..f4ec48799 100644 --- a/cli/container.go +++ b/cli/container.go @@ -95,10 +95,6 @@ func (c *container) config() (*types.ContainerCreateConfig, error) { return nil, err } - if err := opts.ValidateMemorySwappiness(c.memorySwappiness); err != nil { - return nil, err - } - memory, err := opts.ParseMemory(c.memory) if err != nil { return nil, err @@ -147,18 +143,6 @@ func (c *container) config() (*types.ContainerCreateConfig, error) { return nil, err } - if err := opts.ValidateOOMScore(c.oomScoreAdj); err != nil { - return nil, err - } - - if err := opts.ValidateCPUPeriod(c.cpuperiod); err != nil { - return nil, err - } - - if err := opts.ValidateCPUQuota(c.cpuquota); err != nil { - return nil, err - } - networkingConfig, networkMode, err := opts.ParseNetworks(c.networks) if err != nil { return nil, err