//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 v1beta1

import (
	context "context"
	fmt "fmt"

	appsv1beta1 "k8s.io/api/apps/v1beta1"
	apicorev1 "k8s.io/api/core/v1"
	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"
	corev1 "k8s.io/kubernetes/pkg/apis/core/v1"
)

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 ControllerRevision
	scheme.AddValidationFunc(
		(*appsv1beta1.ControllerRevision)(nil),
		func(ctx context.Context, op operation.Operation, obj, oldObj interface{}) field.ErrorList {
			switch op.Request.SubresourcePath() {
			case "/":
				return Validate_ControllerRevision(
					ctx, op, nil, /* fldPath */
					obj.(*appsv1beta1.ControllerRevision),
					safe.Cast[*appsv1beta1.ControllerRevision](oldObj))
			}
			return field.ErrorList{
				field.InternalError(nil, fmt.Errorf("no validation found for %T, subresource: %v", obj, op.Request.SubresourcePath())),
			}
		})
	// type Deployment
	scheme.AddValidationFunc(
		(*appsv1beta1.Deployment)(nil),
		func(ctx context.Context, op operation.Operation, obj, oldObj interface{}) field.ErrorList {
			switch op.Request.SubresourcePath() {
			case "/", "/scale", "/status":
				return Validate_Deployment(
					ctx, op, nil, /* fldPath */
					obj.(*appsv1beta1.Deployment),
					safe.Cast[*appsv1beta1.Deployment](oldObj))
			}
			return field.ErrorList{
				field.InternalError(nil, fmt.Errorf("no validation found for %T, subresource: %v", obj, op.Request.SubresourcePath())),
			}
		})
	// type Scale
	scheme.AddValidationFunc(
		(*appsv1beta1.Scale)(nil),
		func(ctx context.Context, op operation.Operation, obj, oldObj interface{}) field.ErrorList {
			switch op.Request.SubresourcePath() {
			case "/scale":
				return Validate_Scale(
					ctx, op, nil, /* fldPath */
					obj.(*appsv1beta1.Scale),
					safe.Cast[*appsv1beta1.Scale](oldObj))
			}
			return field.ErrorList{
				field.InternalError(nil, fmt.Errorf("no validation found for %T, subresource: %v", obj, op.Request.SubresourcePath())),
			}
		})
	// type StatefulSet
	scheme.AddValidationFunc(
		(*appsv1beta1.StatefulSet)(nil),
		func(ctx context.Context, op operation.Operation, obj, oldObj interface{}) field.ErrorList {
			switch op.Request.SubresourcePath() {
			case "/", "/scale", "/status":
				return Validate_StatefulSet(
					ctx, op, nil, /* fldPath */
					obj.(*appsv1beta1.StatefulSet),
					safe.Cast[*appsv1beta1.StatefulSet](oldObj))
			}
			return field.ErrorList{
				field.InternalError(nil, fmt.Errorf("no validation found for %T, subresource: %v", obj, op.Request.SubresourcePath())),
			}
		})
	return nil
}

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

	// field appsv1beta1.ControllerRevision.TypeMeta has no validation

	{ // field appsv1beta1.ControllerRevision.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 *appsv1beta1.ControllerRevision) *v1.ObjectMeta {
				return &oldObj.ObjectMeta
			})
		errs = append(errs, fn(fldPath.Child("metadata"), &obj.ObjectMeta, oldVal, oldObj != nil)...)
	}

	// field appsv1beta1.ControllerRevision.Data has no validation
	// field appsv1beta1.ControllerRevision.Revision has no validation
	return errs
}

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

	// field appsv1beta1.Deployment.TypeMeta has no validation

	{ // field appsv1beta1.Deployment.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 *appsv1beta1.Deployment) *v1.ObjectMeta {
				return &oldObj.ObjectMeta
			})
		errs = append(errs, fn(fldPath.Child("metadata"), &obj.ObjectMeta, oldVal, oldObj != nil)...)
	}

	{ // field appsv1beta1.Deployment.Spec
		fn := func(
			fldPath *field.Path,
			obj, oldObj *appsv1beta1.DeploymentSpec,
			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, Validate_DeploymentSpec(ctx, op, fldPath, obj, oldObj)...)
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *appsv1beta1.Deployment) *appsv1beta1.DeploymentSpec {
				return &oldObj.Spec
			})
		errs = append(errs, fn(fldPath.Child("spec"), &obj.Spec, oldVal, oldObj != nil)...)
	}

	// field appsv1beta1.Deployment.Status has no validation
	return errs
}

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

	// field appsv1beta1.DeploymentSpec.Replicas has no validation
	// field appsv1beta1.DeploymentSpec.Selector has no validation

	{ // field appsv1beta1.DeploymentSpec.Template
		fn := func(
			fldPath *field.Path,
			obj, oldObj *apicorev1.PodTemplateSpec,
			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, corev1.Validate_PodTemplateSpec(ctx, op, fldPath, obj, oldObj)...)
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *appsv1beta1.DeploymentSpec) *apicorev1.PodTemplateSpec {
				return &oldObj.Template
			})
		errs = append(errs, fn(fldPath.Child("template"), &obj.Template, oldVal, oldObj != nil)...)
	}

	// field appsv1beta1.DeploymentSpec.Strategy has no validation
	// field appsv1beta1.DeploymentSpec.MinReadySeconds has no validation
	// field appsv1beta1.DeploymentSpec.RevisionHistoryLimit has no validation
	// field appsv1beta1.DeploymentSpec.Paused has no validation
	// field appsv1beta1.DeploymentSpec.RollbackTo has no validation
	// field appsv1beta1.DeploymentSpec.ProgressDeadlineSeconds has no validation
	return errs
}

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

	// field appsv1beta1.Scale.TypeMeta has no validation
	// field appsv1beta1.Scale.ObjectMeta has no validation

	{ // field appsv1beta1.Scale.Spec
		fn := func(
			fldPath *field.Path,
			obj, oldObj *appsv1beta1.ScaleSpec,
			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 the type's validation function
			errs = append(errs, Validate_ScaleSpec(ctx, op, fldPath, obj, oldObj)...)
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *appsv1beta1.Scale) *appsv1beta1.ScaleSpec {
				return &oldObj.Spec
			})
		errs = append(errs, fn(fldPath.Child("spec"), &obj.Spec, oldVal, oldObj != nil)...)
	}

	// field appsv1beta1.Scale.Status has no validation
	return errs
}

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

	{ // field appsv1beta1.ScaleSpec.Replicas
		fn := func(
			fldPath *field.Path,
			obj, oldObj *int32,
			oldValueCorrelated bool) (errs field.ErrorList) {
			// optional value-type fields with zero-value defaults are purely documentation
			// 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
			if e := validate.Minimum(ctx, op, fldPath, obj, oldObj, 0).MarkBeta(); len(e) != 0 {
				errs = append(errs, e...)
			}
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *appsv1beta1.ScaleSpec) *int32 {
				return &oldObj.Replicas
			})
		errs = append(errs, fn(fldPath.Child("replicas"), &obj.Replicas, oldVal, oldObj != nil)...)
	}

	return errs
}

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

	// field appsv1beta1.StatefulSet.TypeMeta has no validation

	{ // field appsv1beta1.StatefulSet.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 *appsv1beta1.StatefulSet) *v1.ObjectMeta {
				return &oldObj.ObjectMeta
			})
		errs = append(errs, fn(fldPath.Child("metadata"), &obj.ObjectMeta, oldVal, oldObj != nil)...)
	}

	{ // field appsv1beta1.StatefulSet.Spec
		fn := func(
			fldPath *field.Path,
			obj, oldObj *appsv1beta1.StatefulSetSpec,
			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, Validate_StatefulSetSpec(ctx, op, fldPath, obj, oldObj)...)
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *appsv1beta1.StatefulSet) *appsv1beta1.StatefulSetSpec {
				return &oldObj.Spec
			})
		errs = append(errs, fn(fldPath.Child("spec"), &obj.Spec, oldVal, oldObj != nil)...)
	}

	// field appsv1beta1.StatefulSet.Status has no validation
	return errs
}

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

	// field appsv1beta1.StatefulSetSpec.Replicas has no validation

	{ // field appsv1beta1.StatefulSetSpec.Selector
		fn := func(
			fldPath *field.Path,
			obj, oldObj *v1.LabelSelector,
			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.RequiredPointer(ctx, op, fldPath, obj, oldObj).MarkAlpha().MarkShortCircuit(); len(e) != 0 {
				errs = append(errs, e...)
				earlyReturn = true
			}
			if e := validate.Immutable(ctx, op, fldPath, obj, oldObj).MarkAlpha().MarkShortCircuit(); len(e) != 0 {
				errs = append(errs, e...)
				earlyReturn = true
			}
			if earlyReturn {
				return // do not proceed
			}
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *appsv1beta1.StatefulSetSpec) *v1.LabelSelector {
				return oldObj.Selector
			})
		errs = append(errs, fn(fldPath.Child("selector"), obj.Selector, oldVal, oldObj != nil)...)
	}

	{ // field appsv1beta1.StatefulSetSpec.Template
		fn := func(
			fldPath *field.Path,
			obj, oldObj *apicorev1.PodTemplateSpec,
			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, corev1.Validate_PodTemplateSpec(ctx, op, fldPath, obj, oldObj)...)
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *appsv1beta1.StatefulSetSpec) *apicorev1.PodTemplateSpec {
				return &oldObj.Template
			})
		errs = append(errs, fn(fldPath.Child("template"), &obj.Template, oldVal, oldObj != nil)...)
	}

	{ // field appsv1beta1.StatefulSetSpec.VolumeClaimTemplates
		fn := func(
			fldPath *field.Path,
			obj, oldObj []apicorev1.PersistentVolumeClaim,
			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).MarkAlpha().MarkShortCircuit(); len(e) != 0 {
				errs = append(errs, e...)
				earlyReturn = true
			}
			if e := validate.OptionalSlice(ctx, op, fldPath, obj, oldObj).MarkAlpha().MarkShortCircuit(); len(e) != 0 {
				earlyReturn = true
			}
			if earlyReturn {
				return // do not proceed
			}
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *appsv1beta1.StatefulSetSpec) []apicorev1.PersistentVolumeClaim {
				return oldObj.VolumeClaimTemplates
			})
		errs = append(errs, fn(fldPath.Child("volumeClaimTemplates"), obj.VolumeClaimTemplates, oldVal, oldObj != nil)...)
	}

	{ // field appsv1beta1.StatefulSetSpec.ServiceName
		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.Immutable(ctx, op, fldPath, obj, oldObj).MarkAlpha().MarkShortCircuit(); len(e) != 0 {
				errs = append(errs, e...)
				earlyReturn = true
			}
			if e := validate.OptionalValue(ctx, op, fldPath, obj, oldObj).MarkAlpha().MarkShortCircuit(); len(e) != 0 {
				earlyReturn = true
			}
			if earlyReturn {
				return // do not proceed
			}
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *appsv1beta1.StatefulSetSpec) *string {
				return &oldObj.ServiceName
			})
		errs = append(errs, fn(fldPath.Child("serviceName"), &obj.ServiceName, oldVal, oldObj != nil)...)
	}

	{ // field appsv1beta1.StatefulSetSpec.PodManagementPolicy
		fn := func(
			fldPath *field.Path,
			obj, oldObj *appsv1beta1.PodManagementPolicyType,
			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.Immutable(ctx, op, fldPath, obj, oldObj).MarkAlpha().MarkShortCircuit(); len(e) != 0 {
				errs = append(errs, e...)
				earlyReturn = true
			}
			if e := validate.OptionalValue(ctx, op, fldPath, obj, oldObj).MarkAlpha().MarkShortCircuit(); len(e) != 0 {
				earlyReturn = true
			}
			if earlyReturn {
				return // do not proceed
			}
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *appsv1beta1.StatefulSetSpec) *appsv1beta1.PodManagementPolicyType {
				return &oldObj.PodManagementPolicy
			})
		errs = append(errs, fn(fldPath.Child("podManagementPolicy"), &obj.PodManagementPolicy, oldVal, oldObj != nil)...)
	}

	// field appsv1beta1.StatefulSetSpec.UpdateStrategy has no validation
	// field appsv1beta1.StatefulSetSpec.RevisionHistoryLimit has no validation
	// field appsv1beta1.StatefulSetSpec.MinReadySeconds has no validation
	// field appsv1beta1.StatefulSetSpec.PersistentVolumeClaimRetentionPolicy has no validation
	// field appsv1beta1.StatefulSetSpec.Ordinals has no validation
	return errs
}
