mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 18:53:35 +00:00
vendor update for CSI 0.3.0
This commit is contained in:
24
vendor/k8s.io/kubernetes/pkg/apis/scheduling/validation/validation.go
generated
vendored
24
vendor/k8s.io/kubernetes/pkg/apis/scheduling/validation/validation.go
generated
vendored
@ -17,6 +17,7 @@ limitations under the License.
|
||||
package validation
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/validation/field"
|
||||
@ -24,22 +25,21 @@ import (
|
||||
"k8s.io/kubernetes/pkg/apis/scheduling"
|
||||
)
|
||||
|
||||
// ValidatePriorityClassName checks whether the given priority class name is valid.
|
||||
func ValidatePriorityClassName(name string, prefix bool) []string {
|
||||
var allErrs []string
|
||||
if strings.HasPrefix(name, scheduling.SystemPriorityClassPrefix) {
|
||||
allErrs = append(allErrs, "priority class names with '"+scheduling.SystemPriorityClassPrefix+"' prefix are reserved for system use only")
|
||||
}
|
||||
allErrs = append(allErrs, apivalidation.NameIsDNSSubdomain(name, prefix)...)
|
||||
return allErrs
|
||||
}
|
||||
|
||||
// ValidatePriorityClass tests whether required fields in the PriorityClass are
|
||||
// set correctly.
|
||||
func ValidatePriorityClass(pc *scheduling.PriorityClass) field.ErrorList {
|
||||
allErrs := field.ErrorList{}
|
||||
allErrs = append(allErrs, apivalidation.ValidateObjectMeta(&pc.ObjectMeta, false, ValidatePriorityClassName, field.NewPath("metadata"))...)
|
||||
// The "Value" field can be any valid integer. So, no need to validate.
|
||||
allErrs = append(allErrs, apivalidation.ValidateObjectMeta(&pc.ObjectMeta, false, apivalidation.NameIsDNSSubdomain, field.NewPath("metadata"))...)
|
||||
// If the priorityClass starts with a system prefix, it must be one of the
|
||||
// predefined system priority classes.
|
||||
if strings.HasPrefix(pc.Name, scheduling.SystemPriorityClassPrefix) {
|
||||
if is, err := scheduling.IsKnownSystemPriorityClass(pc); !is {
|
||||
allErrs = append(allErrs, field.Forbidden(field.NewPath("metadata", "name"), "priority class names with '"+scheduling.SystemPriorityClassPrefix+"' prefix are reserved for system use only. error: "+err.Error()))
|
||||
}
|
||||
} else if pc.Value > scheduling.HighestUserDefinablePriority {
|
||||
// Non-system critical priority classes are not allowed to have a value larger than HighestUserDefinablePriority.
|
||||
allErrs = append(allErrs, field.Forbidden(field.NewPath("value"), fmt.Sprintf("maximum allowed value of a user defined priority is %v", scheduling.HighestUserDefinablePriority)))
|
||||
}
|
||||
return allErrs
|
||||
}
|
||||
|
||||
|
19
vendor/k8s.io/kubernetes/pkg/apis/scheduling/validation/validation_test.go
generated
vendored
19
vendor/k8s.io/kubernetes/pkg/apis/scheduling/validation/validation_test.go
generated
vendored
@ -25,6 +25,7 @@ import (
|
||||
)
|
||||
|
||||
func TestValidatePriorityClass(t *testing.T) {
|
||||
spcs := scheduling.SystemPriorityClasses()
|
||||
successCases := map[string]scheduling.PriorityClass{
|
||||
"no description": {
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "tier1", Namespace: ""},
|
||||
@ -36,6 +37,12 @@ func TestValidatePriorityClass(t *testing.T) {
|
||||
GlobalDefault: false,
|
||||
Description: "Used for the highest priority pods.",
|
||||
},
|
||||
"system node critical": {
|
||||
ObjectMeta: metav1.ObjectMeta{Name: spcs[0].Name, Namespace: ""},
|
||||
Value: spcs[0].Value,
|
||||
GlobalDefault: spcs[0].GlobalDefault,
|
||||
Description: "system priority class 0",
|
||||
},
|
||||
}
|
||||
|
||||
for k, v := range successCases {
|
||||
@ -53,9 +60,15 @@ func TestValidatePriorityClass(t *testing.T) {
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "tier&1", Namespace: ""},
|
||||
Value: 100,
|
||||
},
|
||||
"invalid system name": {
|
||||
ObjectMeta: metav1.ObjectMeta{Name: scheduling.SystemPriorityClassPrefix + "test"},
|
||||
Value: 100,
|
||||
"incorrect system class name": {
|
||||
ObjectMeta: metav1.ObjectMeta{Name: spcs[0].Name, Namespace: ""},
|
||||
Value: 0,
|
||||
GlobalDefault: spcs[0].GlobalDefault,
|
||||
},
|
||||
"incorrect system class value": {
|
||||
ObjectMeta: metav1.ObjectMeta{Name: "system-something", Namespace: ""},
|
||||
Value: spcs[0].Value,
|
||||
GlobalDefault: spcs[0].GlobalDefault,
|
||||
},
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user