Merge pull request #53158 from liggitt/update-pod-spec-versioned
Automatic merge from submit-queue (batch tested with PRs 53101, 53158, 52165). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Calculate patches for commands using input version Fixes #53040 the encoder used for encoding these objects while calculating patches does not have sufficient information to select a correct version when the object does not exist in all versions of a target group (like replicasets not existing in apps/v1beta1) this PR wraps the encoder to first convert to the same version used to read the object (based on the mapping's GroupVersion) long-term, we should switch UpdatePodSpecForObject to work on versioned objects and v1.PodSpec and avoid conversion altogether ```release-note Fixes an issue with `kubectl set` commands encountering conversion errors for ReplicaSet and DaemonSet objects ```
This commit is contained in:
@@ -126,7 +126,9 @@ type patchFn func(*resource.Info) ([]byte, error)
|
||||
// the changes in the object. Encoder must be able to encode the info into the appropriate destination type.
|
||||
// This function returns whether the mutation function made any change in the original object.
|
||||
func CalculatePatch(patch *Patch, encoder runtime.Encoder, mutateFn patchFn) bool {
|
||||
patch.Before, patch.Err = runtime.Encode(encoder, patch.Info.Object)
|
||||
versionedEncoder := api.Codecs.EncoderForVersion(encoder, patch.Info.Mapping.GroupVersionKind.GroupVersion())
|
||||
|
||||
patch.Before, patch.Err = runtime.Encode(versionedEncoder, patch.Info.Object)
|
||||
|
||||
patch.After, patch.Err = mutateFn(patch.Info)
|
||||
if patch.Err != nil {
|
||||
|
||||
@@ -381,7 +381,9 @@ func (o *EnvOptions) RunEnv(f cmdutil.Factory) error {
|
||||
})
|
||||
|
||||
if err == nil {
|
||||
return runtime.Encode(o.Encoder, info.Object)
|
||||
// TODO: switch UpdatePodSpecForObject to work on v1.PodSpec, use info.VersionedObject, and avoid conversion completely
|
||||
versionedEncoder := api.Codecs.EncoderForVersion(o.Encoder, info.Mapping.GroupVersionKind.GroupVersion())
|
||||
return runtime.Encode(versionedEncoder, info.Object)
|
||||
}
|
||||
return nil, err
|
||||
})
|
||||
|
||||
@@ -225,7 +225,9 @@ func (o *ImageOptions) Run() error {
|
||||
return nil
|
||||
})
|
||||
if transformed && err == nil {
|
||||
return runtime.Encode(o.Encoder, info.Object)
|
||||
// TODO: switch UpdatePodSpecForObject to work on v1.PodSpec, use info.VersionedObject, and avoid conversion completely
|
||||
versionedEncoder := api.Codecs.EncoderForVersion(o.Encoder, info.Mapping.GroupVersionKind.GroupVersion())
|
||||
return runtime.Encode(versionedEncoder, info.Object)
|
||||
}
|
||||
return nil, err
|
||||
})
|
||||
|
||||
@@ -216,7 +216,9 @@ func (o *ResourcesOptions) Run() error {
|
||||
return nil
|
||||
})
|
||||
if transformed && err == nil {
|
||||
return runtime.Encode(o.Encoder, info.Object)
|
||||
// TODO: switch UpdatePodSpecForObject to work on v1.PodSpec, use info.VersionedObject, and avoid conversion completely
|
||||
versionedEncoder := api.Codecs.EncoderForVersion(o.Encoder, info.Mapping.GroupVersionKind.GroupVersion())
|
||||
return runtime.Encode(versionedEncoder, info.Object)
|
||||
}
|
||||
return nil, err
|
||||
})
|
||||
|
||||
@@ -28,6 +28,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
utilerrors "k8s.io/apimachinery/pkg/util/errors"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/apis/rbac"
|
||||
"k8s.io/kubernetes/pkg/kubectl/cmd/templates"
|
||||
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
|
||||
@@ -218,7 +219,9 @@ func (o *SubjectOptions) Run(f cmdutil.Factory, fn updateSubjects) error {
|
||||
|
||||
transformed, err := updateSubjectForObject(info.Object, subjects, fn)
|
||||
if transformed && err == nil {
|
||||
return runtime.Encode(o.Encoder, info.Object)
|
||||
// TODO: switch UpdatePodSpecForObject to work on v1.PodSpec, use info.VersionedObject, and avoid conversion completely
|
||||
versionedEncoder := api.Codecs.EncoderForVersion(o.Encoder, info.Mapping.GroupVersionKind.GroupVersion())
|
||||
return runtime.Encode(versionedEncoder, info.Object)
|
||||
}
|
||||
return nil, err
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user