mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-07 11:13:48 +00:00
Remove obsolete ErrorList Prefix logic
This commit is contained in:
parent
e6df0b1a24
commit
0fe29232eb
@ -53,7 +53,7 @@ func validateHorizontalPodAutoscalerSpec(autoscaler extensions.HorizontalPodAuto
|
|||||||
allErrs = append(allErrs, validation.NewInvalidError(fldPath.Child("cpuUtilization", "targetPercentage"), autoscaler.CPUUtilization.TargetPercentage, `must be greater than or equal to 1`))
|
allErrs = append(allErrs, validation.NewInvalidError(fldPath.Child("cpuUtilization", "targetPercentage"), autoscaler.CPUUtilization.TargetPercentage, `must be greater than or equal to 1`))
|
||||||
}
|
}
|
||||||
if refErrs := ValidateSubresourceReference(autoscaler.ScaleRef, fldPath.Child("scaleRef")); len(refErrs) > 0 {
|
if refErrs := ValidateSubresourceReference(autoscaler.ScaleRef, fldPath.Child("scaleRef")); len(refErrs) > 0 {
|
||||||
allErrs = append(allErrs, refErrs.Prefix("scaleRef")...)
|
allErrs = append(allErrs, refErrs...)
|
||||||
} else if autoscaler.ScaleRef.Subresource != "scale" {
|
} else if autoscaler.ScaleRef.Subresource != "scale" {
|
||||||
allErrs = append(allErrs, validation.NewNotSupportedError(fldPath.Child("scaleRef", "subresource"), autoscaler.ScaleRef.Subresource, []string{"scale"}))
|
allErrs = append(allErrs, validation.NewNotSupportedError(fldPath.Child("scaleRef", "subresource"), autoscaler.ScaleRef.Subresource, []string{"scale"}))
|
||||||
}
|
}
|
||||||
|
@ -181,28 +181,6 @@ func NewInternalError(field *FieldPath, err error) *Error {
|
|||||||
// ErrorList holds a set of errors.
|
// ErrorList holds a set of errors.
|
||||||
type ErrorList []*Error
|
type ErrorList []*Error
|
||||||
|
|
||||||
// Prefix adds a prefix to the Field of every Error in the list.
|
|
||||||
// Returns the list for convenience.
|
|
||||||
func (list ErrorList) Prefix(prefix string) ErrorList {
|
|
||||||
for i := range list {
|
|
||||||
err := list[i]
|
|
||||||
if strings.HasPrefix(err.Field, "[") {
|
|
||||||
err.Field = prefix + err.Field
|
|
||||||
} else if len(err.Field) != 0 {
|
|
||||||
err.Field = prefix + "." + err.Field
|
|
||||||
} else {
|
|
||||||
err.Field = prefix
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return list
|
|
||||||
}
|
|
||||||
|
|
||||||
// PrefixIndex adds an index to the Field of every Error in the list.
|
|
||||||
// Returns the list for convenience.
|
|
||||||
func (list ErrorList) PrefixIndex(index int) ErrorList {
|
|
||||||
return list.Prefix(fmt.Sprintf("[%d]", index))
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewErrorTypeMatcher returns an errors.Matcher that returns true
|
// NewErrorTypeMatcher returns an errors.Matcher that returns true
|
||||||
// if the provided error is a Error and has the provided ErrorType.
|
// if the provided error is a Error and has the provided ErrorType.
|
||||||
func NewErrorTypeMatcher(t ErrorType) utilerrors.Matcher {
|
func NewErrorTypeMatcher(t ErrorType) utilerrors.Matcher {
|
||||||
|
@ -132,63 +132,3 @@ func TestErrListFilter(t *testing.T) {
|
|||||||
t.Errorf("should filter")
|
t.Errorf("should filter")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestErrListPrefix(t *testing.T) {
|
|
||||||
testCases := []struct {
|
|
||||||
Err *Error
|
|
||||||
Expected string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
NewNotFoundError("[0].bar", "value"),
|
|
||||||
"foo[0].bar",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
NewInvalidError("field", "value", ""),
|
|
||||||
"foo.field",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
NewDuplicateError("", "value"),
|
|
||||||
"foo",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, testCase := range testCases {
|
|
||||||
errList := ErrorList{testCase.Err}
|
|
||||||
prefix := errList.Prefix("foo")
|
|
||||||
if prefix == nil || len(prefix) != len(errList) {
|
|
||||||
t.Errorf("Prefix should return self")
|
|
||||||
}
|
|
||||||
if e, a := testCase.Expected, errList[0].Field; e != a {
|
|
||||||
t.Errorf("expected %s, got %s", e, a)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestErrListPrefixIndex(t *testing.T) {
|
|
||||||
testCases := []struct {
|
|
||||||
Err *Error
|
|
||||||
Expected string
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
NewNotFoundError("[0].bar", "value"),
|
|
||||||
"[1][0].bar",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
NewInvalidError("field", "value", ""),
|
|
||||||
"[1].field",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
NewDuplicateError("", "value"),
|
|
||||||
"[1]",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
for _, testCase := range testCases {
|
|
||||||
errList := ErrorList{testCase.Err}
|
|
||||||
prefix := errList.PrefixIndex(1)
|
|
||||||
if prefix == nil || len(prefix) != len(errList) {
|
|
||||||
t.Errorf("PrefixIndex should return self")
|
|
||||||
}
|
|
||||||
if e, a := testCase.Expected, errList[0].Field; e != a {
|
|
||||||
t.Errorf("expected %s, got %s", e, a)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user