Skip to content

Commit

Permalink
make the parameter codec include defaulters
Browse files Browse the repository at this point in the history
  • Loading branch information
deads2k committed Nov 14, 2017
1 parent 149e5a2 commit 18552ce
Showing 1 changed file with 15 additions and 1 deletion.
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

0 comments on commit 18552ce

Please sign in to comment.