func dropDisabledFields(
	podSpec *api.PodSpec, podAnnotations map[string]string,
	oldPodSpec *api.PodSpec, oldPodAnnotations map[string]string,
) {
	// the new spec must always be non-nil
	if podSpec == nil {
		podSpec = &api.PodSpec{}
	}

	if !utilfeature.DefaultFeatureGate.Enabled(features.TokenRequestProjection) &&
		!tokenRequestProjectionInUse(oldPodSpec) {
		for i := range podSpec.Volumes {
			if podSpec.Volumes[i].Projected != nil {
				for j := range podSpec.Volumes[i].Projected.Sources {
					podSpec.Volumes[i].Projected.Sources[j].ServiceAccountToken = nil
				}
			}

		}
	}

	if !utilfeature.DefaultFeatureGate.Enabled(features.AppArmor) && !appArmorInUse(oldPodAnnotations) {
		for k := range podAnnotations {
			if strings.HasPrefix(k, v1.AppArmorBetaContainerAnnotationKeyPrefix) {
				delete(podAnnotations, k)
			}
		}
	}

	if !utilfeature.DefaultFeatureGate.Enabled(features.Sysctls) && !sysctlsInUse(oldPodSpec) {
		if podSpec.SecurityContext != nil {
			podSpec.SecurityContext.Sysctls = nil
		}
	}

	if !utilfeature.DefaultFeatureGate.Enabled(features.LocalStorageCapacityIsolation) && !emptyDirSizeLimitInUse(oldPodSpec) {
		for i := range podSpec.Volumes {
			if podSpec.Volumes[i].EmptyDir != nil {
				podSpec.Volumes[i].EmptyDir.SizeLimit = nil
			}
		}
	}

	if !utilfeature.DefaultFeatureGate.Enabled(features.VolumeSubpath) && !subpathInUse(oldPodSpec) {
		// drop subpath from the pod if the feature is disabled and the old spec did not specify subpaths
		VisitContainers(podSpec, AllContainers, func(c *api.Container, containerType ContainerType) bool {
			for i := range c.VolumeMounts {
				c.VolumeMounts[i].SubPath = ""
			}
			return true
		})
	}
	if !utilfeature.DefaultFeatureGate.Enabled(features.EphemeralContainers) && !ephemeralContainersInUse(oldPodSpec) {
		podSpec.EphemeralContainers = nil
	}

	if !utilfeature.DefaultFeatureGate.Enabled(features.VolumeSubpath) && !subpathExprInUse(oldPodSpec) {
		// drop subpath env expansion from the pod if subpath feature is disabled and the old spec did not specify subpath env expansion
		VisitContainers(podSpec, AllContainers, func(c *api.Container, containerType ContainerType) bool {
			for i := range c.VolumeMounts {
				c.VolumeMounts[i].SubPathExpr = ""
			}
			return true
		})
	}

	if !utilfeature.DefaultFeatureGate.Enabled(features.StartupProbe) && !startupProbeInUse(oldPodSpec) {
		// drop startupProbe from all containers if the feature is disabled
		VisitContainers(podSpec, AllContainers, func(c *api.Container, containerType ContainerType) bool {
			c.StartupProbe = nil
			return true
		})
	}

	dropDisabledRunAsGroupField(podSpec, oldPodSpec)

	dropDisabledFSGroupFields(podSpec, oldPodSpec)

	if !utilfeature.DefaultFeatureGate.Enabled(features.RuntimeClass) && !runtimeClassInUse(oldPodSpec) {
		// Set RuntimeClassName to nil only if feature is disabled and it is not used
		podSpec.RuntimeClassName = nil
	}

	if !utilfeature.DefaultFeatureGate.Enabled(features.PodOverhead) && !overheadInUse(oldPodSpec) {
		// Set Overhead to nil only if the feature is disabled and it is not used
		podSpec.Overhead = nil
	}

	dropDisabledProcMountField(podSpec, oldPodSpec)

	dropDisabledCSIVolumeSourceAlphaFields(podSpec, oldPodSpec)
	dropDisabledEphemeralVolumeSourceAlphaFields(podSpec, oldPodSpec)

	if !utilfeature.DefaultFeatureGate.Enabled(features.NonPreemptingPriority) &&
		!podPriorityInUse(oldPodSpec) {
		// Set to nil pod's PreemptionPolicy fields if the feature is disabled and the old pod
		// does not specify any values for these fields.
		podSpec.PreemptionPolicy = nil
	}

	if !utilfeature.DefaultFeatureGate.Enabled(features.SetHostnameAsFQDN) && !setHostnameAsFQDNInUse(oldPodSpec) {
		// Set SetHostnameAsFQDN to nil only if feature is disabled and it is not used
		podSpec.SetHostnameAsFQDN = nil
	}

}
// dropDisabledFields removes disabled fields from the pod metadata and spec.
dropDisabledFields removes disabled fields from the pod metadata and spec.
// dropDisabledFields removes disabled fields from the pod metadata and spec .
func dropDisabledFields(
	podSpec *api.PodSpec, podAnnotations map[string]string,
	oldPodSpec *api.PodSpec, oldPodAnnotations map[string]string,
) {
	if podSpec == nil {
		podSpec = &api.PodSpec{}
	}
	if !utilfeature.DefaultFeatureGate.Enabled(features.TokenRequestProjection) &&
		!tokenRequestProjectionInUse(oldPodSpec) {
		for i := range podSpec.Volumes {
			if podSpec.Volumes[i].Projected != nil {
				for j := range podSpec.Volumes[i].Projected.Sources {
					podSpec.Volumes[i].Projected.Sources[j].ServiceAccountToken = nil
				}
			}
		}
	}
	if !utilfeature.DefaultFeatureGate.Enabled(features.AppArmor) && !appArmorInUse(oldPodAnnotations) {
		for k := range podAnnotations {
			if strings.HasPrefix(k, v1.AppArmorBetaContainerAnnotationKeyPrefix) {
				delete(podAnnotations, k)
			}
		}
	}
	if !utilfeature.DefaultFeatureGate.Enabled(features.Sysctls) && !sysctlsInUse(oldPodSpec) {
		if podSpec.SecurityContext != nil {
			podSpec.SecurityContext.Sysctls = nil
		}
	}
	if !utilfeature.DefaultFeatureGate.Enabled(features.LocalStorageCapacityIsolation) && !emptyDirSizeLimitInUse(oldPodSpec) {
		for i := range podSpec.Volumes {
			if podSpec.Volumes[i].EmptyDir != nil {
				podSpec.Volumes[i].EmptyDir.SizeLimit = nil
			}
		}
	}
	if !utilfeature.DefaultFeatureGate.Enabled(features.VolumeSubpath) && !subpathInUse(oldPodSpec) {
		VisitContainers(podSpec, AllContainers, func(c *api.Container, containerType ContainerType) bool {
			for i := range c.VolumeMounts {
				c.VolumeMounts[i].SubPath = ""
			}
			return true
		})
	}
	if !utilfeature.DefaultFeatureGate.Enabled(features.EphemeralContainers) && !ephemeralContainersInUse(oldPodSpec) {
		podSpec.EphemeralContainers = nil
	}
	if !utilfeature.DefaultFeatureGate.Enabled(features.VolumeSubpath) && !subpathExprInUse(oldPodSpec) {
		VisitContainers(podSpec, AllContainers, func(c *api.Container, containerType ContainerType) bool {
			for i := range c.VolumeMounts {
				c.VolumeMounts[i].SubPathExpr = ""
			}
			return true
		})
	}
	if !utilfeature.DefaultFeatureGate.Enabled(features.StartupProbe) && !startupProbeInUse(oldPodSpec) {
		VisitContainers(podSpec, AllContainers, func(c *api.Container, containerType ContainerType) bool {
			c.StartupProbe = nil
			return true
		})
	}
	dropDisabledRunAsGroupField(podSpec, oldPodSpec)
	dropDisabledFSGroupFields(podSpec, oldPodSpec)
	if !utilfeature.DefaultFeatureGate.Enabled(features.RuntimeClass) && !runtimeClassInUse(oldPodSpec) {
		podSpec.RuntimeClassName = nil
	}
	if !utilfeature.DefaultFeatureGate.Enabled(features.PodOverhead) && !overheadInUse(oldPodSpec) {
		podSpec.Overhead = nil
	}
	dropDisabledProcMountField(podSpec, oldPodSpec)
	dropDisabledCSIVolumeSourceAlphaFields(podSpec, oldPodSpec)
	dropDisabledEphemeralVolumeSourceAlphaFields(podSpec, oldPodSpec)
	if !utilfeature.DefaultFeatureGate.Enabled(features.NonPreemptingPriority) &&
		!podPriorityInUse(oldPodSpec) {
		podSpec.PreemptionPolicy = nil
	}
	if !utilfeature.DefaultFeatureGate.Enabled(features.SetHostnameAsFQDN) && !setHostnameAsFQDNInUse(oldPodSpec) {
		podSpec.SetHostnameAsFQDN = nil
	}
}
func dropDisabledFields ( podSpec * api . PodSpec , podAnnotations map [ string ] string , oldPodSpec * api . PodSpec , oldPodAnnotations map [ string ] string , ) { if podSpec == nil { podSpec = & api . PodSpec { } } if ! utilfeature . DefaultFeatureGate . Enabled ( features . TokenRequestProjection ) && ! tokenRequestProjectionInUse ( oldPodSpec ) { for i := range podSpec . Volumes { if podSpec . Volumes [ i ] . Projected != nil { for j := range podSpec . Volumes [ i ] . Projected . Sources { podSpec . Volumes [ i ] . Projected . Sources [ j ] . ServiceAccountToken = nil } } } } if ! utilfeature . DefaultFeatureGate . Enabled ( features . AppArmor ) && ! appArmorInUse ( oldPodAnnotations ) { for k := range podAnnotations { if strings . HasPrefix ( k , v1 . AppArmorBetaContainerAnnotationKeyPrefix ) { delete ( podAnnotations , k ) } } } if ! utilfeature . DefaultFeatureGate . Enabled ( features . Sysctls ) && ! sysctlsInUse ( oldPodSpec ) { if podSpec . SecurityContext != nil { podSpec . SecurityContext . Sysctls = nil } } if ! utilfeature . DefaultFeatureGate . Enabled ( features . LocalStorageCapacityIsolation ) && ! emptyDirSizeLimitInUse ( oldPodSpec ) { for i := range podSpec . Volumes { if podSpec . Volumes [ i ] . EmptyDir != nil { podSpec . Volumes [ i ] . EmptyDir . SizeLimit = nil } } } if ! utilfeature . DefaultFeatureGate . Enabled ( features . VolumeSubpath ) && ! subpathInUse ( oldPodSpec ) { VisitContainers ( podSpec , AllContainers , func ( c * api . Container , containerType ContainerType ) bool { for i := range c . VolumeMounts { c . VolumeMounts [ i ] . SubPath = " " } return true } ) } if ! utilfeature . DefaultFeatureGate . Enabled ( features . EphemeralContainers ) && ! ephemeralContainersInUse ( oldPodSpec ) { podSpec . EphemeralContainers = nil } if ! utilfeature . DefaultFeatureGate . Enabled ( features . VolumeSubpath ) && ! subpathExprInUse ( oldPodSpec ) { VisitContainers ( podSpec , AllContainers , func ( c * api . Container , containerType ContainerType ) bool { for i := range c . VolumeMounts { c . VolumeMounts [ i ] . SubPathExpr = " " } return true } ) } if ! utilfeature . DefaultFeatureGate . Enabled ( features . StartupProbe ) && ! startupProbeInUse ( oldPodSpec ) { VisitContainers ( podSpec , AllContainers , func ( c * api . Container , containerType ContainerType ) bool { c . StartupProbe = nil return true } ) } dropDisabledRunAsGroupField ( podSpec , oldPodSpec ) dropDisabledFSGroupFields ( podSpec , oldPodSpec ) if ! utilfeature . DefaultFeatureGate . Enabled ( features . RuntimeClass ) && ! runtimeClassInUse ( oldPodSpec ) { podSpec . RuntimeClassName = nil } if ! utilfeature . DefaultFeatureGate . Enabled ( features . PodOverhead ) && ! overheadInUse ( oldPodSpec ) { podSpec . Overhead = nil } dropDisabledProcMountField ( podSpec , oldPodSpec ) dropDisabledCSIVolumeSourceAlphaFields ( podSpec , oldPodSpec ) dropDisabledEphemeralVolumeSourceAlphaFields ( podSpec , oldPodSpec ) if ! utilfeature . DefaultFeatureGate . Enabled ( features . NonPreemptingPriority ) && ! podPriorityInUse ( oldPodSpec ) { podSpec . PreemptionPolicy = nil } if ! utilfeature . DefaultFeatureGate . Enabled ( features . SetHostnameAsFQDN ) && ! setHostnameAsFQDNInUse ( oldPodSpec ) { podSpec . SetHostnameAsFQDN = nil } }
dropDisabledFields removes disabled fields from the pod metadata and spec.
dropDisabledFields removes disabled fields from the pod metadata and spec .
// the new spec must always be non-nil // drop subpath from the pod if the feature is disabled and the old spec did not specify subpaths // drop subpath env expansion from the pod if subpath feature is disabled and the old spec did not specify subpath env expansion // drop startupProbe from all containers if the feature is disabled // Set RuntimeClassName to nil only if feature is disabled and it is not used // Set Overhead to nil only if the feature is disabled and it is not used // Set to nil pod's PreemptionPolicy fields if the feature is disabled and the old pod // does not specify any values for these fields. // Set SetHostnameAsFQDN to nil only if feature is disabled and it is not used