mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-17 02:06:23 +00:00
add userAgent info to create and update
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"k8s.io/apimachinery/pkg/api/errors"
|
||||
@@ -141,7 +142,7 @@ func createHandler(r rest.NamedCreater, scope RequestScope, admit admission.Inte
|
||||
return
|
||||
}
|
||||
|
||||
obj, err = scope.FieldManager.Update(liveObj, obj, "create")
|
||||
obj, err = scope.FieldManager.Update(liveObj, obj, prefixFromUserAgent(req.UserAgent()))
|
||||
if err != nil {
|
||||
scope.err(fmt.Errorf("failed to update object managed fields: %v", err), w, req)
|
||||
return
|
||||
@@ -198,3 +199,7 @@ type namedCreaterAdapter struct {
|
||||
func (c *namedCreaterAdapter) Create(ctx context.Context, name string, obj runtime.Object, createValidatingAdmission rest.ValidateObjectFunc, options *metav1.CreateOptions) (runtime.Object, error) {
|
||||
return c.Creater.Create(ctx, obj, createValidatingAdmission, options)
|
||||
}
|
||||
|
||||
func prefixFromUserAgent(u string) string {
|
||||
return strings.Split(u, "/")[0]
|
||||
}
|
||||
|
||||
@@ -551,7 +551,7 @@ func (p *patcher) patchResource(ctx context.Context, scope RequestScope) (runtim
|
||||
}
|
||||
|
||||
func (p *patcher) prefixFromUserAgent() string {
|
||||
return strings.Split(p.userAgent, "/")[0]
|
||||
return prefixFromUserAgent(p.userAgent)
|
||||
}
|
||||
|
||||
// applyPatchToObject applies a strategic merge patch of <patchMap> to
|
||||
|
||||
@@ -124,7 +124,7 @@ func UpdateResource(r rest.Updater, scope RequestScope, admit admission.Interfac
|
||||
transformers := []rest.TransformFunc{}
|
||||
if scope.FieldManager != nil {
|
||||
transformers = append(transformers, func(_ context.Context, newObj, liveObj runtime.Object) (runtime.Object, error) {
|
||||
if obj, err = scope.FieldManager.Update(liveObj, newObj, "update"); err != nil {
|
||||
if obj, err = scope.FieldManager.Update(liveObj, newObj, prefixFromUserAgent(req.UserAgent())); err != nil {
|
||||
return nil, fmt.Errorf("failed to update object managed fields: %v", err)
|
||||
}
|
||||
return obj, nil
|
||||
|
||||
Reference in New Issue
Block a user