change preempting to PreemptionPolicy

This commit is contained in:
wangqingcan
2019-05-31 06:28:21 +08:00
parent 5c9438c691
commit 52f3380ef3
101 changed files with 2100 additions and 1472 deletions

View File

@@ -19,6 +19,7 @@ package versioned
import (
"fmt"
apiv1 "k8s.io/api/core/v1"
scheduling "k8s.io/api/scheduling/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
@@ -27,11 +28,11 @@ import (
// PriorityClassV1Generator supports stable generation of a priorityClass.
type PriorityClassV1Generator struct {
Name string
Value int32
GlobalDefault bool
Description string
Preempting bool
Name string
Value int32
GlobalDefault bool
Description string
PreemptionPolicy apiv1.PreemptionPolicy
}
// Ensure it supports the generator pattern that uses parameters specified during construction.
@@ -43,9 +44,10 @@ func (PriorityClassV1Generator) ParamNames() []generate.GeneratorParam {
{Name: "value", Required: true},
{Name: "global-default", Required: false},
{Name: "description", Required: false},
{Name: "preempting", Required: false},
{Name: "preemption-policy", Required: false},
}
}
func (s PriorityClassV1Generator) Generate(params map[string]interface{}) (runtime.Object, error) {
if err := generate.ValidateParams(s.ParamNames(), params); err != nil {
return nil, err
@@ -71,12 +73,9 @@ func (s PriorityClassV1Generator) Generate(params map[string]interface{}) (runti
return nil, fmt.Errorf("expected string, found %v", description)
}
Preempting, found := params["preempting"].(bool)
if !found {
return nil, fmt.Errorf("expected bool, found %v", Preempting)
}
preemptionPolicy := apiv1.PreemptionPolicy(params["preemption-policy"].(string))
delegate := &PriorityClassV1Generator{Name: name, Value: value, GlobalDefault: globalDefault, Description: description, Preempting: Preempting}
delegate := &PriorityClassV1Generator{Name: name, Value: value, GlobalDefault: globalDefault, Description: description, PreemptionPolicy: preemptionPolicy}
return delegate.StructuredGenerate()
}
@@ -86,9 +85,9 @@ func (s *PriorityClassV1Generator) StructuredGenerate() (runtime.Object, error)
ObjectMeta: metav1.ObjectMeta{
Name: s.Name,
},
Value: s.Value,
GlobalDefault: s.GlobalDefault,
Description: s.Description,
Preempting: &s.Preempting,
Value: s.Value,
GlobalDefault: s.GlobalDefault,
Description: s.Description,
PreemptionPolicy: &s.PreemptionPolicy,
}, nil
}

View File

@@ -17,6 +17,7 @@ limitations under the License.
package versioned
import (
apiv1 "k8s.io/api/core/v1"
scheduling "k8s.io/api/scheduling/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -25,8 +26,10 @@ import (
)
func TestPriorityClassV1Generator(t *testing.T) {
true := true
false := false
var (
preemptLowerPriority = apiv1.PreemptLowerPriority
preemptNever = apiv1.PreemptNever
)
tests := []struct {
name string
params map[string]interface{}
@@ -36,70 +39,70 @@ func TestPriorityClassV1Generator(t *testing.T) {
{
name: "test valid case",
params: map[string]interface{}{
"name": "foo",
"value": int32(1000),
"global-default": false,
"description": "high priority class",
"preempting": false,
"name": "foo",
"value": int32(1000),
"global-default": false,
"description": "high priority class",
"preemption-policy": "PreemptLowerPriority",
},
expected: &scheduling.PriorityClass{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
},
Value: int32(1000),
GlobalDefault: false,
Description: "high priority class",
Preempting: &false,
Value: int32(1000),
GlobalDefault: false,
Description: "high priority class",
PreemptionPolicy: &preemptLowerPriority,
},
expectErr: false,
},
{
name: "test valid case that field non-preempting is set",
params: map[string]interface{}{
"name": "foo",
"value": int32(1000),
"global-default": false,
"description": "high priority class",
"preempting": true,
"name": "foo",
"value": int32(1000),
"global-default": false,
"description": "high priority class",
"preemption-policy": "Never",
},
expected: &scheduling.PriorityClass{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
},
Value: int32(1000),
GlobalDefault: false,
Description: "high priority class",
Preempting: &true,
Value: int32(1000),
GlobalDefault: false,
Description: "high priority class",
PreemptionPolicy: &preemptNever,
},
expectErr: false,
},
{
name: "test valid case that as default priority",
params: map[string]interface{}{
"name": "foo",
"value": int32(1000),
"global-default": true,
"description": "high priority class",
"preempting": false,
"name": "foo",
"value": int32(1000),
"global-default": true,
"description": "high priority class",
"preemption-policy": "PreemptLowerPriority",
},
expected: &scheduling.PriorityClass{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
},
Value: int32(1000),
GlobalDefault: true,
Description: "high priority class",
Preempting: &false,
Value: int32(1000),
GlobalDefault: true,
Description: "high priority class",
PreemptionPolicy: &preemptLowerPriority,
},
expectErr: false,
},
{
name: "test missing required param",
params: map[string]interface{}{
"name": "foo",
"global-default": true,
"description": "high priority class",
"preempting": false,
"name": "foo",
"global-default": true,
"description": "high priority class",
"preemption-policy": "PreemptLowerPriority",
},
expectErr: true,
},