mirror of https://github.com/k3s-io/k3s
Compute apply patch using versioned object
parent
fcf5bbccd6
commit
3654d63766
|
@ -17,8 +17,6 @@ limitations under the License.
|
|||
package kubectl
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api/annotations"
|
||||
"k8s.io/kubernetes/pkg/api/meta"
|
||||
"k8s.io/kubernetes/pkg/kubectl/resource"
|
||||
|
@ -96,7 +94,7 @@ func GetModifiedConfiguration(info *resource.Info, annotate bool, codec runtime.
|
|||
accessor.SetAnnotations(annots)
|
||||
// TODO: this needs to be abstracted - there should be no assumption that versioned object
|
||||
// can be marshalled to JSON.
|
||||
modified, err = json.Marshal(info.VersionedObject)
|
||||
modified, err = runtime.Encode(codec, info.VersionedObject)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -106,7 +104,7 @@ func GetModifiedConfiguration(info *resource.Info, annotate bool, codec runtime.
|
|||
accessor.SetAnnotations(annots)
|
||||
// TODO: this needs to be abstracted - there should be no assumption that versioned object
|
||||
// can be marshalled to JSON.
|
||||
modified, err = json.Marshal(info.VersionedObject)
|
||||
modified, err = runtime.Encode(codec, info.VersionedObject)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -527,14 +527,11 @@ func (p *patcher) patchSimple(obj runtime.Object, modified []byte, source, names
|
|||
return nil, cmdutil.AddSourceToErr(fmt.Sprintf("retrieving original configuration from:\n%v\nfor:", obj), source, err)
|
||||
}
|
||||
|
||||
// Create the versioned struct from the original from the server for
|
||||
// strategic patch.
|
||||
// TODO: Move all structs in apply to use raw data. Can be done once
|
||||
// builder has a RawResult method which delivers raw data instead of
|
||||
// internal objects.
|
||||
versionedObject, _, err := p.decoder.Decode(current, nil, nil)
|
||||
// Create the versioned struct from the type defined in the restmapping
|
||||
// (which is the API version we'll be submitting the patch to)
|
||||
versionedObject, err := api.Scheme.New(p.mapping.GroupVersionKind)
|
||||
if err != nil {
|
||||
return nil, cmdutil.AddSourceToErr(fmt.Sprintf("converting encoded server-side object back to versioned struct:\n%v\nfor:", obj), source, err)
|
||||
return nil, cmdutil.AddSourceToErr(fmt.Sprintf("getting instance of versioned object for %v:", p.mapping.GroupVersionKind), source, err)
|
||||
}
|
||||
|
||||
// Compute a three way strategic merge patch to send to server.
|
||||
|
|
|
@ -81,9 +81,9 @@ type Info struct {
|
|||
// Optional, this is the provided object in a versioned type before defaulting
|
||||
// and conversions into its corresponding internal type. This is useful for
|
||||
// reflecting on user intent which may be lost after defaulting and conversions.
|
||||
VersionedObject interface{}
|
||||
VersionedObject runtime.Object
|
||||
// Optional, this is the most recent value returned by the server if available
|
||||
runtime.Object
|
||||
Object runtime.Object
|
||||
// Optional, this is the most recent resource version the server knows about for
|
||||
// this type of resource. It may not match the resource version of the object,
|
||||
// but if set it should be equal to or newer than the resource version of the
|
||||
|
|
Loading…
Reference in New Issue