mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Merge pull request #99835 from chendave/args
Move VolumeBinding plugin args validation to apis/config/validation
This commit is contained in:
commit
027d9e6c25
@ -298,3 +298,15 @@ func ValidateNodeAffinityArgs(args *config.NodeAffinityArgs) error {
|
|||||||
}
|
}
|
||||||
return errors.Flatten(errors.NewAggregate(errs))
|
return errors.Flatten(errors.NewAggregate(errs))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ValidateVolumeBindingArgs validates that VolumeBindingArgs are set correctly.
|
||||||
|
func ValidateVolumeBindingArgs(args *config.VolumeBindingArgs) error {
|
||||||
|
var path *field.Path
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if args.BindTimeoutSeconds < 0 {
|
||||||
|
err = field.Invalid(path.Child("bindTimeoutSeconds"), args.BindTimeoutSeconds, "invalid BindTimeoutSeconds, should not be a negative value")
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
@ -945,3 +945,42 @@ func TestValidateNodeAffinityArgs(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestValidateVolumeBindingArgs(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
name string
|
||||||
|
args config.VolumeBindingArgs
|
||||||
|
wantErr error
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "zero is a valid config",
|
||||||
|
args: config.VolumeBindingArgs{
|
||||||
|
BindTimeoutSeconds: 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "positive value is valid config",
|
||||||
|
args: config.VolumeBindingArgs{
|
||||||
|
BindTimeoutSeconds: 10,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "negative value is invalid config ",
|
||||||
|
args: config.VolumeBindingArgs{
|
||||||
|
BindTimeoutSeconds: -10,
|
||||||
|
},
|
||||||
|
wantErr: &field.Error{
|
||||||
|
Type: field.ErrorTypeInvalid,
|
||||||
|
Field: "bindTimeoutSeconds",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tc := range cases {
|
||||||
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
|
err := ValidateVolumeBindingArgs(&tc.args)
|
||||||
|
if diff := cmp.Diff(tc.wantErr, err, ignoreBadValueDetail); diff != "" {
|
||||||
|
t.Errorf("ValidateVolumeBindingArgs returned err (-want,+got):\n%s", diff)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -32,6 +32,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/controller/volume/scheduling"
|
"k8s.io/kubernetes/pkg/controller/volume/scheduling"
|
||||||
"k8s.io/kubernetes/pkg/features"
|
"k8s.io/kubernetes/pkg/features"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/apis/config"
|
"k8s.io/kubernetes/pkg/scheduler/apis/config"
|
||||||
|
"k8s.io/kubernetes/pkg/scheduler/apis/config/validation"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/framework"
|
"k8s.io/kubernetes/pkg/scheduler/framework"
|
||||||
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/helper"
|
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/helper"
|
||||||
)
|
)
|
||||||
@ -340,7 +341,7 @@ func New(plArgs runtime.Object, fh framework.Handle) (framework.Plugin, error) {
|
|||||||
if !ok {
|
if !ok {
|
||||||
return nil, fmt.Errorf("want args to be of type VolumeBindingArgs, got %T", plArgs)
|
return nil, fmt.Errorf("want args to be of type VolumeBindingArgs, got %T", plArgs)
|
||||||
}
|
}
|
||||||
if err := validateArgs(args); err != nil {
|
if err := validation.ValidateVolumeBindingArgs(args); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
podInformer := fh.SharedInformerFactory().Core().V1().Pods()
|
podInformer := fh.SharedInformerFactory().Core().V1().Pods()
|
||||||
@ -377,10 +378,3 @@ func New(plArgs runtime.Object, fh framework.Handle) (framework.Plugin, error) {
|
|||||||
scorer: scorer,
|
scorer: scorer,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateArgs(args *config.VolumeBindingArgs) error {
|
|
||||||
if args.BindTimeoutSeconds <= 0 {
|
|
||||||
return fmt.Errorf("invalid BindTimeoutSeconds: %d, must be positive integer", args.BindTimeoutSeconds)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user