mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 23:37:01 +00:00
Compute apply patch using versioned object
This commit is contained in:
parent
fcf5bbccd6
commit
3654d63766
@ -17,8 +17,6 @@ limitations under the License.
|
|||||||
package kubectl
|
package kubectl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api/annotations"
|
"k8s.io/kubernetes/pkg/api/annotations"
|
||||||
"k8s.io/kubernetes/pkg/api/meta"
|
"k8s.io/kubernetes/pkg/api/meta"
|
||||||
"k8s.io/kubernetes/pkg/kubectl/resource"
|
"k8s.io/kubernetes/pkg/kubectl/resource"
|
||||||
@ -96,7 +94,7 @@ func GetModifiedConfiguration(info *resource.Info, annotate bool, codec runtime.
|
|||||||
accessor.SetAnnotations(annots)
|
accessor.SetAnnotations(annots)
|
||||||
// TODO: this needs to be abstracted - there should be no assumption that versioned object
|
// TODO: this needs to be abstracted - there should be no assumption that versioned object
|
||||||
// can be marshalled to JSON.
|
// can be marshalled to JSON.
|
||||||
modified, err = json.Marshal(info.VersionedObject)
|
modified, err = runtime.Encode(codec, info.VersionedObject)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -106,7 +104,7 @@ func GetModifiedConfiguration(info *resource.Info, annotate bool, codec runtime.
|
|||||||
accessor.SetAnnotations(annots)
|
accessor.SetAnnotations(annots)
|
||||||
// TODO: this needs to be abstracted - there should be no assumption that versioned object
|
// TODO: this needs to be abstracted - there should be no assumption that versioned object
|
||||||
// can be marshalled to JSON.
|
// can be marshalled to JSON.
|
||||||
modified, err = json.Marshal(info.VersionedObject)
|
modified, err = runtime.Encode(codec, info.VersionedObject)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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)
|
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
|
// Create the versioned struct from the type defined in the restmapping
|
||||||
// strategic patch.
|
// (which is the API version we'll be submitting the patch to)
|
||||||
// TODO: Move all structs in apply to use raw data. Can be done once
|
versionedObject, err := api.Scheme.New(p.mapping.GroupVersionKind)
|
||||||
// builder has a RawResult method which delivers raw data instead of
|
|
||||||
// internal objects.
|
|
||||||
versionedObject, _, err := p.decoder.Decode(current, nil, nil)
|
|
||||||
if err != nil {
|
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.
|
// 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
|
// Optional, this is the provided object in a versioned type before defaulting
|
||||||
// and conversions into its corresponding internal type. This is useful for
|
// and conversions into its corresponding internal type. This is useful for
|
||||||
// reflecting on user intent which may be lost after defaulting and conversions.
|
// 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
|
// 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
|
// 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,
|
// 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
|
// but if set it should be equal to or newer than the resource version of the
|
||||||
|
Loading…
Reference in New Issue
Block a user