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

import (
	context "context"

	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"
	types "k8s.io/apimachinery/pkg/types"
	sets "k8s.io/apimachinery/pkg/util/sets"
	field "k8s.io/apimachinery/pkg/util/validation/field"
)

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

	{ // field v1.Condition.Type
		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).MarkAlpha().MarkShortCircuit(); len(e) != 0 {
				errs = append(errs, e...)
				earlyReturn = true
			}
			if earlyReturn {
				return // do not proceed
			}
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *v1.Condition) *string {
				return &oldObj.Type
			})
		errs = append(errs, fn(fldPath.Child("type"), &obj.Type, oldVal, oldObj != nil)...)
	}

	{ // field v1.Condition.Status
		fn := func(
			fldPath *field.Path,
			obj, oldObj *v1.ConditionStatus,
			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).MarkAlpha().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_ConditionStatus(ctx, op, fldPath, obj, oldObj)...)
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *v1.Condition) *v1.ConditionStatus {
				return &oldObj.Status
			})
		errs = append(errs, fn(fldPath.Child("status"), &obj.Status, oldVal, oldObj != nil)...)
	}

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

	{ // field v1.Condition.LastTransitionTime
		fn := func(
			fldPath *field.Path,
			obj, oldObj *v1.Time,
			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
			// custom validation
			if e := ValidateCustom_Condition_LastTransitionTime(ctx, op, fldPath, obj, oldObj).MarkAlpha(); len(e) != 0 {
				errs = append(errs, e...)
			}
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *v1.Condition) *v1.Time {
				return &oldObj.LastTransitionTime
			})
		errs = append(errs, fn(fldPath.Child("lastTransitionTime"), &obj.LastTransitionTime, oldVal, oldObj != nil)...)
	}

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

	// field v1.Condition.Message has no validation
	return errs
}

var symbolsForConditionStatus = sets.New(v1.ConditionFalse, v1.ConditionTrue, v1.ConditionUnknown)

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

	if e := validate.Enum(ctx, op, fldPath, obj, oldObj, symbolsForConditionStatus, nil).MarkAlpha(); len(e) != 0 {
		errs = append(errs, e...)
	}

	return errs
}

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

	// field v1.ManagedFieldsEntry.Manager has no validation

	{ // field v1.ManagedFieldsEntry.Operation
		fn := func(
			fldPath *field.Path,
			obj, oldObj *v1.ManagedFieldsOperationType,
			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).MarkAlpha().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_ManagedFieldsOperationType(ctx, op, fldPath, obj, oldObj)...)
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *v1.ManagedFieldsEntry) *v1.ManagedFieldsOperationType {
				return &oldObj.Operation
			})
		errs = append(errs, fn(fldPath.Child("operation"), &obj.Operation, oldVal, oldObj != nil)...)
	}

	// field v1.ManagedFieldsEntry.APIVersion has no validation
	// field v1.ManagedFieldsEntry.Time has no validation
	// field v1.ManagedFieldsEntry.FieldsType has no validation
	// field v1.ManagedFieldsEntry.FieldsV1 has no validation
	// field v1.ManagedFieldsEntry.Subresource has no validation
	return errs
}

