change preempting to PreemptionPolicy
This commit is contained in:
@@ -19,6 +19,7 @@ package create
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
apiv1 "k8s.io/api/core/v1"
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||
"k8s.io/kubernetes/pkg/kubectl/generate"
|
||||
@@ -29,14 +30,17 @@ import (
|
||||
|
||||
var (
|
||||
pcLong = templates.LongDesc(i18n.T(`
|
||||
Create a priorityclass with the specified name, value, globalDefault,preempting and description`))
|
||||
Create a priorityclass with the specified name, value, globalDefault and description`))
|
||||
|
||||
pcExample = templates.Examples(i18n.T(`
|
||||
# Create a priorityclass named high-priority
|
||||
kubectl create priorityclass high-priority --value=1000 --description="high priority"
|
||||
|
||||
# Create a priorityclass named default-priority that considered as the global default priority
|
||||
kubectl create priorityclass default-priority --value=1000 --global-default=true --description="default priority"`))
|
||||
kubectl create priorityclass default-priority --value=1000 --global-default=true --description="default priority"
|
||||
|
||||
# Create a priorityclass named high-priority that can not preempt pods with lower priority
|
||||
kubectl create priorityclass high-priority --value=1000 --description="high priority" --preemption-policy="Never"`))
|
||||
)
|
||||
|
||||
// PriorityClassOpts holds the options for 'create priorityclass' sub command
|
||||
@@ -72,8 +76,7 @@ func NewCmdCreatePriorityClass(f cmdutil.Factory, ioStreams genericclioptions.IO
|
||||
cmd.Flags().Int32("value", 0, i18n.T("the value of this priority class."))
|
||||
cmd.Flags().Bool("global-default", false, i18n.T("global-default specifies whether this PriorityClass should be considered as the default priority."))
|
||||
cmd.Flags().String("description", "", i18n.T("description is an arbitrary string that usually provides guidelines on when this priority class should be used."))
|
||||
cmd.Flags().Bool("preempting", false, i18n.T("preempting specifies whether a pod with this PriorityClass could trigger a preemption process."))
|
||||
|
||||
cmd.Flags().String("preemption-policy", "", i18n.T("preemption-policy is the policy for preempting pods with lower priority."))
|
||||
return cmd
|
||||
}
|
||||
|
||||
@@ -88,11 +91,11 @@ func (o *PriorityClassOpts) Complete(f cmdutil.Factory, cmd *cobra.Command, args
|
||||
switch generatorName := cmdutil.GetFlagString(cmd, "generator"); generatorName {
|
||||
case generateversioned.PriorityClassV1GeneratorName:
|
||||
generator = &generateversioned.PriorityClassV1Generator{
|
||||
Name: name,
|
||||
Value: cmdutil.GetFlagInt32(cmd, "value"),
|
||||
GlobalDefault: cmdutil.GetFlagBool(cmd, "global-default"),
|
||||
Description: cmdutil.GetFlagString(cmd, "description"),
|
||||
Preempting: cmdutil.GetFlagBool(cmd, "preempting"),
|
||||
Name: name,
|
||||
Value: cmdutil.GetFlagInt32(cmd, "value"),
|
||||
GlobalDefault: cmdutil.GetFlagBool(cmd, "global-default"),
|
||||
Description: cmdutil.GetFlagString(cmd, "description"),
|
||||
PreemptionPolicy: apiv1.PreemptionPolicy(cmdutil.GetFlagString(cmd, "preemption-policy")),
|
||||
}
|
||||
default:
|
||||
return errUnsupportedGenerator(cmd, generatorName)
|
||||
|
@@ -56,9 +56,9 @@ func TestCreatePriorityClass(t *testing.T) {
|
||||
cmd.Flags().Set("value", "1000")
|
||||
cmd.Flags().Set("global-default", "true")
|
||||
cmd.Flags().Set("description", "my priority")
|
||||
cmd.Flags().Set("preempting", "true")
|
||||
cmd.Flags().Set("dry-run", "true")
|
||||
cmd.Flags().Set("output", outputFormat)
|
||||
cmd.Flags().Set("preemption-policy", "Never")
|
||||
|
||||
printFlags := genericclioptions.NewPrintFlags("created").WithTypeSetter(scheme.Scheme)
|
||||
printFlags.OutputFormat = &outputFormat
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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,
|
||||
},
|
||||
|
@@ -1444,7 +1444,6 @@ func TestUpdateRcWithRetries(t *testing.T) {
|
||||
one := int32(1)
|
||||
grace := int64(30)
|
||||
enableServiceLinks := corev1.DefaultEnableServiceLinks
|
||||
preempting := corev1.DefaultPreempting
|
||||
rc := &corev1.ReplicationController{
|
||||
TypeMeta: metav1.TypeMeta{
|
||||
APIVersion: "v1",
|
||||
@@ -1472,7 +1471,6 @@ func TestUpdateRcWithRetries(t *testing.T) {
|
||||
TerminationGracePeriodSeconds: &grace,
|
||||
SecurityContext: &corev1.PodSecurityContext{},
|
||||
EnableServiceLinks: &enableServiceLinks,
|
||||
Preempting: &preempting,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
Reference in New Issue
Block a user