k3s/pkg/client/unversioned/nodes.go

111 lines
3.2 KiB
Go
Raw Normal View History

2014-10-21 21:14:35 +00:00
/*
Copyright 2014 The Kubernetes Authors All rights reserved.
2014-10-21 21:14:35 +00:00
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
2015-08-12 17:35:07 +00:00
package unversioned
2014-10-21 21:14:35 +00:00
2014-12-11 15:13:10 +00:00
import (
"fmt"
2014-12-11 15:13:10 +00:00
2015-08-05 22:03:47 +00:00
"k8s.io/kubernetes/pkg/api"
"k8s.io/kubernetes/pkg/watch"
2014-12-11 15:13:10 +00:00
)
2014-10-21 21:14:35 +00:00
type NodesInterface interface {
Nodes() NodeInterface
2014-10-21 21:14:35 +00:00
}
type NodeInterface interface {
2014-12-11 15:13:10 +00:00
Get(name string) (result *api.Node, err error)
Create(node *api.Node) (*api.Node, error)
List(opts api.ListOptions) (*api.NodeList, error)
2014-12-11 15:13:10 +00:00
Delete(name string) error
Update(*api.Node) (*api.Node, error)
2015-04-08 09:32:47 +00:00
UpdateStatus(*api.Node) (*api.Node, error)
Watch(opts api.ListOptions) (watch.Interface, error)
2014-10-21 21:14:35 +00:00
}
// nodes implements NodesInterface
type nodes struct {
r *Client
2014-10-21 21:14:35 +00:00
}
// newNodes returns a nodes object.
func newNodes(c *Client) *nodes {
return &nodes{c}
}
// resourceName returns node's URL resource name.
func (c *nodes) resourceName() string {
return "nodes"
2014-10-21 21:14:35 +00:00
}
// Create creates a new node.
func (c *nodes) Create(node *api.Node) (*api.Node, error) {
2014-12-08 03:44:27 +00:00
result := &api.Node{}
err := c.r.Post().Resource(c.resourceName()).Body(node).Do().Into(result)
2014-10-21 21:14:35 +00:00
return result, err
}
// List takes a selector, and returns the list of nodes that match that selector in the cluster.
func (c *nodes) List(opts api.ListOptions) (*api.NodeList, error) {
2014-12-08 03:44:27 +00:00
result := &api.NodeList{}
2015-12-02 11:12:57 +00:00
err := c.r.Get().Resource(c.resourceName()).VersionedParams(&opts, api.Scheme).Do().Into(result)
return result, err
2014-10-21 21:14:35 +00:00
}
// Get gets an existing node.
2014-12-11 15:13:10 +00:00
func (c *nodes) Get(name string) (*api.Node, error) {
2014-12-08 03:44:27 +00:00
result := &api.Node{}
err := c.r.Get().Resource(c.resourceName()).Name(name).Do().Into(result)
return result, err
2014-10-21 21:14:35 +00:00
}
// Delete deletes an existing node.
2014-12-11 15:13:10 +00:00
func (c *nodes) Delete(name string) error {
return c.r.Delete().Resource(c.resourceName()).Name(name).Do().Error()
2014-10-21 21:14:35 +00:00
}
// Update updates an existing node.
func (c *nodes) Update(node *api.Node) (*api.Node, error) {
result := &api.Node{}
if len(node.ResourceVersion) == 0 {
err := fmt.Errorf("invalid update object, missing resource version: %v", node)
return nil, err
}
err := c.r.Put().Resource(c.resourceName()).Name(node.Name).Body(node).Do().Into(result)
return result, err
}
2015-04-08 09:32:47 +00:00
func (c *nodes) UpdateStatus(node *api.Node) (*api.Node, error) {
result := &api.Node{}
if len(node.ResourceVersion) == 0 {
err := fmt.Errorf("invalid update object, missing resource version: %v", node)
return nil, err
}
err := c.r.Put().Resource(c.resourceName()).Name(node.Name).SubResource("status").Body(node).Do().Into(result)
return result, err
}
// Watch returns a watch.Interface that watches the requested nodes.
func (c *nodes) Watch(opts api.ListOptions) (watch.Interface, error) {
return c.r.Get().
Prefix("watch").
Namespace(api.NamespaceAll).
Resource(c.resourceName()).
2015-10-16 13:07:14 +00:00
VersionedParams(&opts, api.Scheme).
Watch()
}