Merge pull request #50924 from liggitt/alpha-fields

Automatic merge from submit-queue (batch tested with PRs 51682, 51546, 51369, 50924, 51827)

Clear values for disabled alpha fields

Fixes #51831

Before persisting new or updated resources, alpha fields that are disabled by feature gate must be removed from the incoming objects.

This adds a helper for clearing these values for pod specs and calls it from the strategies of all in-tree resources containing pod specs.

Addresses https://github.com/kubernetes/community/pull/869
This commit is contained in:
Kubernetes Submit Queue
2017-09-03 15:54:22 -07:00
committed by GitHub
22 changed files with 107 additions and 3 deletions

View File

@@ -16,6 +16,7 @@ go_library(
deps = [
"//pkg/api:go_default_library",
"//pkg/api/helper:go_default_library",
"//pkg/api/pod:go_default_library",
"//pkg/api/validation:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/api/equality:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/internalversion:go_default_library",

View File

@@ -35,6 +35,7 @@ import (
"k8s.io/apiserver/pkg/storage/names"
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/helper"
"k8s.io/kubernetes/pkg/api/pod"
"k8s.io/kubernetes/pkg/api/validation"
)
@@ -64,6 +65,10 @@ func (rcStrategy) PrepareForCreate(ctx genericapirequest.Context, obj runtime.Ob
controller.Status = api.ReplicationControllerStatus{}
controller.Generation = 1
if controller.Spec.Template != nil {
pod.DropDisabledAlphaFields(&controller.Spec.Template.Spec)
}
}
// PrepareForUpdate clears fields that are not allowed to be set by end users on update.
@@ -73,6 +78,13 @@ func (rcStrategy) PrepareForUpdate(ctx genericapirequest.Context, obj, old runti
// update is not allowed to set status
newController.Status = oldController.Status
if oldController.Spec.Template != nil {
pod.DropDisabledAlphaFields(&oldController.Spec.Template.Spec)
}
if newController.Spec.Template != nil {
pod.DropDisabledAlphaFields(&newController.Spec.Template.Spec)
}
// 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
// the burden of managing the status onto the clients because we can't (in general)