//go:build !ignore_autogenerated
// +build !ignore_autogenerated

/*
Copyright The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// Code generated by validation-gen. DO NOT EDIT.

package v1alpha1

import (
	context "context"
	fmt "fmt"

	storagev1alpha1 "k8s.io/api/storage/v1alpha1"
	equality "k8s.io/apimachinery/pkg/api/equality"
	operation "k8s.io/apimachinery/pkg/api/operation"
	safe "k8s.io/apimachinery/pkg/api/safe"
	validate "k8s.io/apimachinery/pkg/api/validate"
	v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	validation "k8s.io/apimachinery/pkg/apis/meta/v1/validation"
	runtime "k8s.io/apimachinery/pkg/runtime"
	field "k8s.io/apimachinery/pkg/util/validation/field"
)

func init() { localSchemeBuilder.Register(RegisterValidations) }

// RegisterValidations adds validation functions to the given scheme.
// Public to allow building arbitrary schemes.
func RegisterValidations(scheme *runtime.Scheme) error {
	// type CSIStorageCapacity
	scheme.AddValidationFunc(
		(*storagev1alpha1.CSIStorageCapacity)(nil),
		func(ctx context.Context, op operation.Operation, obj, oldObj interface{}) field.ErrorList {
			switch op.Request.SubresourcePath() {
			case "/":
				return Validate_CSIStorageCapacity(
					ctx, op, nil, /* fldPath */
					obj.(*storagev1alpha1.CSIStorageCapacity),
					safe.Cast[*storagev1alpha1.CSIStorageCapacity](oldObj))
			}
			return field.ErrorList{
				field.InternalError(nil, fmt.Errorf("no validation found for %T, subresource: %v", obj, op.Request.SubresourcePath())),
			}
		})
	// type VolumeAttachment
	scheme.AddValidationFunc(
		(*storagev1alpha1.VolumeAttachment)(nil),
		func(ctx context.Context, op operation.Operation, obj, oldObj interface{}) field.ErrorList {
			switch op.Request.SubresourcePath() {
			case "/", "/status":
				return Validate_VolumeAttachment(
					ctx, op, nil, /* fldPath */
					obj.(*storagev1alpha1.VolumeAttachment),
					safe.Cast[*storagev1alpha1.VolumeAttachment](oldObj))
			}
			return field.ErrorList{
				field.InternalError(nil, fmt.Errorf("no validation found for %T, subresource: %v", obj, op.Request.SubresourcePath())),
			}
		})
	// type VolumeAttributesClass
	scheme.AddValidationFunc(
		(*storagev1alpha1.VolumeAttributesClass)(nil),
		func(ctx context.Context, op operation.Operation, obj, oldObj interface{}) field.ErrorList {
			switch op.Request.SubresourcePath() {
			case "/":
				return Validate_VolumeAttributesClass(
					ctx, op, nil, /* fldPath */
					obj.(*storagev1alpha1.VolumeAttributesClass),
					safe.Cast[*storagev1alpha1.VolumeAttributesClass](oldObj))
			}
			return field.ErrorList{
				field.InternalError(nil, fmt.Errorf("no validation found for %T, subresource: %v", obj, op.Request.SubresourcePath())),
			}
		})
	return nil
}

// Validate_CSIStorageCapacity validates an instance of CSIStorageCapacity according
// to declarative validation rules in the API schema.
func Validate_CSIStorageCapacity(
	ctx context.Context, op operation.Operation, fldPath *field.Path,
	obj, oldObj *storagev1alpha1.CSIStorageCapacity) (errs field.ErrorList) {

	// field storagev1alpha1.CSIStorageCapacity.TypeMeta has no validation

	{ // field storagev1alpha1.CSIStorageCapacity.ObjectMeta
		fn := func(
			fldPath *field.Path,
			obj, oldObj *v1.ObjectMeta,
			oldValueCorrelated bool) (errs field.ErrorList) {
			// don't revalidate unchanged data
			if oldValueCorrelated && op.Type == operation.Update {
				if equality.Semantic.DeepEqual(obj, oldObj) {
					return nil
				}
			}
			// call the type's validation function
			errs = append(errs, validation.Validate_ObjectMeta(ctx, op, fldPath, obj, oldObj)...)
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *storagev1alpha1.CSIStorageCapacity) *v1.ObjectMeta {
				return &oldObj.ObjectMeta
			})
		errs = append(errs, fn(fldPath.Child("metadata"), &obj.ObjectMeta, oldVal, oldObj != nil)...)
	}

	// field storagev1alpha1.CSIStorageCapacity.NodeTopology has no validation
	// field storagev1alpha1.CSIStorageCapacity.StorageClassName has no validation
	// field storagev1alpha1.CSIStorageCapacity.Capacity has no validation
	// field storagev1alpha1.CSIStorageCapacity.MaximumVolumeSize has no validation
	return errs
}

