node

package
v0.0.0-...-ed4b1df Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Well known taints for master nodes, see
	// https://kubernetes.io/docs/reference/labels-annotations-taints/.
	// Tainting such nodes might result in a broken cluster should one of the
	// control plane components fail during the test runs.
	MasterTaintKeys = map[string]struct{}{
		"node-role.kubernetes.io/master":        {},
		"node-role.kubernetes.io/control-plane": {},
	}
)

Functions

This section is empty.

Types

type Client

type Client struct {
	Nodes            corev1client.NodeInterface
	MasterNodeTaints map[string]struct{}
	Log              logr.Logger
}

func NewClientFromKubecfg

func NewClientFromKubecfg(kubecfg string) (Client, error)

func (Client) Get

func (c Client) Get(ctx context.Context, nodeName string) (v1.Node, error)

Get returns the node named `nodeName`. In case of error, it returns the error and an empty v1.Node struct.

func (Client) GetLabels

func (c Client) GetLabels(ctx context.Context, nodeName string) (map[string]string, error)

func (Client) Label

func (c Client) Label(ctx context.Context, n v1.Node, labels map[string]string) error

func (Client) ListAll

func (c Client) ListAll(ctx context.Context) ([]v1.Node, error)

ListAll returns a slice with all the nodes in the K8s cluster. ListAll returns an empty slice and an error if a failure occurs.

func (Client) ListWorkers

func (c Client) ListWorkers(ctx context.Context) ([]v1.Node, error)

ListWorkers returns a slice with all the worker nodes in the K8s cluster. Worker nodes are nodes that DO NOT have the taints with the keys contained in `c.MasterNodeTaints`. ListWorkers returns an empty slice and an error if a failure occurs.

func (Client) TaintWorkers

func (c Client) TaintWorkers(ctx context.Context, t []v1.Taint) error

TaintWorkers adds the taints `t` to all the worker nodes in the K8s cluster. Worker nodes are nodes that DO NOT have the taints with the keys contained in `c.MasterNodeTaints`. TaintWorkers is idempotent:

  • if a worker already has a subset of the taints in `t`, only the missing ones are added.
  • if a worker already has all the taints in `t`, it's left unchanged.

If a worker has one (or more) taint(s) with the same key as one of the taints in `t` but different value or effect, TaintWorkers panics. TaintWorkers returns an error if a failure occurs.

func (Client) UnlabelAll

func (c Client) UnlabelAll(ctx context.Context, labelsKeys []string) error

UnlabelAll removes the labels with the keys in `labelsKeys` from all the nodes (worker and master ones) in the K8s cluster, regardless of the labels values. UnlabelAll is idempotent and safe to retry:

  • if a node has only a subset of the labels in `labelsKeys`, only that subset is removed.
  • if a node doesn't have any of the labels in `labelsKeys`, it's left unchanged.

UnlabelAll returns an error if a failure occurs.

func (Client) UntaintAll

func (c Client) UntaintAll(ctx context.Context, t []v1.Taint) error

UntaintAll removes the taints `t` from all the nodes (worker and master ones) in the K8s cluster. UntaintAll is idempotent and safe to retry:

  • if a node has only a subset of the taints in `t`, only that subset is removed.
  • if a node doesn't have any of the taints in `t`, it's left unchanged.

If a node has one (or more) taint(s) with the same key as one of the taints in `t` but different value or effect, UntaintAll panics. UntaintAll returns an error if a failure occurs.

type ErrNodeGet

type ErrNodeGet struct {
	NodeName string
	Err      error
}

ErrNodeGet is the error type returned when a node GET call fails. Unless you really really really really know what you're doing, avoid calling errors.Is on variables of type `ErrNodeGet`, because it behaves in crazy ways: errors.Is(e1, e2) can panic if both e1 and e2 are variables of type ErrNodeGet, in the case where e1.Err and e2.Err are of two incomparable concrete types. More details here: https://github.com/golang/go/issues/54709

func (ErrNodeGet) Error

func (e ErrNodeGet) Error() string

func (ErrNodeGet) Unwrap

func (e ErrNodeGet) Unwrap() error

type ErrNodeUpdate

type ErrNodeUpdate struct {
	Node v1.Node
	Err  error
}

ErrNodeUpdate is the error type returned when a node UPDATE call fails. Unless you really really really really know what you're doing, avoid calling errors.Is on variables of type `ErrNodeUpdate`, because it behaves in crazy ways. First, ErrNodeUpdate is not reflexive with respect to errors.Is. This means that given a variable `e` of type ErrNodeUpdate errors.Is(e, e) evaluates to `false`. Second, errors.Is(e1, e2) can panic if both e1 and e2 are variables of type ErrNodeUpdate, in the case where e1.Err and e2.Err are of two incomparable concrete types. More details here: https://github.com/golang/go/issues/54709

func (ErrNodeUpdate) Error

func (e ErrNodeUpdate) Error() string

func (ErrNodeUpdate) Unwrap

func (e ErrNodeUpdate) Unwrap() error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL