|
| 1 | +/* |
| 2 | +Copyright 2016 The Kubernetes Authors. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package fake |
| 18 | + |
| 19 | +import ( |
| 20 | + api "k8s.io/kubernetes/pkg/api" |
| 21 | + unversioned "k8s.io/kubernetes/pkg/api/unversioned" |
| 22 | + core "k8s.io/kubernetes/pkg/client/testing/core" |
| 23 | + labels "k8s.io/kubernetes/pkg/labels" |
| 24 | + watch "k8s.io/kubernetes/pkg/watch" |
| 25 | +) |
| 26 | + |
| 27 | +// FakeNamespaces implements NamespaceInterface |
| 28 | +type FakeNamespaces struct { |
| 29 | + Fake *FakeCore |
| 30 | +} |
| 31 | + |
| 32 | +var namespacesResource = unversioned.GroupVersionResource{Group: "", Version: "", Resource: "namespaces"} |
| 33 | + |
| 34 | +func (c *FakeNamespaces) Create(namespace *api.Namespace) (result *api.Namespace, err error) { |
| 35 | + obj, err := c.Fake. |
| 36 | + Invokes(core.NewRootCreateAction(namespacesResource, namespace), &api.Namespace{}) |
| 37 | + if obj == nil { |
| 38 | + return nil, err |
| 39 | + } |
| 40 | + return obj.(*api.Namespace), err |
| 41 | +} |
| 42 | + |
| 43 | +func (c *FakeNamespaces) Update(namespace *api.Namespace) (result *api.Namespace, err error) { |
| 44 | + obj, err := c.Fake. |
| 45 | + Invokes(core.NewRootUpdateAction(namespacesResource, namespace), &api.Namespace{}) |
| 46 | + if obj == nil { |
| 47 | + return nil, err |
| 48 | + } |
| 49 | + return obj.(*api.Namespace), err |
| 50 | +} |
| 51 | + |
| 52 | +func (c *FakeNamespaces) UpdateStatus(namespace *api.Namespace) (*api.Namespace, error) { |
| 53 | + obj, err := c.Fake. |
| 54 | + Invokes(core.NewRootUpdateSubresourceAction(namespacesResource, "status", namespace), &api.Namespace{}) |
| 55 | + if obj == nil { |
| 56 | + return nil, err |
| 57 | + } |
| 58 | + return obj.(*api.Namespace), err |
| 59 | +} |
| 60 | + |
| 61 | +func (c *FakeNamespaces) Delete(name string, options *api.DeleteOptions) error { |
| 62 | + _, err := c.Fake. |
| 63 | + Invokes(core.NewRootDeleteAction(namespacesResource, name), &api.Namespace{}) |
| 64 | + return err |
| 65 | +} |
| 66 | + |
| 67 | +func (c *FakeNamespaces) DeleteCollection(options *api.DeleteOptions, listOptions api.ListOptions) error { |
| 68 | + action := core.NewRootDeleteCollectionAction(namespacesResource, listOptions) |
| 69 | + |
| 70 | + _, err := c.Fake.Invokes(action, &api.NamespaceList{}) |
| 71 | + return err |
| 72 | +} |
| 73 | + |
| 74 | +func (c *FakeNamespaces) Get(name string) (result *api.Namespace, err error) { |
| 75 | + obj, err := c.Fake. |
| 76 | + Invokes(core.NewRootGetAction(namespacesResource, name), &api.Namespace{}) |
| 77 | + if obj == nil { |
| 78 | + return nil, err |
| 79 | + } |
| 80 | + return obj.(*api.Namespace), err |
| 81 | +} |
| 82 | + |
| 83 | +func (c *FakeNamespaces) List(opts api.ListOptions) (result *api.NamespaceList, err error) { |
| 84 | + obj, err := c.Fake. |
| 85 | + Invokes(core.NewRootListAction(namespacesResource, opts), &api.NamespaceList{}) |
| 86 | + if obj == nil { |
| 87 | + return nil, err |
| 88 | + } |
| 89 | + |
| 90 | + label := opts.LabelSelector |
| 91 | + if label == nil { |
| 92 | + label = labels.Everything() |
| 93 | + } |
| 94 | + list := &api.NamespaceList{} |
| 95 | + for _, item := range obj.(*api.NamespaceList).Items { |
| 96 | + if label.Matches(labels.Set(item.Labels)) { |
| 97 | + list.Items = append(list.Items, item) |
| 98 | + } |
| 99 | + } |
| 100 | + return list, err |
| 101 | +} |
| 102 | + |
| 103 | +// Watch returns a watch.Interface that watches the requested namespaces. |
| 104 | +func (c *FakeNamespaces) Watch(opts api.ListOptions) (watch.Interface, error) { |
| 105 | + return c.Fake. |
| 106 | + InvokesWatch(core.NewRootWatchAction(namespacesResource, opts)) |
| 107 | +} |
| 108 | + |
| 109 | +// Patch applies the patch and returns the patched namespace. |
| 110 | +func (c *FakeNamespaces) Patch(name string, pt api.PatchType, data []byte, subresources ...string) (result *api.Namespace, err error) { |
| 111 | + obj, err := c.Fake. |
| 112 | + Invokes(core.NewRootPatchSubresourceAction(namespacesResource, name, data, subresources...), &api.Namespace{}) |
| 113 | + if obj == nil { |
| 114 | + return nil, err |
| 115 | + } |
| 116 | + return obj.(*api.Namespace), err |
| 117 | +} |
0 commit comments