// Validate_VolumeAttachment validates an instance of VolumeAttachment according
// to declarative validation rules in the API schema.
func Validate_VolumeAttachment(
	ctx context.Context, op operation.Operation, fldPath *field.Path,
	obj, oldObj *storagev1alpha1.VolumeAttachment) (errs field.ErrorList) {

	// field storagev1alpha1.VolumeAttachment.TypeMeta has no validation

	{ // field storagev1alpha1.VolumeAttachment.ObjectMeta
		fn := func(
			fldPath *field.Path,
			obj, oldObj *v1.ObjectMeta,
			oldValueCorrelated bool) (errs field.ErrorList) {
			// don't revalidate unchanged data
			if oldValueCorrelated && op.Type == operation.Update {
				if equality.Semantic.DeepEqual(obj, oldObj) {
					return nil
				}
			}
			// call the type's validation function
			errs = append(errs, validation.Validate_ObjectMeta(ctx, op, fldPath, obj, oldObj)...)
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *storagev1alpha1.VolumeAttachment) *v1.ObjectMeta {
				return &oldObj.ObjectMeta
			})
		errs = append(errs, fn(fldPath.Child("metadata"), &obj.ObjectMeta, oldVal, oldObj != nil)...)
	}

	{ // field storagev1alpha1.VolumeAttachment.Spec
		fn := func(
			fldPath *field.Path,
			obj, oldObj *storagev1alpha1.VolumeAttachmentSpec,
			oldValueCorrelated bool) (errs field.ErrorList) {
			// don't revalidate unchanged data
			if oldValueCorrelated && op.Type == operation.Update {
				if equality.Semantic.DeepEqual(obj, oldObj) {
					return nil
				}
			}
			// call field-attached validations
			earlyReturn := false
			if e := validate.Immutable(ctx, op, fldPath, obj, oldObj).MarkBeta().MarkShortCircuit(); len(e) != 0 {
				errs = append(errs, e...)
				earlyReturn = true
			}
			if earlyReturn {
				return // do not proceed
			}
			// call the type's validation function
			errs = append(errs, Validate_VolumeAttachmentSpec(ctx, op, fldPath, obj, oldObj)...)
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *storagev1alpha1.VolumeAttachment) *storagev1alpha1.VolumeAttachmentSpec {
				return &oldObj.Spec
			})
		errs = append(errs, fn(fldPath.Child("spec"), &obj.Spec, oldVal, oldObj != nil)...)
	}

	// field storagev1alpha1.VolumeAttachment.Status has no validation
	return errs
}

// Validate_VolumeAttachmentSpec validates an instance of VolumeAttachmentSpec according
// to declarative validation rules in the API schema.
func Validate_VolumeAttachmentSpec(
	ctx context.Context, op operation.Operation, fldPath *field.Path,
	obj, oldObj *storagev1alpha1.VolumeAttachmentSpec) (errs field.ErrorList) {

	{ // field storagev1alpha1.VolumeAttachmentSpec.Attacher
		fn := func(
			fldPath *field.Path,
			obj, oldObj *string,
			oldValueCorrelated bool) (errs field.ErrorList) {
			// don't revalidate unchanged data
			if oldValueCorrelated && op.Type == operation.Update {
				if obj == oldObj || (obj != nil && oldObj != nil && *obj == *oldObj) {
					return nil
				}
			}
			// call field-attached validations
			earlyReturn := false
			if e := validate.RequiredValue(ctx, op, fldPath, obj, oldObj).MarkBeta().MarkShortCircuit(); len(e) != 0 {
				errs = append(errs, e...)
				earlyReturn = true
			}
			if earlyReturn {
				return // do not proceed
			}
			if e := validate.LongNameCaseless(ctx, op, fldPath, obj, oldObj).MarkBeta(); len(e) != 0 {
				errs = append(errs, e...)
			}
			if e := validate.MaxLength(ctx, op, fldPath, obj, oldObj, 63).MarkBeta(); len(e) != 0 {
				errs = append(errs, e...)
			}
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *storagev1alpha1.VolumeAttachmentSpec) *string {
				return &oldObj.Attacher
			})
		errs = append(errs, fn(fldPath.Child("attacher"), &obj.Attacher, oldVal, oldObj != nil)...)
	}

	// field storagev1alpha1.VolumeAttachmentSpec.Source has no validation
	// field storagev1alpha1.VolumeAttachmentSpec.NodeName has no validation
	return errs
}

// Validate_VolumeAttributesClass validates an instance of VolumeAttributesClass according
// to declarative validation rules in the API schema.
func Validate_VolumeAttributesClass(
	ctx context.Context, op operation.Operation, fldPath *field.Path,
	obj, oldObj *storagev1alpha1.VolumeAttributesClass) (errs field.ErrorList) {

	// field storagev1alpha1.VolumeAttributesClass.TypeMeta has no validation

	{ // field storagev1alpha1.VolumeAttributesClass.ObjectMeta
		fn := func(
			fldPath *field.Path,
			obj, oldObj *v1.ObjectMeta,
			oldValueCorrelated bool) (errs field.ErrorList) {
			// don't revalidate unchanged data
			if oldValueCorrelated && op.Type == operation.Update {
				if equality.Semantic.DeepEqual(obj, oldObj) {
					return nil
				}
			}
			// call the type's validation function
			errs = append(errs, validation.Validate_ObjectMeta(ctx, op, fldPath, obj, oldObj)...)
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *storagev1alpha1.VolumeAttributesClass) *v1.ObjectMeta {
				return &oldObj.ObjectMeta
			})
		errs = append(errs, fn(fldPath.Child("metadata"), &obj.ObjectMeta, oldVal, oldObj != nil)...)
	}

	// field storagev1alpha1.VolumeAttributesClass.DriverName has no validation
	// field storagev1alpha1.VolumeAttributesClass.Parameters has no validation
	return errs
}
