zz_generated.validations.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //go:build !ignore_autogenerated
  2. // +build !ignore_autogenerated
  3. /*
  4. Copyright The Kubernetes Authors.
  5. Licensed under the Apache License, Version 2.0 (the "License");
  6. you may not use this file except in compliance with the License.
  7. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. */
  15. // Code generated by validation-gen. DO NOT EDIT.
  16. package v1beta1
  17. import (
  18. context "context"
  19. fmt "fmt"
  20. operation "k8s.io/apimachinery/pkg/api/operation"
  21. safe "k8s.io/apimachinery/pkg/api/safe"
  22. validate "k8s.io/apimachinery/pkg/api/validate"
  23. runtime "k8s.io/apimachinery/pkg/runtime"
  24. field "k8s.io/apimachinery/pkg/util/validation/field"
  25. )
  26. func init() { localSchemeBuilder.Register(RegisterValidations) }
  27. // RegisterValidations adds validation functions to the given scheme.
  28. // Public to allow building arbitrary schemes.
  29. func RegisterValidations(scheme *runtime.Scheme) error {
  30. // type Scale
  31. scheme.AddValidationFunc((*Scale)(nil), func(ctx context.Context, op operation.Operation, obj, oldObj interface{}) field.ErrorList {
  32. switch op.Request.SubresourcePath() {
  33. case "/scale":
  34. return Validate_Scale(ctx, op, nil /* fldPath */, obj.(*Scale), safe.Cast[*Scale](oldObj))
  35. }
  36. return field.ErrorList{field.InternalError(nil, fmt.Errorf("no validation found for %T, subresource: %v", obj, op.Request.SubresourcePath()))}
  37. })
  38. return nil
  39. }
  40. // Validate_Scale validates an instance of Scale according
  41. // to declarative validation rules in the API schema.
  42. func Validate_Scale(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *Scale) (errs field.ErrorList) {
  43. // field Scale.TypeMeta has no validation
  44. // field Scale.ObjectMeta has no validation
  45. // field Scale.Spec
  46. errs = append(errs,
  47. func(fldPath *field.Path, obj, oldObj *ScaleSpec, oldValueCorrelated bool) (errs field.ErrorList) {
  48. // don't revalidate unchanged data
  49. if oldValueCorrelated && op.Type == operation.Update && (obj == oldObj || (obj != nil && oldObj != nil && *obj == *oldObj)) {
  50. return nil
  51. }
  52. // call the type's validation function
  53. errs = append(errs, Validate_ScaleSpec(ctx, op, fldPath, obj, oldObj)...)
  54. return
  55. }(fldPath.Child("spec"), &obj.Spec, safe.Field(oldObj, func(oldObj *Scale) *ScaleSpec { return &oldObj.Spec }), oldObj != nil)...)
  56. // field Scale.Status has no validation
  57. return errs
  58. }
  59. // Validate_ScaleSpec validates an instance of ScaleSpec according
  60. // to declarative validation rules in the API schema.
  61. func Validate_ScaleSpec(ctx context.Context, op operation.Operation, fldPath *field.Path, obj, oldObj *ScaleSpec) (errs field.ErrorList) {
  62. // field ScaleSpec.Replicas
  63. errs = append(errs,
  64. func(fldPath *field.Path, obj, oldObj *int32, oldValueCorrelated bool) (errs field.ErrorList) {
  65. // optional value-type fields with zero-value defaults are purely documentation
  66. // don't revalidate unchanged data
  67. if oldValueCorrelated && op.Type == operation.Update && (obj == oldObj || (obj != nil && oldObj != nil && *obj == *oldObj)) {
  68. return nil
  69. }
  70. // call field-attached validations
  71. errs = append(errs, validate.Minimum(ctx, op, fldPath, obj, oldObj, 0)...)
  72. return
  73. }(fldPath.Child("replicas"), &obj.Replicas, safe.Field(oldObj, func(oldObj *ScaleSpec) *int32 { return &oldObj.Replicas }), oldObj != nil)...)
  74. return errs
  75. }