mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-01-05 07:27:21 +00:00
remove unneeded factory codec methods
This commit is contained in:
@@ -62,7 +62,6 @@ type EditOptions struct {
|
||||
|
||||
ResourceMapper *resource.Mapper
|
||||
OriginalResult *resource.Result
|
||||
Encoder runtime.Encoder
|
||||
|
||||
EditMode EditMode
|
||||
|
||||
@@ -137,7 +136,6 @@ func (o *EditOptions) Complete(f cmdutil.Factory, out, errOut io.Writer, args []
|
||||
}
|
||||
|
||||
o.CmdNamespace = cmdNamespace
|
||||
o.Encoder = f.JSONEncoder()
|
||||
o.f = f
|
||||
|
||||
// Set up writer
|
||||
@@ -394,12 +392,12 @@ func (o *EditOptions) visitToApplyEditPatch(originalInfos []*resource.Info, patc
|
||||
return fmt.Errorf("no original object found for %#v", info.Object)
|
||||
}
|
||||
|
||||
originalJS, err := encodeToJson(o.Encoder, originalInfo.Object)
|
||||
originalJS, err := encodeToJson(cmdutil.InternalVersionJSONEncoder(), originalInfo.Object)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
editedJS, err := encodeToJson(o.Encoder, info.Object)
|
||||
editedJS, err := encodeToJson(cmdutil.InternalVersionJSONEncoder(), info.Object)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -420,7 +418,7 @@ func (o *EditOptions) visitToApplyEditPatch(originalInfos []*resource.Info, patc
|
||||
}
|
||||
|
||||
func (o *EditOptions) annotationPatch(update *resource.Info) error {
|
||||
patch, _, patchType, err := GetApplyPatch(update.Object, o.Encoder)
|
||||
patch, _, patchType, err := GetApplyPatch(update.Object, cmdutil.InternalVersionJSONEncoder())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -519,12 +517,12 @@ func (o *EditOptions) visitToPatch(originalInfos []*resource.Info, patchVisitor
|
||||
return fmt.Errorf("no original object found for %#v", info.Object)
|
||||
}
|
||||
|
||||
originalJS, err := encodeToJson(o.Encoder, originalInfo.Object)
|
||||
originalJS, err := encodeToJson(cmdutil.InternalVersionJSONEncoder(), originalInfo.Object)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
editedJS, err := encodeToJson(o.Encoder, info.Object)
|
||||
editedJS, err := encodeToJson(cmdutil.InternalVersionJSONEncoder(), info.Object)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -607,7 +605,7 @@ func (o *EditOptions) visitAnnotation(annotationVisitor resource.Visitor) error
|
||||
err := annotationVisitor.Visit(func(info *resource.Info, incomingErr error) error {
|
||||
// put configuration annotation in "updates"
|
||||
if o.ApplyAnnotation {
|
||||
if err := kubectl.CreateOrUpdateAnnotation(true, info, o.Encoder); err != nil {
|
||||
if err := kubectl.CreateOrUpdateAnnotation(true, info, cmdutil.InternalVersionJSONEncoder()); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,13 +112,6 @@ type ClientAccessFactory interface {
|
||||
// TODO remove. This should be rolled into `ClientConfig`
|
||||
ClientConfigForVersion(requiredVersion *schema.GroupVersion) (*restclient.Config, error)
|
||||
|
||||
// Returns interfaces for decoding objects - if toInternal is set, decoded objects will be converted
|
||||
// into their internal form (if possible). Eventually the internal form will be removed as an option,
|
||||
// and only versioned objects will be returned.
|
||||
Decoder(toInternal bool) runtime.Decoder
|
||||
// Returns an encoder capable of encoding a provided object into JSON in the default desired version.
|
||||
JSONEncoder() runtime.Encoder
|
||||
|
||||
// UpdatePodSpecForObject will call the provided function on the pod spec this object supports,
|
||||
// return false if no pod spec is supported, or return an error.
|
||||
UpdatePodSpecForObject(obj runtime.Object, fn func(*v1.PodSpec) error) (bool, error)
|
||||
|
||||
@@ -54,7 +54,7 @@ func (f *ring2Factory) NewBuilder() *resource.Builder {
|
||||
RESTMapper: mapper,
|
||||
ObjectTyper: typer,
|
||||
ClientMapper: clientMapperFunc,
|
||||
Decoder: f.clientAccessFactory.Decoder(true),
|
||||
Decoder: InternalVersionDecoder(),
|
||||
},
|
||||
&resource.Mapper{
|
||||
RESTMapper: mapper,
|
||||
|
||||
@@ -231,20 +231,6 @@ func (f *ring0Factory) RESTClient() (*restclient.RESTClient, error) {
|
||||
return restclient.RESTClientFor(clientConfig)
|
||||
}
|
||||
|
||||
func (f *ring0Factory) Decoder(toInternal bool) runtime.Decoder {
|
||||
var decoder runtime.Decoder
|
||||
if toInternal {
|
||||
decoder = legacyscheme.Codecs.UniversalDecoder()
|
||||
} else {
|
||||
decoder = legacyscheme.Codecs.UniversalDeserializer()
|
||||
}
|
||||
return decoder
|
||||
}
|
||||
|
||||
func (f *ring0Factory) JSONEncoder() runtime.Encoder {
|
||||
return legacyscheme.Codecs.LegacyCodec(legacyscheme.Registry.EnabledVersions()...)
|
||||
}
|
||||
|
||||
func (f *ring0Factory) UpdatePodSpecForObject(obj runtime.Object, fn func(*v1.PodSpec) error) (bool, error) {
|
||||
// TODO: replace with a swagger schema based approach (identify pod template via schema introspection)
|
||||
switch t := obj.(type) {
|
||||
@@ -451,7 +437,7 @@ func (f *ring0Factory) Pauser(info *resource.Info) ([]byte, error) {
|
||||
return nil, errors.New("is already paused")
|
||||
}
|
||||
obj.Spec.Paused = true
|
||||
return runtime.Encode(f.JSONEncoder(), info.Object)
|
||||
return runtime.Encode(InternalVersionJSONEncoder(), info.Object)
|
||||
default:
|
||||
return nil, fmt.Errorf("pausing is not supported")
|
||||
}
|
||||
@@ -468,7 +454,7 @@ func (f *ring0Factory) Resumer(info *resource.Info) ([]byte, error) {
|
||||
return nil, errors.New("is not paused")
|
||||
}
|
||||
obj.Spec.Paused = false
|
||||
return runtime.Encode(f.JSONEncoder(), info.Object)
|
||||
return runtime.Encode(InternalVersionJSONEncoder(), info.Object)
|
||||
default:
|
||||
return nil, fmt.Errorf("resuming is not supported")
|
||||
}
|
||||
@@ -714,3 +700,12 @@ func computeDiscoverCacheDir(parentDir, host string) string {
|
||||
|
||||
return filepath.Join(parentDir, safeHost)
|
||||
}
|
||||
|
||||
// this method exists to help us find the points still relying on internal types.
|
||||
func InternalVersionDecoder() runtime.Decoder {
|
||||
return legacyscheme.Codecs.UniversalDecoder()
|
||||
}
|
||||
|
||||
func InternalVersionJSONEncoder() runtime.Encoder {
|
||||
return legacyscheme.Codecs.LegacyCodec(legacyscheme.Registry.EnabledVersions()...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user