mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-17 02:06:23 +00:00
try a different way to handle the userAgent
This commit is contained in:
@@ -18,6 +18,7 @@ package fieldmanager
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
@@ -97,6 +98,8 @@ func (f *FieldManager) Update(liveObj, newObj runtime.Object, manager string) (r
|
||||
return nil, fmt.Errorf("failed to create typed live object: %v", err)
|
||||
}
|
||||
apiVersion := fieldpath.APIVersion(f.groupVersion.String())
|
||||
manager = f.buildManagerInfo(manager, f.groupVersion.String())
|
||||
|
||||
managed, err = f.updater.Update(liveObjTyped, newObjTyped, apiVersion, managed, manager)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to update ManagedFields: %v", err)
|
||||
@@ -172,3 +175,8 @@ func (f *FieldManager) toVersioned(obj runtime.Object) (runtime.Object, error) {
|
||||
func (f *FieldManager) toUnversioned(obj runtime.Object) (runtime.Object, error) {
|
||||
return f.objectConverter.ConvertToVersion(obj, f.hubVersion)
|
||||
}
|
||||
|
||||
func (f *FieldManager) buildManagerInfo(prefix, version string) string {
|
||||
timestamp := time.Now().Format("20060102-150405")
|
||||
return fmt.Sprintf("%s-%s@%s", prefix, version, timestamp)
|
||||
}
|
||||
|
||||
@@ -313,7 +313,7 @@ func (p *jsonPatcher) applyPatchToCurrentObject(currentObject runtime.Object) (r
|
||||
}
|
||||
|
||||
if p.fieldManager != nil {
|
||||
if objToUpdate, err = p.fieldManager.Update(currentObject, objToUpdate, p.buildManagerInfo(objToUpdate.GetObjectKind().GroupVersionKind().Version)); err != nil {
|
||||
if objToUpdate, err = p.fieldManager.Update(currentObject, objToUpdate, stripUserAgent(p.userAgent)); err != nil {
|
||||
return nil, fmt.Errorf("failed to update object managed fields: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -375,7 +375,7 @@ func (p *smpPatcher) applyPatchToCurrentObject(currentObject runtime.Object) (ru
|
||||
}
|
||||
|
||||
if p.fieldManager != nil {
|
||||
if newObj, err = p.fieldManager.Update(currentObject, newObj, p.buildManagerInfo(newObj.GetObjectKind().GroupVersionKind().Version)); err != nil {
|
||||
if newObj, err = p.fieldManager.Update(currentObject, newObj, stripUserAgent(p.userAgent)); err != nil {
|
||||
return nil, fmt.Errorf("failed to update object managed fields: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -549,13 +549,6 @@ func (p *patcher) patchResource(ctx context.Context, scope RequestScope) (runtim
|
||||
return result, wasCreated, err
|
||||
}
|
||||
|
||||
func (p *patcher) buildManagerInfo(version string) string {
|
||||
userAgent := strings.Split(p.userAgent, "/")[0]
|
||||
timestamp := time.Now().Format("20060102-150405")
|
||||
|
||||
return fmt.Sprintf("%s-%s@%s", userAgent, version, timestamp)
|
||||
}
|
||||
|
||||
// applyPatchToObject applies a strategic merge patch of <patchMap> to
|
||||
// <originalMap> and stores the result in <objToUpdate>.
|
||||
// NOTE: <objToUpdate> must be a versioned object.
|
||||
@@ -602,3 +595,7 @@ func patchToUpdateOptions(po *metav1.PatchOptions) (*metav1.UpdateOptions, error
|
||||
err = json.Unmarshal(b, &uo)
|
||||
return &uo, err
|
||||
}
|
||||
|
||||
func stripUserAgent(userAgent string) string {
|
||||
return strings.Split(userAgent, "/")[0]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user