mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 22:46:12 +00:00
Merge pull request #49579 from deads2k/server-34-default
Automatic merge from submit-queue (batch tested with PRs 55798, 49579, 54862, 55188, 51990). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. add back defaulting for parameter decoding At the beginning of 1.7, we removed the last "conversion causes defaulting". This broke the "default to true" behavior for exec and attach options, but we didn't notice. This removes the broken defaulter (you can default a non-point bool to true on an object) and adds back defaulting to parameter codecs. @k8s-mirror-api-machinery-misc @lavalamp @smarterclayton
This commit is contained in:
commit
3c51f53960
@ -58,8 +58,6 @@ func TestDefaulting(t *testing.T) {
|
||||
{Group: "", Version: "v1", Kind: "PersistentVolumeList"}: {},
|
||||
{Group: "", Version: "v1", Kind: "PersistentVolumeClaim"}: {},
|
||||
{Group: "", Version: "v1", Kind: "PersistentVolumeClaimList"}: {},
|
||||
{Group: "", Version: "v1", Kind: "PodAttachOptions"}: {},
|
||||
{Group: "", Version: "v1", Kind: "PodExecOptions"}: {},
|
||||
{Group: "", Version: "v1", Kind: "Pod"}: {},
|
||||
{Group: "", Version: "v1", Kind: "PodList"}: {},
|
||||
{Group: "", Version: "v1", Kind: "PodTemplate"}: {},
|
||||
|
@ -39,14 +39,6 @@ func SetDefaults_ResourceList(obj *v1.ResourceList) {
|
||||
}
|
||||
}
|
||||
|
||||
func SetDefaults_PodExecOptions(obj *v1.PodExecOptions) {
|
||||
obj.Stdout = true
|
||||
obj.Stderr = true
|
||||
}
|
||||
func SetDefaults_PodAttachOptions(obj *v1.PodAttachOptions) {
|
||||
obj.Stdout = true
|
||||
obj.Stderr = true
|
||||
}
|
||||
func SetDefaults_ReplicationController(obj *v1.ReplicationController) {
|
||||
var labels map[string]string
|
||||
if obj.Spec.Template != nil {
|
||||
|
10
pkg/apis/core/v1/zz_generated.defaults.go
generated
10
pkg/apis/core/v1/zz_generated.defaults.go
generated
@ -46,8 +46,6 @@ func RegisterDefaults(scheme *runtime.Scheme) error {
|
||||
})
|
||||
scheme.AddTypeDefaultingFunc(&v1.PersistentVolumeList{}, func(obj interface{}) { SetObjectDefaults_PersistentVolumeList(obj.(*v1.PersistentVolumeList)) })
|
||||
scheme.AddTypeDefaultingFunc(&v1.Pod{}, func(obj interface{}) { SetObjectDefaults_Pod(obj.(*v1.Pod)) })
|
||||
scheme.AddTypeDefaultingFunc(&v1.PodAttachOptions{}, func(obj interface{}) { SetObjectDefaults_PodAttachOptions(obj.(*v1.PodAttachOptions)) })
|
||||
scheme.AddTypeDefaultingFunc(&v1.PodExecOptions{}, func(obj interface{}) { SetObjectDefaults_PodExecOptions(obj.(*v1.PodExecOptions)) })
|
||||
scheme.AddTypeDefaultingFunc(&v1.PodList{}, func(obj interface{}) { SetObjectDefaults_PodList(obj.(*v1.PodList)) })
|
||||
scheme.AddTypeDefaultingFunc(&v1.PodTemplate{}, func(obj interface{}) { SetObjectDefaults_PodTemplate(obj.(*v1.PodTemplate)) })
|
||||
scheme.AddTypeDefaultingFunc(&v1.PodTemplateList{}, func(obj interface{}) { SetObjectDefaults_PodTemplateList(obj.(*v1.PodTemplateList)) })
|
||||
@ -308,14 +306,6 @@ func SetObjectDefaults_Pod(in *v1.Pod) {
|
||||
}
|
||||
}
|
||||
|
||||
func SetObjectDefaults_PodAttachOptions(in *v1.PodAttachOptions) {
|
||||
SetDefaults_PodAttachOptions(in)
|
||||
}
|
||||
|
||||
func SetObjectDefaults_PodExecOptions(in *v1.PodExecOptions) {
|
||||
SetDefaults_PodExecOptions(in)
|
||||
}
|
||||
|
||||
func SetObjectDefaults_PodList(in *v1.PodList) {
|
||||
for i := range in.Items {
|
||||
a := &in.Items[i]
|
||||
|
@ -139,6 +139,7 @@ func NewParameterCodec(scheme *Scheme) ParameterCodec {
|
||||
typer: scheme,
|
||||
convertor: scheme,
|
||||
creator: scheme,
|
||||
defaulter: scheme,
|
||||
}
|
||||
}
|
||||
|
||||
@ -147,6 +148,7 @@ type parameterCodec struct {
|
||||
typer ObjectTyper
|
||||
convertor ObjectConvertor
|
||||
creator ObjectCreater
|
||||
defaulter ObjectDefaulter
|
||||
}
|
||||
|
||||
var _ ParameterCodec = ¶meterCodec{}
|
||||
@ -163,9 +165,17 @@ func (c *parameterCodec) DecodeParameters(parameters url.Values, from schema.Gro
|
||||
}
|
||||
for i := range targetGVKs {
|
||||
if targetGVKs[i].GroupVersion() == from {
|
||||
return c.convertor.Convert(¶meters, into, nil)
|
||||
if err := c.convertor.Convert(¶meters, into, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
// in the case where we going into the same object we're receiving, default on the outbound object
|
||||
if c.defaulter != nil {
|
||||
c.defaulter.Default(into)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
input, err := c.creator.New(from.WithKind(targetGVKs[0].Kind))
|
||||
if err != nil {
|
||||
return err
|
||||
@ -173,6 +183,10 @@ func (c *parameterCodec) DecodeParameters(parameters url.Values, from schema.Gro
|
||||
if err := c.convertor.Convert(¶meters, input, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
// if we have defaulter, default the input before converting to output
|
||||
if c.defaulter != nil {
|
||||
c.defaulter.Default(input)
|
||||
}
|
||||
return c.convertor.Convert(input, into, nil)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user