var symbolsForManagedFieldsOperationType = sets.New(v1.ManagedFieldsOperationApply, v1.ManagedFieldsOperationUpdate)

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

	if e := validate.Enum(ctx, op, fldPath, obj, oldObj, symbolsForManagedFieldsOperationType, nil).MarkAlpha(); len(e) != 0 {
		errs = append(errs, e...)
	}

	return errs
}

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

	// field v1.ObjectMeta.Name has no validation
	// field v1.ObjectMeta.GenerateName has no validation
	// field v1.ObjectMeta.Namespace has no validation
	// field v1.ObjectMeta.SelfLink has no validation

	{ // field v1.ObjectMeta.UID
		fn := func(
			fldPath *field.Path,
			obj, oldObj *types.UID,
			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.OptionalValue(ctx, op, fldPath, obj, oldObj).MarkAlpha().MarkShortCircuit(); len(e) != 0 {
				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 *v1.ObjectMeta) *types.UID {
				return &oldObj.UID
			})
		errs = append(errs, fn(fldPath.Child("uid"), &obj.UID, oldVal, oldObj != nil)...)
	}

	// field v1.ObjectMeta.ResourceVersion has no validation

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

	{ // field v1.ObjectMeta.CreationTimestamp
		fn := func(
			fldPath *field.Path,
			obj, oldObj *v1.Time,
			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 earlyReturn {
				return // do not proceed
			}
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *v1.ObjectMeta) *v1.Time {
				return &oldObj.CreationTimestamp
			})
		errs = append(errs, fn(fldPath.Child("creationTimestamp"), &obj.CreationTimestamp, oldVal, oldObj != nil)...)
	}

	{ // field v1.ObjectMeta.DeletionTimestamp
		fn := func(
			fldPath *field.Path,
			obj, oldObj *v1.Time,
			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.OptionalPointer(ctx, op, fldPath, obj, oldObj).MarkAlpha().MarkShortCircuit(); len(e) != 0 {
				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 *v1.ObjectMeta) *v1.Time {
				return oldObj.DeletionTimestamp
			})
		errs = append(errs, fn(fldPath.Child("deletionTimestamp"), obj.DeletionTimestamp, oldVal, oldObj != nil)...)
	}

	{ // field v1.ObjectMeta.DeletionGracePeriodSeconds
		fn := func(
			fldPath *field.Path,
			obj, oldObj *int64,
			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.OptionalPointer(ctx, op, fldPath, obj, oldObj).MarkAlpha().MarkShortCircuit(); len(e) != 0 {
				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 *v1.ObjectMeta) *int64 {
				return oldObj.DeletionGracePeriodSeconds
			})
		errs = append(errs, fn(fldPath.Child("deletionGracePeriodSeconds"), obj.DeletionGracePeriodSeconds, oldVal, oldObj != nil)...)
	}

	// field v1.ObjectMeta.Labels has no validation
	// field v1.ObjectMeta.Annotations has no validation

	{ // field v1.ObjectMeta.OwnerReferences
		fn := func(
			fldPath *field.Path,
			obj, oldObj []v1.OwnerReference,
			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.OptionalSlice(ctx, op, fldPath, obj, oldObj).MarkAlpha().MarkShortCircuit(); len(e) != 0 {
				earlyReturn = true
			}
			if earlyReturn {
				return // do not proceed
			}
			// iterate the list and call the type's validation function
			if e := validate.EachValSliceVal(ctx, op, fldPath, obj, oldObj, nil, nil, Validate_OwnerReference); len(e) != 0 {
				errs = append(errs, e...)
			}
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *v1.ObjectMeta) []v1.OwnerReference {
				return oldObj.OwnerReferences
			})
		errs = append(errs, fn(fldPath.Child("ownerReferences"), obj.OwnerReferences, oldVal, oldObj != nil)...)
	}

	// field v1.ObjectMeta.Finalizers has no validation

	{ // field v1.ObjectMeta.ManagedFields
		fn := func(
			fldPath *field.Path,
			obj, oldObj []v1.ManagedFieldsEntry,
			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.OptionalSlice(ctx, op, fldPath, obj, oldObj).MarkAlpha().MarkShortCircuit(); len(e) != 0 {
				earlyReturn = true
			}
			if earlyReturn {
				return // do not proceed
			}
			// iterate the list and call the type's validation function
			if e := validate.EachValSliceVal(ctx, op, fldPath, obj, oldObj, nil, nil, Validate_ManagedFieldsEntry); len(e) != 0 {
				errs = append(errs, e...)
			}
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *v1.ObjectMeta) []v1.ManagedFieldsEntry {
				return oldObj.ManagedFields
			})
		errs = append(errs, fn(fldPath.Child("managedFields"), obj.ManagedFields, oldVal, oldObj != nil)...)
	}

	return errs
}

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

	{ // field v1.OwnerReference.APIVersion
		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).MarkAlpha().MarkShortCircuit(); len(e) != 0 {
				errs = append(errs, e...)
				earlyReturn = true
			}
			if earlyReturn {
				return // do not proceed
			}
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *v1.OwnerReference) *string {
				return &oldObj.APIVersion
			})
		errs = append(errs, fn(fldPath.Child("apiVersion"), &obj.APIVersion, oldVal, oldObj != nil)...)
	}

	{ // field v1.OwnerReference.Kind
		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).MarkAlpha().MarkShortCircuit(); len(e) != 0 {
				errs = append(errs, e...)
				earlyReturn = true
			}
			if earlyReturn {
				return // do not proceed
			}
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *v1.OwnerReference) *string {
				return &oldObj.Kind
			})
		errs = append(errs, fn(fldPath.Child("kind"), &obj.Kind, oldVal, oldObj != nil)...)
	}

	{ // field v1.OwnerReference.Name
		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).MarkAlpha().MarkShortCircuit(); len(e) != 0 {
				errs = append(errs, e...)
				earlyReturn = true
			}
			if earlyReturn {
				return // do not proceed
			}
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *v1.OwnerReference) *string {
				return &oldObj.Name
			})
		errs = append(errs, fn(fldPath.Child("name"), &obj.Name, oldVal, oldObj != nil)...)
	}

	{ // field v1.OwnerReference.UID
		fn := func(
			fldPath *field.Path,
			obj, oldObj *types.UID,
			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).MarkAlpha().MarkShortCircuit(); len(e) != 0 {
				errs = append(errs, e...)
				earlyReturn = true
			}
			if earlyReturn {
				return // do not proceed
			}
			return
		}
		oldVal := safe.Field(oldObj,
			func(oldObj *v1.OwnerReference) *types.UID {
				return &oldObj.UID
			})
		errs = append(errs, fn(fldPath.Child("uid"), &obj.UID, oldVal, oldObj != nil)...)
	}

	// field v1.OwnerReference.Controller has no validation
	// field v1.OwnerReference.BlockOwnerDeletion has no validation
	return errs
}
