mirror of https://github.com/k3s-io/k3s
Rename DropDisabledFields
parent
f77a0706d0
commit
49028df5f9
|
@ -232,9 +232,9 @@ func UpdatePodCondition(status *api.PodStatus, condition *api.PodCondition) bool
|
||||||
return !isEqual
|
return !isEqual
|
||||||
}
|
}
|
||||||
|
|
||||||
// DropDisabledAlphaFields removes disabled fields from the pod spec.
|
// DropDisabledFields removes disabled fields from the pod spec.
|
||||||
// This should be called from PrepareForCreate/PrepareForUpdate for all resources containing a pod spec.
|
// This should be called from PrepareForCreate/PrepareForUpdate for all resources containing a pod spec.
|
||||||
func DropDisabledAlphaFields(podSpec *api.PodSpec) {
|
func DropDisabledFields(podSpec *api.PodSpec) {
|
||||||
if !utilfeature.DefaultFeatureGate.Enabled(features.PodPriority) {
|
if !utilfeature.DefaultFeatureGate.Enabled(features.PodPriority) {
|
||||||
podSpec.Priority = nil
|
podSpec.Priority = nil
|
||||||
podSpec.PriorityClassName = ""
|
podSpec.PriorityClassName = ""
|
||||||
|
|
|
@ -307,7 +307,7 @@ func TestDropAlphaVolumeDevices(t *testing.T) {
|
||||||
defer utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.BlockVolume, true)()
|
defer utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.BlockVolume, true)()
|
||||||
|
|
||||||
// now test dropping the fields - should not be dropped
|
// now test dropping the fields - should not be dropped
|
||||||
DropDisabledAlphaFields(&testPod.Spec)
|
DropDisabledFields(&testPod.Spec)
|
||||||
|
|
||||||
// check to make sure VolumeDevices is still present
|
// check to make sure VolumeDevices is still present
|
||||||
// if featureset is set to true
|
// if featureset is set to true
|
||||||
|
@ -322,14 +322,14 @@ func TestDropAlphaVolumeDevices(t *testing.T) {
|
||||||
defer utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.BlockVolume, false)()
|
defer utilfeaturetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.BlockVolume, false)()
|
||||||
|
|
||||||
// now test dropping the fields
|
// now test dropping the fields
|
||||||
DropDisabledAlphaFields(&testPod.Spec)
|
DropDisabledFields(&testPod.Spec)
|
||||||
|
|
||||||
// check to make sure VolumeDevices is nil
|
// check to make sure VolumeDevices is nil
|
||||||
// if featureset is set to false
|
// if featureset is set to false
|
||||||
if testPod.Spec.Containers[0].VolumeDevices != nil {
|
if testPod.Spec.Containers[0].VolumeDevices != nil {
|
||||||
t.Error("DropDisabledAlphaFields for Containers failed")
|
t.Error("DropDisabledFields for Containers failed")
|
||||||
}
|
}
|
||||||
if testPod.Spec.InitContainers[0].VolumeDevices != nil {
|
if testPod.Spec.InitContainers[0].VolumeDevices != nil {
|
||||||
t.Error("DropDisabledAlphaFields for InitContainers failed")
|
t.Error("DropDisabledFields for InitContainers failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ func (daemonSetStrategy) PrepareForCreate(ctx context.Context, obj runtime.Objec
|
||||||
daemonSet.Spec.TemplateGeneration = 1
|
daemonSet.Spec.TemplateGeneration = 1
|
||||||
}
|
}
|
||||||
|
|
||||||
pod.DropDisabledAlphaFields(&daemonSet.Spec.Template.Spec)
|
pod.DropDisabledFields(&daemonSet.Spec.Template.Spec)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
|
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
|
||||||
|
@ -83,8 +83,8 @@ func (daemonSetStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.
|
||||||
newDaemonSet := obj.(*apps.DaemonSet)
|
newDaemonSet := obj.(*apps.DaemonSet)
|
||||||
oldDaemonSet := old.(*apps.DaemonSet)
|
oldDaemonSet := old.(*apps.DaemonSet)
|
||||||
|
|
||||||
pod.DropDisabledAlphaFields(&newDaemonSet.Spec.Template.Spec)
|
pod.DropDisabledFields(&newDaemonSet.Spec.Template.Spec)
|
||||||
pod.DropDisabledAlphaFields(&oldDaemonSet.Spec.Template.Spec)
|
pod.DropDisabledFields(&oldDaemonSet.Spec.Template.Spec)
|
||||||
|
|
||||||
// update is not allowed to set status
|
// update is not allowed to set status
|
||||||
newDaemonSet.Status = oldDaemonSet.Status
|
newDaemonSet.Status = oldDaemonSet.Status
|
||||||
|
|
|
@ -73,7 +73,7 @@ func (deploymentStrategy) PrepareForCreate(ctx context.Context, obj runtime.Obje
|
||||||
deployment.Status = apps.DeploymentStatus{}
|
deployment.Status = apps.DeploymentStatus{}
|
||||||
deployment.Generation = 1
|
deployment.Generation = 1
|
||||||
|
|
||||||
pod.DropDisabledAlphaFields(&deployment.Spec.Template.Spec)
|
pod.DropDisabledFields(&deployment.Spec.Template.Spec)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates a new deployment.
|
// Validate validates a new deployment.
|
||||||
|
@ -97,8 +97,8 @@ func (deploymentStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime
|
||||||
oldDeployment := old.(*apps.Deployment)
|
oldDeployment := old.(*apps.Deployment)
|
||||||
newDeployment.Status = oldDeployment.Status
|
newDeployment.Status = oldDeployment.Status
|
||||||
|
|
||||||
pod.DropDisabledAlphaFields(&newDeployment.Spec.Template.Spec)
|
pod.DropDisabledFields(&newDeployment.Spec.Template.Spec)
|
||||||
pod.DropDisabledAlphaFields(&oldDeployment.Spec.Template.Spec)
|
pod.DropDisabledFields(&oldDeployment.Spec.Template.Spec)
|
||||||
|
|
||||||
// Spec updates bump the generation so that we can distinguish between
|
// Spec updates bump the generation so that we can distinguish between
|
||||||
// scaling events and template changes, annotation updates bump the generation
|
// scaling events and template changes, annotation updates bump the generation
|
||||||
|
|
|
@ -80,7 +80,7 @@ func (rsStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
|
||||||
|
|
||||||
rs.Generation = 1
|
rs.Generation = 1
|
||||||
|
|
||||||
pod.DropDisabledAlphaFields(&rs.Spec.Template.Spec)
|
pod.DropDisabledFields(&rs.Spec.Template.Spec)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
|
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
|
||||||
|
@ -90,8 +90,8 @@ func (rsStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object)
|
||||||
// update is not allowed to set status
|
// update is not allowed to set status
|
||||||
newRS.Status = oldRS.Status
|
newRS.Status = oldRS.Status
|
||||||
|
|
||||||
pod.DropDisabledAlphaFields(&newRS.Spec.Template.Spec)
|
pod.DropDisabledFields(&newRS.Spec.Template.Spec)
|
||||||
pod.DropDisabledAlphaFields(&oldRS.Spec.Template.Spec)
|
pod.DropDisabledFields(&oldRS.Spec.Template.Spec)
|
||||||
|
|
||||||
// Any changes to the spec increment the generation number, any changes to the
|
// Any changes to the spec increment the generation number, any changes to the
|
||||||
// status should reflect the generation number of the corresponding object. We push
|
// status should reflect the generation number of the corresponding object. We push
|
||||||
|
|
|
@ -72,7 +72,7 @@ func (statefulSetStrategy) PrepareForCreate(ctx context.Context, obj runtime.Obj
|
||||||
|
|
||||||
statefulSet.Generation = 1
|
statefulSet.Generation = 1
|
||||||
|
|
||||||
pod.DropDisabledAlphaFields(&statefulSet.Spec.Template.Spec)
|
pod.DropDisabledFields(&statefulSet.Spec.Template.Spec)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
|
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
|
||||||
|
@ -82,8 +82,8 @@ func (statefulSetStrategy) PrepareForUpdate(ctx context.Context, obj, old runtim
|
||||||
// Update is not allowed to set status
|
// Update is not allowed to set status
|
||||||
newStatefulSet.Status = oldStatefulSet.Status
|
newStatefulSet.Status = oldStatefulSet.Status
|
||||||
|
|
||||||
pod.DropDisabledAlphaFields(&newStatefulSet.Spec.Template.Spec)
|
pod.DropDisabledFields(&newStatefulSet.Spec.Template.Spec)
|
||||||
pod.DropDisabledAlphaFields(&oldStatefulSet.Spec.Template.Spec)
|
pod.DropDisabledFields(&oldStatefulSet.Spec.Template.Spec)
|
||||||
|
|
||||||
// Any changes to the spec increment the generation number, any changes to the
|
// Any changes to the spec increment the generation number, any changes to the
|
||||||
// status should reflect the generation number of the corresponding object.
|
// status should reflect the generation number of the corresponding object.
|
||||||
|
|
|
@ -68,7 +68,7 @@ func (cronJobStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object)
|
||||||
cronJob := obj.(*batch.CronJob)
|
cronJob := obj.(*batch.CronJob)
|
||||||
cronJob.Status = batch.CronJobStatus{}
|
cronJob.Status = batch.CronJobStatus{}
|
||||||
|
|
||||||
pod.DropDisabledAlphaFields(&cronJob.Spec.JobTemplate.Spec.Template.Spec)
|
pod.DropDisabledFields(&cronJob.Spec.JobTemplate.Spec.Template.Spec)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
|
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
|
||||||
|
@ -77,8 +77,8 @@ func (cronJobStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Ob
|
||||||
oldCronJob := old.(*batch.CronJob)
|
oldCronJob := old.(*batch.CronJob)
|
||||||
newCronJob.Status = oldCronJob.Status
|
newCronJob.Status = oldCronJob.Status
|
||||||
|
|
||||||
pod.DropDisabledAlphaFields(&newCronJob.Spec.JobTemplate.Spec.Template.Spec)
|
pod.DropDisabledFields(&newCronJob.Spec.JobTemplate.Spec.Template.Spec)
|
||||||
pod.DropDisabledAlphaFields(&oldCronJob.Spec.JobTemplate.Spec.Template.Spec)
|
pod.DropDisabledFields(&oldCronJob.Spec.JobTemplate.Spec.Template.Spec)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates a new scheduled job.
|
// Validate validates a new scheduled job.
|
||||||
|
|
|
@ -80,7 +80,7 @@ func (jobStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
|
||||||
job.Spec.TTLSecondsAfterFinished = nil
|
job.Spec.TTLSecondsAfterFinished = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
pod.DropDisabledAlphaFields(&job.Spec.Template.Spec)
|
pod.DropDisabledFields(&job.Spec.Template.Spec)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
|
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
|
||||||
|
@ -94,8 +94,8 @@ func (jobStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object
|
||||||
oldJob.Spec.TTLSecondsAfterFinished = nil
|
oldJob.Spec.TTLSecondsAfterFinished = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
pod.DropDisabledAlphaFields(&newJob.Spec.Template.Spec)
|
pod.DropDisabledFields(&newJob.Spec.Template.Spec)
|
||||||
pod.DropDisabledAlphaFields(&oldJob.Spec.Template.Spec)
|
pod.DropDisabledFields(&oldJob.Spec.Template.Spec)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates a new job.
|
// Validate validates a new job.
|
||||||
|
|
|
@ -73,7 +73,7 @@ func (podStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
|
||||||
QOSClass: qos.GetPodQOS(pod),
|
QOSClass: qos.GetPodQOS(pod),
|
||||||
}
|
}
|
||||||
|
|
||||||
podutil.DropDisabledAlphaFields(&pod.Spec)
|
podutil.DropDisabledFields(&pod.Spec)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
|
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
|
||||||
|
@ -82,8 +82,8 @@ func (podStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object
|
||||||
oldPod := old.(*api.Pod)
|
oldPod := old.(*api.Pod)
|
||||||
newPod.Status = oldPod.Status
|
newPod.Status = oldPod.Status
|
||||||
|
|
||||||
podutil.DropDisabledAlphaFields(&newPod.Spec)
|
podutil.DropDisabledFields(&newPod.Spec)
|
||||||
podutil.DropDisabledAlphaFields(&oldPod.Spec)
|
podutil.DropDisabledFields(&oldPod.Spec)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates a new pod.
|
// Validate validates a new pod.
|
||||||
|
|
|
@ -47,7 +47,7 @@ func (podTemplateStrategy) NamespaceScoped() bool {
|
||||||
func (podTemplateStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
|
func (podTemplateStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
|
||||||
template := obj.(*api.PodTemplate)
|
template := obj.(*api.PodTemplate)
|
||||||
|
|
||||||
pod.DropDisabledAlphaFields(&template.Template.Spec)
|
pod.DropDisabledFields(&template.Template.Spec)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates a new pod template.
|
// Validate validates a new pod template.
|
||||||
|
@ -70,8 +70,8 @@ func (podTemplateStrategy) PrepareForUpdate(ctx context.Context, obj, old runtim
|
||||||
newTemplate := obj.(*api.PodTemplate)
|
newTemplate := obj.(*api.PodTemplate)
|
||||||
oldTemplate := old.(*api.PodTemplate)
|
oldTemplate := old.(*api.PodTemplate)
|
||||||
|
|
||||||
pod.DropDisabledAlphaFields(&newTemplate.Template.Spec)
|
pod.DropDisabledFields(&newTemplate.Template.Spec)
|
||||||
pod.DropDisabledAlphaFields(&oldTemplate.Template.Spec)
|
pod.DropDisabledFields(&oldTemplate.Template.Spec)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateUpdate is the default update validation for an end user.
|
// ValidateUpdate is the default update validation for an end user.
|
||||||
|
|
|
@ -81,7 +81,7 @@ func (rcStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
|
||||||
controller.Generation = 1
|
controller.Generation = 1
|
||||||
|
|
||||||
if controller.Spec.Template != nil {
|
if controller.Spec.Template != nil {
|
||||||
pod.DropDisabledAlphaFields(&controller.Spec.Template.Spec)
|
pod.DropDisabledFields(&controller.Spec.Template.Spec)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -93,10 +93,10 @@ func (rcStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object)
|
||||||
newController.Status = oldController.Status
|
newController.Status = oldController.Status
|
||||||
|
|
||||||
if oldController.Spec.Template != nil {
|
if oldController.Spec.Template != nil {
|
||||||
pod.DropDisabledAlphaFields(&oldController.Spec.Template.Spec)
|
pod.DropDisabledFields(&oldController.Spec.Template.Spec)
|
||||||
}
|
}
|
||||||
if newController.Spec.Template != nil {
|
if newController.Spec.Template != nil {
|
||||||
pod.DropDisabledAlphaFields(&newController.Spec.Template.Spec)
|
pod.DropDisabledFields(&newController.Spec.Template.Spec)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Any changes to the spec increment the generation number, any changes to the
|
// Any changes to the spec increment the generation number, any changes to the
|
||||||
|
|
Loading…
Reference in New Issue