show patch error as string not byte slice
Kubernetes-commit: ea887557d36cec45744c11019aa3fd64d44f24f7
This commit is contained in:
parent
af3692a43f
commit
e8086d93fd
|
|
@ -565,11 +565,12 @@ func patchResource(
|
||||||
namespace := request.NamespaceValue(ctx)
|
namespace := request.NamespaceValue(ctx)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
originalObjJS []byte
|
originalObjJS []byte
|
||||||
originalPatchedObjJS []byte
|
originalPatchedObjJS []byte
|
||||||
originalObjMap map[string]interface{}
|
originalObjMap map[string]interface{}
|
||||||
originalPatchMap map[string]interface{}
|
originalPatchMap map[string]interface{}
|
||||||
lastConflictErr error
|
lastConflictErr error
|
||||||
|
originalResourceVersion string
|
||||||
)
|
)
|
||||||
|
|
||||||
// applyPatch is called every time GuaranteedUpdate asks for the updated object,
|
// applyPatch is called every time GuaranteedUpdate asks for the updated object,
|
||||||
|
|
@ -582,12 +583,18 @@ func patchResource(
|
||||||
return nil, errors.NewNotFound(resource.GroupResource(), name)
|
return nil, errors.NewNotFound(resource.GroupResource(), name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
currentResourceVersion := ""
|
||||||
|
if currentMetadata, err := meta.Accessor(currentObject); err == nil {
|
||||||
|
currentResourceVersion = currentMetadata.GetResourceVersion()
|
||||||
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case originalObjJS == nil && originalObjMap == nil:
|
case originalObjJS == nil && originalObjMap == nil:
|
||||||
// first time through,
|
// first time through,
|
||||||
// 1. apply the patch
|
// 1. apply the patch
|
||||||
// 2. save the original and patched to detect whether there were conflicting changes on retries
|
// 2. save the original and patched to detect whether there were conflicting changes on retries
|
||||||
|
|
||||||
|
originalResourceVersion = currentResourceVersion
|
||||||
objToUpdate := patcher.New()
|
objToUpdate := patcher.New()
|
||||||
|
|
||||||
// For performance reasons, in case of strategicpatch, we avoid json
|
// For performance reasons, in case of strategicpatch, we avoid json
|
||||||
|
|
@ -690,11 +697,12 @@ func patchResource(
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if hasConflicts {
|
if hasConflicts {
|
||||||
diff1, _ := json.Marshal(currentPatchMap)
|
diff1, _ := json.Marshal(currentPatchMap)
|
||||||
diff2, _ := json.Marshal(originalPatchMap)
|
diff2, _ := json.Marshal(originalPatchMap)
|
||||||
patchDiffErr := fmt.Errorf("there is a meaningful conflict:\n diff1=%v\n, diff2=%v\n", diff1, diff2)
|
patchDiffErr := fmt.Errorf("there is a meaningful conflict (firstResourceVersion: %q, currentResourceVersion: %q):\n diff1=%v\n, diff2=%v\n", originalResourceVersion, currentResourceVersion, string(diff1), string(diff2))
|
||||||
glog.V(4).Infof("patchResource failed for resource %s, because there is a meaningful conflict.\n diff1=%v\n, diff2=%v\n", name, diff1, diff2)
|
glog.V(4).Infof("patchResource failed for resource %s, because there is a meaningful conflict(firstResourceVersion: %q, currentResourceVersion: %q):\n diff1=%v\n, diff2=%v\n", name, originalResourceVersion, currentResourceVersion, string(diff1), string(diff2))
|
||||||
|
|
||||||
// Return the last conflict error we got if we have one
|
// Return the last conflict error we got if we have one
|
||||||
if lastConflictErr != nil {
|
if lastConflictErr != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue