Revert "support patch list of primitives"

This reverts commit 34891ad9f6.
This commit is contained in:
ymqytw
2016-11-22 21:06:36 -08:00
parent 18f4395f80
commit 3cc294b1e0
27 changed files with 1661 additions and 2659 deletions

View File

@@ -23,7 +23,7 @@ import (
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/api/errors"
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/runtime"
"k8s.io/kubernetes/pkg/util/strategicpatch"
@@ -61,7 +61,7 @@ func handlePodUpdateError(out io.Writer, err error, resource string) {
return
}
} else {
if ok := cmdutil.PrintErrorWithCauses(err, out); ok {
if ok := kcmdutil.PrintErrorWithCauses(err, out); ok {
return
}
}
@@ -120,20 +120,8 @@ type Patch struct {
// CalculatePatches calls the mutation function on each provided info object, and generates a strategic merge patch for
// the changes in the object. Encoder must be able to encode the info into the appropriate destination type. If mutateFn
// returns false, the object is not included in the final list of patches.
// If local is true, it will be default to use SMPatchVersionLatest to calculate a patch without contacting the server to
// get the server supported SMPatchVersion. If you are using a patch's Patch field generated in local mode, be careful.
// If local is false, it will talk to the server to check which StategicMergePatchVersion to use.
func CalculatePatches(f cmdutil.Factory, infos []*resource.Info, encoder runtime.Encoder, local bool, mutateFn func(*resource.Info) (bool, error)) []*Patch {
func CalculatePatches(infos []*resource.Info, encoder runtime.Encoder, mutateFn func(*resource.Info) (bool, error)) []*Patch {
var patches []*Patch
smPatchVersion := strategicpatch.SMPatchVersionLatest
var err error
if !local {
smPatchVersion, err = cmdutil.GetServerSupportedSMPatchVersionFromFactory(f)
if err != nil {
return patches
}
}
for _, info := range infos {
patch := &Patch{Info: info}
patch.Before, patch.Err = runtime.Encode(encoder, info.Object)
@@ -168,7 +156,7 @@ func CalculatePatches(f cmdutil.Factory, infos []*resource.Info, encoder runtime
continue
}
patch.Patch, patch.Err = strategicpatch.CreateTwoWayMergePatch(patch.Before, patch.After, versioned, smPatchVersion)
patch.Patch, patch.Err = strategicpatch.CreateTwoWayMergePatch(patch.Before, patch.After, versioned)
}
return patches
}

View File

@@ -28,7 +28,6 @@ import (
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/runtime"
utilerrors "k8s.io/kubernetes/pkg/util/errors"
"k8s.io/kubernetes/pkg/util/strategicpatch"
)
// ImageOptions is the start of the data required to perform the operation. As new fields are added, add them here instead of
@@ -36,7 +35,6 @@ import (
type ImageOptions struct {
resource.FilenameOptions
f cmdutil.Factory
Mapper meta.RESTMapper
Typer runtime.ObjectTyper
Infos []*resource.Info
@@ -110,7 +108,6 @@ func NewCmdImage(f cmdutil.Factory, out, err io.Writer) *cobra.Command {
}
func (o *ImageOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
o.f = f
o.Mapper, o.Typer = f.Object()
o.UpdatePodSpecForObject = f.UpdatePodSpecForObject
o.Encoder = f.JSONEncoder()
@@ -165,7 +162,7 @@ func (o *ImageOptions) Validate() error {
func (o *ImageOptions) Run() error {
allErrs := []error{}
patches := CalculatePatches(o.f, o.Infos, o.Encoder, o.Local, func(info *resource.Info) (bool, error) {
patches := CalculatePatches(o.Infos, o.Encoder, func(info *resource.Info) (bool, error) {
transformed := false
_, err := o.UpdatePodSpecForObject(info.Object, func(spec *api.PodSpec) error {
for name, image := range o.ContainerImages {
@@ -189,14 +186,6 @@ func (o *ImageOptions) Run() error {
return transformed, err
})
smPatchVersion := strategicpatch.SMPatchVersionLatest
var err error
if !o.Local {
smPatchVersion, err = cmdutil.GetServerSupportedSMPatchVersionFromFactory(o.f)
if err != nil {
return err
}
}
for _, patch := range patches {
info := patch.Info
if patch.Err != nil {
@@ -223,7 +212,7 @@ func (o *ImageOptions) Run() error {
// record this change (for rollout history)
if o.Record || cmdutil.ContainsChangeCause(info) {
if patch, err := cmdutil.ChangeResourcePatch(info, o.ChangeCause, smPatchVersion); err == nil {
if patch, err := cmdutil.ChangeResourcePatch(info, o.ChangeCause); err == nil {
if obj, err = resource.NewHelper(info.Client, info.Mapping).Patch(info.Namespace, info.Name, api.StrategicMergePatchType, patch); err != nil {
fmt.Fprintf(o.Err, "WARNING: changes to %s/%s can't be recorded: %v\n", info.Mapping.Resource, info.Name, err)
}

View File

@@ -60,7 +60,6 @@ var (
type ResourcesOptions struct {
resource.FilenameOptions
f cmdutil.Factory
Mapper meta.RESTMapper
Typer runtime.ObjectTyper
Infos []*resource.Info
@@ -125,7 +124,6 @@ func NewCmdResources(f cmdutil.Factory, out io.Writer, errOut io.Writer) *cobra.
}
func (o *ResourcesOptions) Complete(f cmdutil.Factory, cmd *cobra.Command, args []string) error {
o.f = f
o.Mapper, o.Typer = f.Object()
o.UpdatePodSpecForObject = f.UpdatePodSpecForObject
o.Encoder = f.JSONEncoder()
@@ -176,7 +174,7 @@ func (o *ResourcesOptions) Validate() error {
func (o *ResourcesOptions) Run() error {
allErrs := []error{}
patches := CalculatePatches(o.f, o.Infos, o.Encoder, cmdutil.GetDryRunFlag(o.Cmd), func(info *resource.Info) (bool, error) {
patches := CalculatePatches(o.Infos, o.Encoder, func(info *resource.Info) (bool, error) {
transformed := false
_, err := o.UpdatePodSpecForObject(info.Object, func(spec *api.PodSpec) error {
containers, _ := selectContainers(spec.Containers, o.ContainerSelector)