scale

package
v1.7.14 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2021 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDecommissioningStalled indicates that the decommissioning process of
	// a node has stalled due to the KV allocator being unable to relocate ranges
	// to another node. This could happen if no nodes have available disk space
	// or if ZONE CONFIGURATION constraints can not be satisfied.
	ErrDecommissioningStalled = errors.New("decommissioning has stalled")
)

Functions

func IsStatefulSetReadyToServe

func IsStatefulSetReadyToServe(
	ctx context.Context,
	clientset kubernetes.Interface,
	namespace, name string,
	numReplicas int32,
) error

IsStatefulSetReadyToServe func

func StatefulSetIsRunning

func StatefulSetIsRunning(ctx context.Context, clientset kubernetes.Interface, namespace string, name string) error

StatefulSetIsRunning checks if the expected number of pods for a statefulset are running but not necessarily ready nor healthy

func WaitUntilStatefulSetIsReadyToServe

func WaitUntilStatefulSetIsReadyToServe(
	ctx context.Context,
	clientset kubernetes.Interface,
	namespace, name string,
	numReplicas int32) error

WaitUntilStatefulSetIsReadyToServe func

func WaitUntilStatefulSetIsRunning

func WaitUntilStatefulSetIsRunning(ctx context.Context, clientset kubernetes.Interface, namespace string, name string) error

WaitUntilStatefulSetIsRunning waits until the given statefulset has all pods scheduled and running but not necessarily healthy nor ready

Types

type ClusterScaler

type ClusterScaler interface {
	Replicas(context.Context) (uint, error)
	SetReplicas(context.Context, uint) error
	WaitUntilRunning(context.Context) error
	WaitUntilHealthy(context.Context, uint) error
}

ClusterScaler interface

type CockroachExecutor

type CockroachExecutor struct {
	Namespace   string
	StatefulSet string
	Container   string
	Config      *rest.Config
	ClientSet   kubernetes.Interface
	TTY         bool
}

CockroachExecutor struct

func (CockroachExecutor) Exec

func (e CockroachExecutor) Exec(ctx context.Context, podIdx uint, cmd []string) (string, string, error)

Exec func

type CockroachNodeDrainer

type CockroachNodeDrainer struct {
	Secure   bool
	Logger   logr.Logger
	Executor *CockroachExecutor
	// RangeRelocationTimeout is the maximum amount of time to wait
	// for a range to move. If no ranges have moved from the draining
	// node in the given durration Decommission will fail with
	// ErrDecommissioningStalled
	RangeRelocationTimeout time.Duration
}

CockroachNodeDrainer does decommissioning of nodes in the CockroachDB cluster

func (*CockroachNodeDrainer) Decommission

func (d *CockroachNodeDrainer) Decommission(ctx context.Context, replica uint, gRPCPort int32) error

Decommission commands the node to start training process and watches for it to complete or fail after timeout

type CockroachStatefulSet

type CockroachStatefulSet struct {
	Name      string
	Namespace string
	ClientSet kubernetes.Interface
}

CockroachStatefulSet represents the CRDB statefulset running in a kubernetes cluster

func (*CockroachStatefulSet) Replicas

func (c *CockroachStatefulSet) Replicas(ctx context.Context) (uint, error)

Replicas returns the number of desired replicas for CRDB's statefulset

func (*CockroachStatefulSet) SetReplicas

func (c *CockroachStatefulSet) SetReplicas(ctx context.Context, scale uint) error

SetReplicas sets the desired replicas for CRDB's statefulset without waiting for new pods to be created or to become healthy.

func (*CockroachStatefulSet) WaitUntilHealthy

func (c *CockroachStatefulSet) WaitUntilHealthy(ctx context.Context, scale uint) error

WaitUntilHealthy blocks until the target stateful set has exactly `scale` healthy replicas.

func (*CockroachStatefulSet) WaitUntilRunning

func (c *CockroachStatefulSet) WaitUntilRunning(ctx context.Context) error

WaitUntilRunning blocks until the target statefulset has the expected number of pods running but not necessarily ready

type Drainer

type Drainer interface {
	Decommission(ctx context.Context, replica uint, gRPCPort int32) error
}

Drainer interface

func NewCockroachNodeDrainer

func NewCockroachNodeDrainer(logger logr.Logger, namespace, ssname string, config *rest.Config, clientset kubernetes.Interface, secure bool, rangeRelocation time.Duration) Drainer

NewCockroachNodeDrainer ctor

type Executor

type Executor struct {
	Namespace string
	Config    *rest.Config
}

Executor struct

func (Executor) Exec

func (e Executor) Exec(ctx context.Context, o ExecutorOptions) error

Exec func

type ExecutorOptions

type ExecutorOptions struct {
	Pod       string
	Container string
	Cmd       []string
	Stdin     io.Reader
	Stdout    io.Writer
	Stderr    io.Writer
	TTY       bool
}

ExecutorOptions struct

type PVCPruner

type PVCPruner interface {
	Prune(ctx context.Context) error
}

PVCPruner interface

type PersistentVolumePruner

type PersistentVolumePruner struct {
	Namespace   string
	StatefulSet string
	ClientSet   kubernetes.Interface
	Logger      logr.Logger
}

PersistentVolumePruner provides a .Prune method to remove unused statefulset PVC and their underlying PVs. The underlying PVs SHOULD have their reclaim policy set to delete.

func (*PersistentVolumePruner) Prune

Prune locates and removes all PVCs that belong to a given statefulset but are not in use. Use is determined by the .Spec.Replicas field on the statefulset and the PVCs' ordinal. Prune will return an error if unexpected PVCs are encountered (conflicting labels) or the referenced statefulset's .Spec.Replicas field changes will this operation is running. The underlying PVs' reclaim policy should be set to delete, other options may result in leaking volumes which cost us money.

type Scaler

type Scaler struct {
	Logger    logr.Logger
	CRDB      ClusterScaler
	Drainer   Drainer
	PVCPruner PVCPruner
}

Scaler interface

func (*Scaler) EnsureScale

func (s *Scaler) EnsureScale(ctx context.Context, scale uint, gRPCPort int32, prunePVC bool) error

EnsureScale gracefully adds or removes CRDB replicas from a given stateful until it matches the given number. Removed nodes are drained of all replicas before being removed from the CRDB cluster and their matching PVCs and PVs will be removed as well. In some cases, it may not be possible to full drain a node. In such cases a ErrDecommissioningStalled will be returned and the node will be left in a decommissioning state.

Jump to

Keyboard shortcuts

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