github.com/spotmaxtech/k8s-apimachinery-v0260@v0.0.1/pkg/apis/meta/internalversion/validation/validation.go (about) 1 /* 2 Copyright 2020 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package validation 18 19 import ( 20 "github.com/spotmaxtech/k8s-apimachinery-v0260/pkg/apis/meta/internalversion" 21 metav1 "github.com/spotmaxtech/k8s-apimachinery-v0260/pkg/apis/meta/v1" 22 "github.com/spotmaxtech/k8s-apimachinery-v0260/pkg/util/validation/field" 23 ) 24 25 // ValidateListOptions returns all validation errors found while validating the ListOptions. 26 func ValidateListOptions(options *internalversion.ListOptions) field.ErrorList { 27 allErrs := field.ErrorList{} 28 if match := options.ResourceVersionMatch; len(match) > 0 { 29 if options.Watch { 30 allErrs = append(allErrs, field.Forbidden(field.NewPath("resourceVersionMatch"), "resourceVersionMatch is forbidden for watch")) 31 } 32 if len(options.ResourceVersion) == 0 { 33 allErrs = append(allErrs, field.Forbidden(field.NewPath("resourceVersionMatch"), "resourceVersionMatch is forbidden unless resourceVersion is provided")) 34 } 35 if len(options.Continue) > 0 { 36 allErrs = append(allErrs, field.Forbidden(field.NewPath("resourceVersionMatch"), "resourceVersionMatch is forbidden when continue is provided")) 37 } 38 if match != metav1.ResourceVersionMatchExact && match != metav1.ResourceVersionMatchNotOlderThan { 39 allErrs = append(allErrs, field.NotSupported(field.NewPath("resourceVersionMatch"), match, []string{string(metav1.ResourceVersionMatchExact), string(metav1.ResourceVersionMatchNotOlderThan), ""})) 40 } 41 if match == metav1.ResourceVersionMatchExact && options.ResourceVersion == "0" { 42 allErrs = append(allErrs, field.Forbidden(field.NewPath("resourceVersionMatch"), "resourceVersionMatch \"exact\" is forbidden for resourceVersion \"0\"")) 43 } 44 } 45 return allErrs 46 }