mirror of
https://github.com/kubernetes/client-go.git
synced 2025-09-08 10:29:25 +00:00
published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub) copied from https://github.com/kubernetes/kubernetes.git, branch master, last commit is 5b2823adb9a8777f7819884fa79a6e1daa26b9c2
This commit is contained in:
@@ -41,8 +41,11 @@ type ObjectTracker interface {
|
||||
// Get retrieves the object by its kind, namespace and name.
|
||||
Get(gvk schema.GroupVersionKind, ns, name string) (runtime.Object, error)
|
||||
|
||||
// Update updates an existing object in the tracker.
|
||||
Update(obj runtime.Object) error
|
||||
// Create adds an object to the tracker in the specified namespace.
|
||||
Create(obj runtime.Object, ns string) error
|
||||
|
||||
// Update updates an existing object in the tracker in the specified namespace.
|
||||
Update(obj runtime.Object, ns string) error
|
||||
|
||||
// List retrieves all objects of a given kind in the given
|
||||
// namespace. Only non-List kinds are accepted.
|
||||
@@ -102,12 +105,12 @@ func ObjectReaction(tracker ObjectTracker, mapper meta.RESTMapper) ReactionFunc
|
||||
return true, nil, err
|
||||
}
|
||||
if action.GetSubresource() == "" {
|
||||
err = tracker.Add(action.GetObject())
|
||||
err = tracker.Create(action.GetObject(), ns)
|
||||
} else {
|
||||
// TODO: Currently we're handling subresource creation as an update
|
||||
// on the enclosing resource. This works for some subresources but
|
||||
// might not be generic enough.
|
||||
err = tracker.Update(action.GetObject())
|
||||
err = tracker.Update(action.GetObject(), ns)
|
||||
}
|
||||
if err != nil {
|
||||
return true, nil, err
|
||||
@@ -120,7 +123,7 @@ func ObjectReaction(tracker ObjectTracker, mapper meta.RESTMapper) ReactionFunc
|
||||
if err != nil {
|
||||
return true, nil, err
|
||||
}
|
||||
err = tracker.Update(action.GetObject())
|
||||
err = tracker.Update(action.GetObject(), ns)
|
||||
if err != nil {
|
||||
return true, nil, err
|
||||
}
|
||||
@@ -243,18 +246,26 @@ func (t *tracker) Get(gvk schema.GroupVersionKind, ns, name string) (runtime.Obj
|
||||
}
|
||||
|
||||
func (t *tracker) Add(obj runtime.Object) error {
|
||||
return t.add(obj, false)
|
||||
}
|
||||
|
||||
func (t *tracker) Update(obj runtime.Object) error {
|
||||
return t.add(obj, true)
|
||||
}
|
||||
|
||||
func (t *tracker) add(obj runtime.Object, replaceExisting bool) error {
|
||||
if meta.IsListType(obj) {
|
||||
return t.addList(obj, replaceExisting)
|
||||
return t.addList(obj, false)
|
||||
}
|
||||
|
||||
objMeta, err := meta.Accessor(obj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return t.add(obj, objMeta.GetNamespace(), false)
|
||||
}
|
||||
|
||||
func (t *tracker) Create(obj runtime.Object, ns string) error {
|
||||
return t.add(obj, ns, false)
|
||||
}
|
||||
|
||||
func (t *tracker) Update(obj runtime.Object, ns string) error {
|
||||
return t.add(obj, ns, true)
|
||||
}
|
||||
|
||||
func (t *tracker) add(obj runtime.Object, ns string, replaceExisting bool) error {
|
||||
gvks, _, err := t.scheme.ObjectKinds(obj)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -286,6 +297,16 @@ func (t *tracker) add(obj runtime.Object, replaceExisting bool) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// Propagate namespace to the new object if hasn't already been set.
|
||||
if len(newMeta.GetNamespace()) == 0 {
|
||||
newMeta.SetNamespace(ns)
|
||||
}
|
||||
|
||||
if ns != newMeta.GetNamespace() {
|
||||
msg := fmt.Sprintf("request namespace does not match object namespace, request: %q object: %q", ns, newMeta.GetNamespace())
|
||||
return errors.NewBadRequest(msg)
|
||||
}
|
||||
|
||||
if err := checkNamespace(gvk, newMeta.GetNamespace()); err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -325,7 +346,11 @@ func (t *tracker) addList(obj runtime.Object, replaceExisting bool) error {
|
||||
return errs[0]
|
||||
}
|
||||
for _, obj := range list {
|
||||
err := t.add(obj, replaceExisting)
|
||||
objMeta, err := meta.Accessor(obj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = t.add(obj, objMeta.GetNamespace(), replaceExisting)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user