Documentation
¶
Overview ¶
Package k8s provides a client for interacting with Kubernetes. It provides methods for listing, cordoning, draining, and deleting nodes, as well as setting and getting node annotations and labels.
Index ¶
- type Client
- func (c *Client) CordonNode(ctx context.Context, nodeName string) error
- func (c *Client) DeleteNode(ctx context.Context, nodeName string) error
- func (c *Client) DeletePod(ctx context.Context, podName, namespace string) error
- func (c *Client) DrainNode(ctx context.Context, nodeName string) error
- func (c *Client) GetNodeAnnotation(ctx context.Context, nodeName, key string) (string, error)
- func (c *Client) GetNodeLabel(ctx context.Context, nodeName, key string) (string, error)
- func (c *Client) GetNodeZone(ctx context.Context, nodeName string) (string, error)
- func (c *Client) GetNodes(ctx context.Context) ([]string, error)
- func (c *Client) HasNodeAnnotation(ctx context.Context, nodeName, key string) (bool, error)
- func (c *Client) HasNodeLabel(ctx context.Context, nodeName, key string) (bool, error)
- func (c *Client) SetNodeAnnotation(ctx context.Context, nodeName, key, value string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a Kubernetes client wrapper.
func NewClient ¶
NewClient creates a new Kubernetes client using the provided rest.Config and returns a Client. If no config is provided, it will try to use in-cluster config, and if that fails, it will fallback to a kubeconfig file. At the moment, it does not apply client-side rate limiting.
func (*Client) CordonNode ¶
CordonNode cordon the node with the provided name. Since no out of the box method is provided by the client-go library, we need to patch the node object to set the spec.unschedulable field to true.
func (*Client) DeleteNode ¶
DeleteNode deletes the node with the provided name.
func (*Client) DrainNode ¶
DrainNode drains the node with the provided name. It evicts all the pods running on the node, except for the ones in the kube-system namespace. It uses the Eviction API to evict the pods.
func (*Client) GetNodeAnnotation ¶
GetNodeAnnotation returns the value of the annotation with the provided key on the node with the provided name.
func (*Client) GetNodeLabel ¶
GetNodeLabel returns the value of the label with the provided key on the node with the provided name.
func (*Client) GetNodeZone ¶
GetNodeZone returns the zone of the node with the provided name. It first tries to get the zone from the "topology.kubernetes.io/zone" label, and if that fails, it tries to get it from the "failure-domain.beta.kubernetes.io/zone" label.
func (*Client) GetNodes ¶
GetNodes returns a list of node names in the Kubernetes cluster where the client points to.
func (*Client) HasNodeAnnotation ¶
HasNodeAnnotation checks if the node with the provided name has the annotation with the provided key.
func (*Client) HasNodeLabel ¶
HasNodeLabel checks if the node with the provided name has the label with the provided key.