Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add back defaulting for parameter decoding #49579

Merged
merged 2 commits into from
Nov 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions pkg/api/testing/defaulting_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}: {},
Expand Down
8 changes: 0 additions & 8 deletions pkg/apis/core/v1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 0 additions & 10 deletions pkg/apis/core/v1/zz_generated.defaults.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion staging/src/k8s.io/apimachinery/pkg/runtime/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func NewParameterCodec(scheme *Scheme) ParameterCodec {
typer: scheme,
convertor: scheme,
creator: scheme,
defaulter: scheme,
}
}

Expand All @@ -147,6 +148,7 @@ type parameterCodec struct {
typer ObjectTyper
convertor ObjectConvertor
creator ObjectCreater
defaulter ObjectDefaulter
}

var _ ParameterCodec = &parameterCodec{}
Expand All @@ -163,16 +165,28 @@ func (c *parameterCodec) DecodeParameters(parameters url.Values, from schema.Gro
}
for i := range targetGVKs {
if targetGVKs[i].GroupVersion() == from {
return c.convertor.Convert(&parameters, into, nil)
if err := c.convertor.Convert(&parameters, 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
}
if err := c.convertor.Convert(&parameters, 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)
}

Expand Down