mirror of
https://github.com/optim-enterprises-bv/kubernetes.git
synced 2025-11-01 10:48:15 +00:00
Revert "try old patch after new patch fails"
This reverts commit f32696e734.
This commit is contained in:
@@ -195,6 +195,11 @@ func RunApply(f cmdutil.Factory, cmd *cobra.Command, out io.Writer, options *App
|
||||
visitedUids := sets.NewString()
|
||||
visitedNamespaces := sets.NewString()
|
||||
|
||||
smPatchVersion, err := cmdutil.GetServerSupportedSMPatchVersionFromFactory(f)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
count := 0
|
||||
err = r.Visit(func(info *resource.Info, err error) error {
|
||||
// In this method, info.Object contains the object retrieved from the server
|
||||
@@ -265,13 +270,13 @@ func RunApply(f cmdutil.Factory, cmd *cobra.Command, out io.Writer, options *App
|
||||
gracePeriod: options.GracePeriod,
|
||||
}
|
||||
|
||||
patchBytes, err := patcher.patch(info.Object, modified, info.Source, info.Namespace, info.Name)
|
||||
patchBytes, err := patcher.patch(info.Object, modified, info.Source, info.Namespace, info.Name, smPatchVersion)
|
||||
if err != nil {
|
||||
return cmdutil.AddSourceToErr(fmt.Sprintf("applying patch:\n%s\nto:\n%v\nfor:", patchBytes, info), info.Source, err)
|
||||
}
|
||||
|
||||
if cmdutil.ShouldRecord(cmd, info) {
|
||||
patch, err := cmdutil.ChangeResourcePatch(info, f.Command())
|
||||
patch, err := cmdutil.ChangeResourcePatch(info, f.Command(), smPatchVersion)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -507,7 +512,7 @@ type patcher struct {
|
||||
gracePeriod int
|
||||
}
|
||||
|
||||
func (p *patcher) patchSimple(obj runtime.Object, modified []byte, source, namespace, name string) ([]byte, error) {
|
||||
func (p *patcher) patchSimple(obj runtime.Object, modified []byte, source, namespace, name string, smPatchVersion strategicpatch.StrategicMergePatchVersion) ([]byte, error) {
|
||||
// Serialize the current configuration of the object from the server.
|
||||
current, err := runtime.Encode(p.encoder, obj)
|
||||
if err != nil {
|
||||
@@ -531,27 +536,20 @@ func (p *patcher) patchSimple(obj runtime.Object, modified []byte, source, names
|
||||
}
|
||||
|
||||
// Compute a three way strategic merge patch to send to server.
|
||||
patch, err := strategicpatch.CreateThreeWayMergePatch(original, modified, current, versionedObject, p.overwrite, strategicpatch.SMPatchVersion_1_5)
|
||||
patch, err := strategicpatch.CreateThreeWayMergePatch(original, modified, current, versionedObject, p.overwrite, smPatchVersion)
|
||||
|
||||
if err != nil {
|
||||
format := "creating patch with:\noriginal:\n%s\nmodified:\n%s\ncurrent:\n%s\nfor:"
|
||||
return nil, cmdutil.AddSourceToErr(fmt.Sprintf(format, original, modified, current), source, err)
|
||||
}
|
||||
|
||||
_, err = p.helper.Patch(namespace, name, api.StrategicMergePatchType, patch)
|
||||
if err != nil {
|
||||
// Retry SMPatchVersion_1_0 when applying the SMPatchVersion_1_5 patch
|
||||
patch, err = strategicpatch.CreateThreeWayMergePatch(original, modified, current, versionedObject, p.overwrite, strategicpatch.SMPatchVersion_1_0)
|
||||
if err != nil {
|
||||
format := "creating patch with:\noriginal:\n%s\nmodified:\n%s\ncurrent:\n%s\nfor:"
|
||||
return nil, cmdutil.AddSourceToErr(fmt.Sprintf(format, original, modified, current), source, err)
|
||||
}
|
||||
_, err = p.helper.Patch(namespace, name, api.StrategicMergePatchType, patch)
|
||||
}
|
||||
return patch, err
|
||||
}
|
||||
|
||||
func (p *patcher) patch(current runtime.Object, modified []byte, source, namespace, name string) ([]byte, error) {
|
||||
func (p *patcher) patch(current runtime.Object, modified []byte, source, namespace, name string, smPatchVersion strategicpatch.StrategicMergePatchVersion) ([]byte, error) {
|
||||
var getErr error
|
||||
patchBytes, err := p.patchSimple(current, modified, source, namespace, name)
|
||||
patchBytes, err := p.patchSimple(current, modified, source, namespace, name, smPatchVersion)
|
||||
for i := 1; i <= maxPatchRetry && errors.IsConflict(err); i++ {
|
||||
if i > triesBeforeBackOff {
|
||||
p.backOff.Sleep(backOffPeriod)
|
||||
@@ -560,7 +558,7 @@ func (p *patcher) patch(current runtime.Object, modified []byte, source, namespa
|
||||
if getErr != nil {
|
||||
return nil, getErr
|
||||
}
|
||||
patchBytes, err = p.patchSimple(current, modified, source, namespace, name)
|
||||
patchBytes, err = p.patchSimple(current, modified, source, namespace, name, smPatchVersion)
|
||||
}
|
||||
if err != nil && p.force {
|
||||
patchBytes, err = p.deleteAndCreate(modified, namespace, name)
|
||||
|
||||
Reference in New Issue
Block a user