mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-12 12:48:51 +00:00
Namespace.Spec.Finalizer support
This commit is contained in:
@@ -29,7 +29,7 @@ type FakeNamespaces struct {
|
||||
Fake *Fake
|
||||
}
|
||||
|
||||
func (c *FakeNamespaces) List(selector labels.Selector) (*api.NamespaceList, error) {
|
||||
func (c *FakeNamespaces) List(labels labels.Selector, field fields.Selector) (*api.NamespaceList, error) {
|
||||
c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "list-namespaces"})
|
||||
return api.Scheme.CopyOrDie(&c.Fake.NamespacesList).(*api.NamespaceList), nil
|
||||
}
|
||||
@@ -58,3 +58,13 @@ func (c *FakeNamespaces) Watch(label labels.Selector, field fields.Selector, res
|
||||
c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "watch-namespaces", Value: resourceVersion})
|
||||
return c.Fake.Watch, nil
|
||||
}
|
||||
|
||||
func (c *FakeNamespaces) Finalize(namespace *api.Namespace) (*api.Namespace, error) {
|
||||
c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "finalize-namespace", Value: namespace.Name})
|
||||
return &api.Namespace{}, nil
|
||||
}
|
||||
|
||||
func (c *FakeNamespaces) Status(namespace *api.Namespace) (*api.Namespace, error) {
|
||||
c.Fake.Actions = append(c.Fake.Actions, FakeAction{Action: "status-namespace", Value: namespace.Name})
|
||||
return &api.Namespace{}, nil
|
||||
}
|
||||
|
@@ -33,10 +33,12 @@ type NamespacesInterface interface {
|
||||
type NamespaceInterface interface {
|
||||
Create(item *api.Namespace) (*api.Namespace, error)
|
||||
Get(name string) (result *api.Namespace, err error)
|
||||
List(selector labels.Selector) (*api.NamespaceList, error)
|
||||
List(label labels.Selector, field fields.Selector) (*api.NamespaceList, error)
|
||||
Delete(name string) error
|
||||
Update(item *api.Namespace) (*api.Namespace, error)
|
||||
Watch(label labels.Selector, field fields.Selector, resourceVersion string) (watch.Interface, error)
|
||||
Finalize(item *api.Namespace) (*api.Namespace, error)
|
||||
Status(item *api.Namespace) (*api.Namespace, error)
|
||||
}
|
||||
|
||||
// namespaces implements NamespacesInterface
|
||||
@@ -57,9 +59,13 @@ func (c *namespaces) Create(namespace *api.Namespace) (*api.Namespace, error) {
|
||||
}
|
||||
|
||||
// List lists all the namespaces in the cluster.
|
||||
func (c *namespaces) List(selector labels.Selector) (*api.NamespaceList, error) {
|
||||
func (c *namespaces) List(label labels.Selector, field fields.Selector) (*api.NamespaceList, error) {
|
||||
result := &api.NamespaceList{}
|
||||
err := c.r.Get().Resource("namespaces").LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), selector).Do().Into(result)
|
||||
err := c.r.Get().
|
||||
Resource("namespaces").
|
||||
LabelsSelectorParam(api.LabelSelectorQueryParam(c.r.APIVersion()), label).
|
||||
FieldsSelectorParam(api.FieldSelectorQueryParam(c.r.APIVersion()), field).
|
||||
Do().Into(result)
|
||||
return result, err
|
||||
}
|
||||
|
||||
@@ -74,6 +80,28 @@ func (c *namespaces) Update(namespace *api.Namespace) (result *api.Namespace, er
|
||||
return
|
||||
}
|
||||
|
||||
// Finalize takes the representation of a namespace to update. Returns the server's representation of the namespace, and an error, if it occurs.
|
||||
func (c *namespaces) Finalize(namespace *api.Namespace) (result *api.Namespace, err error) {
|
||||
result = &api.Namespace{}
|
||||
if len(namespace.ResourceVersion) == 0 {
|
||||
err = fmt.Errorf("invalid update object, missing resource version: %v", namespace)
|
||||
return
|
||||
}
|
||||
err = c.r.Put().Resource("namespaces").Name(namespace.Name).SubResource("finalize").Body(namespace).Do().Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// Status takes the representation of a namespace to update. Returns the server's representation of the namespace, and an error, if it occurs.
|
||||
func (c *namespaces) Status(namespace *api.Namespace) (result *api.Namespace, err error) {
|
||||
result = &api.Namespace{}
|
||||
if len(namespace.ResourceVersion) == 0 {
|
||||
err = fmt.Errorf("invalid update object, missing resource version: %v", namespace)
|
||||
return
|
||||
}
|
||||
err = c.r.Put().Resource("namespaces").Name(namespace.Name).SubResource("status").Body(namespace).Do().Into(result)
|
||||
return
|
||||
}
|
||||
|
||||
// Get gets an existing namespace
|
||||
func (c *namespaces) Get(name string) (*api.Namespace, error) {
|
||||
if len(name) == 0 {
|
||||
|
@@ -91,7 +91,7 @@ func TestNamespaceList(t *testing.T) {
|
||||
},
|
||||
Response: Response{StatusCode: 200, Body: namespaceList},
|
||||
}
|
||||
response, err := c.Setup().Namespaces().List(labels.Everything())
|
||||
response, err := c.Setup().Namespaces().List(labels.Everything(), fields.Everything())
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("%#v should be nil.", err)
|
||||
@@ -117,6 +117,9 @@ func TestNamespaceUpdate(t *testing.T) {
|
||||
"name": "baz",
|
||||
},
|
||||
},
|
||||
Spec: api.NamespaceSpec{
|
||||
Finalizers: []api.FinalizerName{api.FinalizerKubernetes},
|
||||
},
|
||||
}
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "PUT", Path: "/namespaces/foo"},
|
||||
@@ -126,6 +129,28 @@ func TestNamespaceUpdate(t *testing.T) {
|
||||
c.Validate(t, receivedNamespace, err)
|
||||
}
|
||||
|
||||
func TestNamespaceFinalize(t *testing.T) {
|
||||
requestNamespace := &api.Namespace{
|
||||
ObjectMeta: api.ObjectMeta{
|
||||
Name: "foo",
|
||||
ResourceVersion: "1",
|
||||
Labels: map[string]string{
|
||||
"foo": "bar",
|
||||
"name": "baz",
|
||||
},
|
||||
},
|
||||
Spec: api.NamespaceSpec{
|
||||
Finalizers: []api.FinalizerName{api.FinalizerKubernetes},
|
||||
},
|
||||
}
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "PUT", Path: "/namespaces/foo/finalize"},
|
||||
Response: Response{StatusCode: 200, Body: requestNamespace},
|
||||
}
|
||||
receivedNamespace, err := c.Setup().Namespaces().Finalize(requestNamespace)
|
||||
c.Validate(t, receivedNamespace, err)
|
||||
}
|
||||
|
||||
func TestNamespaceDelete(t *testing.T) {
|
||||
c := &testClient{
|
||||
Request: testRequest{Method: "DELETE", Path: "/namespaces/foo"},
|
||||
|
Reference in New Issue
Block a user