cluster

package
v0.0.0-...-e7c744b Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2023 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NodePoolNameLabelKey    = "nodepool.banzaicloud.io/name"
	NodePoolVersionLabelKey = "nodepool.banzaicloud.io/version"
)

Common node pool label constants

View Source
const (
	Creating = "CREATING"
	Running  = "RUNNING"
	Updating = "UPDATING"
	Deleting = "DELETING"
	Warning  = "WARNING"
	Error    = "ERROR"

	CreatingMessage = "Cluster creation is in progress"
	RunningMessage  = "Cluster is running"
	UpdatingMessage = "Update is in progress"
	DeletingMessage = "Termination is in progress"
)

Cluster status constants

Variables

This section is empty.

Functions

func IsNotFoundError

func IsNotFoundError(err error) bool

IsNotFoundError returns true if the error implements the NotFound behavior and it returns true.

Types

type ClientFactory

type ClientFactory struct {
	// contains filtered or unexported fields
}

ClientFactory returns a Kubernetes client.

func NewClientFactory

func NewClientFactory(clusters Store, kubeClientFactory KubeClientFactory) ClientFactory

NewClientFactory returns a new ClientFactory.

func (ClientFactory) FromClusterID

func (f ClientFactory) FromClusterID(ctx context.Context, clusterID uint) (kubernetes.Interface, error)

FromClusterID creates a Kubernetes client for a cluster from a cluster ID.

func (ClientFactory) FromSecret

func (f ClientFactory) FromSecret(ctx context.Context, secretID string) (kubernetes.Interface, error)

FromSecret creates a Kubernetes client for a cluster from a secret.

type Cluster

type Cluster struct {
	ID   uint
	UID  string
	Name string

	OrganizationID uint

	Status        string
	StatusMessage string

	Cloud        string
	Distribution string
	Location     string

	SecretID       brn.ResourceName
	ConfigSecretID brn.ResourceName
	Tags           map[string]string
}

Cluster represents a generic, provider agnostic Kubernetes cluster structure.

type ClusterDeleteNotPermittedError

type ClusterDeleteNotPermittedError struct {
	OrganizationID uint
	ClusterID      uint
	ClusterName    string
	Msg            string
}

ClusterDeleteNotPermittedError is returned if a cluster cannot be deleted.

func (ClusterDeleteNotPermittedError) Details

func (e ClusterDeleteNotPermittedError) Details() []interface{}

Details returns error details.

func (ClusterDeleteNotPermittedError) Error

Error implements the error interface.

func (ClusterDeleteNotPermittedError) ServiceError

func (ClusterDeleteNotPermittedError) ServiceError() bool

ServiceError tells the consumer whether this error is caused by invalid input supplied by the client. Client errors are usually returned to the consumer without retrying the operation.

func (ClusterDeleteNotPermittedError) Validation

func (e ClusterDeleteNotPermittedError) Validation() bool

type ClusterGroupManager

type ClusterGroupManager interface {
	ValidateClusterRemoval(ctx context.Context, clusterID uint) error
}

+testify:mock:testOnly=true

type ClusterUpdate

type ClusterUpdate struct {
	Version string
}

ClusterUpdate represents cluster update parameters.

type DeleteClusterOptions

type DeleteClusterOptions struct {
	Force bool
}

DeleteClusterOptions represents cluster deletion options.

type Deleter

type Deleter interface {
	// DeleteCluster deletes the specified cluster.
	DeleteCluster(ctx context.Context, clusterID uint, options DeleteClusterOptions) error
}

Deleter can be used to delete a cluster.

type DynamicClientFactory

type DynamicClientFactory struct {
	// contains filtered or unexported fields
}

DynamicClientFactory returns a Kubernetes client.

func NewDynamicClientFactory

func NewDynamicClientFactory(clusters Store, dynamicKubeClientFactory DynamicKubeClientFactory) DynamicClientFactory

NewDynamicClientFactory returns a new DynamicClientFactory.

func (DynamicClientFactory) FromClusterID

func (f DynamicClientFactory) FromClusterID(ctx context.Context, clusterID uint) (dynamic.Interface, error)

FromClusterID creates a dynamic Kubernetes client for a cluster from a cluster ID.

func (DynamicClientFactory) FromSecret

func (f DynamicClientFactory) FromSecret(ctx context.Context, secretID string) (dynamic.Interface, error)

FromSecret creates a dynamic Kubernetes client for a cluster from a secret.

type DynamicKubeClientFactory

type DynamicKubeClientFactory interface {
	// FromSecret creates a dynamic Kubernetes client for a cluster from a secret.
	FromSecret(ctx context.Context, secretID string) (dynamic.Interface, error)
}

DynamicKubeClientFactory returns a dynamic Kubernetes client.

type Identifier

type Identifier struct {
	OrganizationID uint
	ClusterID      uint
	ClusterName    string
}

type KubeClientFactory

type KubeClientFactory interface {
	// FromSecret creates a Kubernetes client for a cluster from a secret.
	FromSecret(ctx context.Context, secretID string) (kubernetes.Interface, error)
}

KubeClientFactory returns a Kubernetes client.

type LabelValidator

type LabelValidator interface {
	// ValidateKey validates a label key.
	ValidateKey(key string) error

	// ValidateValue validates a label value.
	ValidateValue(value string) error
}

LabelValidator validates Kubernetes object labels.

type Manager

type Manager interface {
	Deleter
}

Manager provides lower level cluster operations for Service.

type MockDynamicKubeClientFactory

type MockDynamicKubeClientFactory struct {
	mock.Mock
}

MockDynamicKubeClientFactory is an autogenerated mock for the DynamicKubeClientFactory type.

func (*MockDynamicKubeClientFactory) FromSecret

func (_m *MockDynamicKubeClientFactory) FromSecret(ctx context.Context, secretID string) (_result_0 dynamic.Interface, _result_1 error)

FromSecret provides a mock function.

type MockService

type MockService struct {
	mock.Mock
}

MockService is an autogenerated mock for the Service type.

func (*MockService) CreateNodePools

func (_m *MockService) CreateNodePools(ctx context.Context, clusterID uint, rawNodePools map[string]NewRawNodePool) (_result_0 error)

CreateNodePools provides a mock function.

func (*MockService) DeleteCluster

func (_m *MockService) DeleteCluster(ctx context.Context, clusterIdentifier Identifier, options DeleteClusterOptions) (deleted bool, err error)

DeleteCluster provides a mock function.

func (*MockService) DeleteNodePool

func (_m *MockService) DeleteNodePool(ctx context.Context, clusterID uint, name string) (deleted bool, err error)

DeleteNodePool provides a mock function.

func (*MockService) ListNodePools

func (_m *MockService) ListNodePools(ctx context.Context, clusterID uint) (nodePoolList RawNodePoolList, err error)

ListNodePools provides a mock function.

func (*MockService) UpdateCluster

func (_m *MockService) UpdateCluster(ctx context.Context, clusterIdentifier Identifier, clusterUpdate ClusterUpdate) (err error)

UpdateCluster provides a mock function.

func (*MockService) UpdateNodePool

func (_m *MockService) UpdateNodePool(ctx context.Context, clusterID uint, nodePoolName string, rawNodePoolUpdate RawNodePoolUpdate) (processID string, err error)

UpdateNodePool provides a mock function.

type MockStore

type MockStore struct {
	mock.Mock
}

MockStore is an autogenerated mock for the Store type.

func (*MockStore) GetCluster

func (_m *MockStore) GetCluster(ctx context.Context, id uint) (_result_0 Cluster, _result_1 error)

GetCluster provides a mock function.

func (*MockStore) GetClusterByName

func (_m *MockStore) GetClusterByName(ctx context.Context, orgID uint, clusterName string) (_result_0 Cluster, _result_1 error)

GetClusterByName provides a mock function.

func (*MockStore) SetStatus

func (_m *MockStore) SetStatus(ctx context.Context, id uint, status string, statusMessage string) (_result_0 error)

SetStatus provides a mock function.

type MockdynamicInterface

type MockdynamicInterface struct {
	mock.Mock
}

MockdynamicInterface is an autogenerated mock for the dynamicInterface type.

func (*MockdynamicInterface) Resource

Resource provides a mock function.

type MockdynamicNamespaceableResourceInterface

type MockdynamicNamespaceableResourceInterface struct {
	mock.Mock
}

MockdynamicNamespaceableResourceInterface is an autogenerated mock for the dynamicNamespaceableResourceInterface type.

func (*MockdynamicNamespaceableResourceInterface) Create

func (_m *MockdynamicNamespaceableResourceInterface) Create(ctx context.Context, obj *unstructured.Unstructured, options v1.CreateOptions, subresources ...string) (_result_0 *unstructured.Unstructured, _result_1 error)

Create provides a mock function.

func (*MockdynamicNamespaceableResourceInterface) Delete

func (_m *MockdynamicNamespaceableResourceInterface) Delete(ctx context.Context, name string, options v1.DeleteOptions, subresources ...string) (_result_0 error)

Delete provides a mock function.

func (*MockdynamicNamespaceableResourceInterface) DeleteCollection

func (_m *MockdynamicNamespaceableResourceInterface) DeleteCollection(ctx context.Context, options v1.DeleteOptions, listOptions v1.ListOptions) (_result_0 error)

DeleteCollection provides a mock function.

func (*MockdynamicNamespaceableResourceInterface) Get

func (_m *MockdynamicNamespaceableResourceInterface) Get(ctx context.Context, name string, options v1.GetOptions, subresources ...string) (_result_0 *unstructured.Unstructured, _result_1 error)

Get provides a mock function.

func (*MockdynamicNamespaceableResourceInterface) List

List provides a mock function.

func (*MockdynamicNamespaceableResourceInterface) Namespace

func (_m *MockdynamicNamespaceableResourceInterface) Namespace(_parameter_0 string) (_result_0 dynamic.ResourceInterface)

Namespace provides a mock function.

func (*MockdynamicNamespaceableResourceInterface) Patch

func (_m *MockdynamicNamespaceableResourceInterface) Patch(ctx context.Context, name string, pt types.PatchType, data []uint8, options v1.PatchOptions, subresources ...string) (_result_0 *unstructured.Unstructured, _result_1 error)

Patch provides a mock function.

func (*MockdynamicNamespaceableResourceInterface) Update

func (_m *MockdynamicNamespaceableResourceInterface) Update(ctx context.Context, obj *unstructured.Unstructured, options v1.UpdateOptions, subresources ...string) (_result_0 *unstructured.Unstructured, _result_1 error)

Update provides a mock function.

func (*MockdynamicNamespaceableResourceInterface) UpdateStatus

UpdateStatus provides a mock function.

func (*MockdynamicNamespaceableResourceInterface) Watch

func (_m *MockdynamicNamespaceableResourceInterface) Watch(ctx context.Context, opts v1.ListOptions) (_result_0 watch.Interface, _result_1 error)

Watch provides a mock function.

type NewRawNodePool

type NewRawNodePool map[string]interface{}

NewRawNodePool is an unstructured, distribution specific descriptor for a new node pool.

func (NewRawNodePool) GetInstanceType

func (n NewRawNodePool) GetInstanceType() string

GetInstanceType returns the node pool instance type.

func (NewRawNodePool) GetLabels

func (n NewRawNodePool) GetLabels() map[string]string

GetLabels returns labels that are/should be applied to every node in the pool.

func (NewRawNodePool) GetName

func (n NewRawNodePool) GetName() string

GetName returns the node pool name.

func (NewRawNodePool) IsOnDemand

func (n NewRawNodePool) IsOnDemand() bool

IsOnDemand determines whether the machines in the node pool are on demand or spot/preemtible instances.

type NodePool

type NodePool interface {
	// GetName returns the node pool name.
	GetName() string

	// GetInstanceType returns the node pool instance type.
	GetInstanceType() string

	// IsOnDemand determines whether the machines in the node pool are on demand or spot/preemtible instances.
	IsOnDemand() bool

	// GetLabels returns labels that are/should be applied to every node in the pool.
	GetLabels() map[string]string
}

NodePool is a common interface for all distribution node pools.

type NodePoolAlreadyExistsError

type NodePoolAlreadyExistsError struct {
	ClusterID uint
	NodePool  string
}

NodePoolAlreadyExistsError is returned when a node pool already exists.

func (NodePoolAlreadyExistsError) Conflict

func (NodePoolAlreadyExistsError) Conflict() bool

Conflict tells a client that this error is related to a conflicting request. Can be used to translate the error to status codes for example.

func (NodePoolAlreadyExistsError) Details

func (e NodePoolAlreadyExistsError) Details() []interface{}

Details returns error details.

func (NodePoolAlreadyExistsError) Error

Error implements the error interface.

func (NodePoolAlreadyExistsError) ServiceError

func (NodePoolAlreadyExistsError) ServiceError() bool

ServiceError tells the consumer whether this error is caused by invalid input supplied by the client. Client errors are usually returned to the consumer without retrying the operation.

type NodePoolLabelSource

type NodePoolLabelSource interface {
	// GetLabels returns a set of labels that should be applied to every node in the pool.
	GetLabels(ctx context.Context, cluster Cluster, nodePool NodePool) (map[string]string, error)
}

NodePoolLabelSource returns a set of labels that should be applied to every node in the pool.

func NewCommonNodePoolLabelSource

func NewCommonNodePoolLabelSource() NodePoolLabelSource

NewCommonNodePoolLabelSource returns a new NodePoolLabelSource that returns common labels for a node pool.

func NewFilterValidNodePoolLabelSource

func NewFilterValidNodePoolLabelSource(labelValidator LabelValidator) NodePoolLabelSource

NewFilterValidNodePoolLabelSource returns a new NodePoolLabelSource that validates existing labels and filters invalid ones.

type NodePoolLabelSources

type NodePoolLabelSources []NodePoolLabelSource

NodePoolLabelSources combines different node pool label sources into one. In case of conflicting labels, the last one is applied (in the order of sources).

func (NodePoolLabelSources) GetLabels

func (s NodePoolLabelSources) GetLabels(ctx context.Context, cluster Cluster, nodePool NodePool) (map[string]string, error)

GetLabels returns a set of labels that should be applied to every node in the pool.

type NodePoolNotFoundError

type NodePoolNotFoundError struct {
	ClusterID uint
	NodePool  string
}

NodePoolNotFoundError is returned when a node pool cannot be found.

func (NodePoolNotFoundError) Details

func (e NodePoolNotFoundError) Details() []interface{}

Details returns error details.

func (NodePoolNotFoundError) Error

func (NodePoolNotFoundError) Error() string

Error implements the error interface.

func (NodePoolNotFoundError) NotFound

func (NodePoolNotFoundError) NotFound() bool

NotFound tells a client that this error is related to a resource being not found. Can be used to translate the error to status codes for example.

func (NodePoolNotFoundError) ServiceError

func (NodePoolNotFoundError) ServiceError() bool

ServiceError tells the consumer whether this error is caused by invalid input supplied by the client. Client errors are usually returned to the consumer without retrying the operation.

type NodePoolProcessor

type NodePoolProcessor interface {
	// ProcessNew processes a new node pool descriptor.
	ProcessNew(ctx context.Context, cluster Cluster, rawNodePool NewRawNodePool) (NewRawNodePool, error)
}

NodePoolProcessor processes a node pool descriptor.

func NewCommonNodePoolProcessor

func NewCommonNodePoolProcessor(labelSource NodePoolLabelSource) NodePoolProcessor

NewCommonNodePoolProcessor returns a new NodePoolProcessor that processes common node pool fields.

func NewDistributionNodePoolProcessor

func NewDistributionNodePoolProcessor(processors map[string]NodePoolProcessor) NodePoolProcessor

NewDistributionNodePoolProcessor returns a new NodePoolProcessor that allows registering processors for Kubernetes distributions.

type NodePoolProcessors

type NodePoolProcessors []NodePoolProcessor

NodePoolProcessors combines different node pool processors into one.

func (NodePoolProcessors) ProcessNew

func (p NodePoolProcessors) ProcessNew(
	ctx context.Context,
	cluster Cluster,
	rawNodePool NewRawNodePool,
) (NewRawNodePool, error)

ProcessNew processes a new node pool descriptor.

type NodePoolStore

type NodePoolStore interface {
	// NodePoolExists checks if a node pool exists.
	NodePoolExists(ctx context.Context, clusterID uint, name string) (isExisting bool, storedName string, err error)
}

NodePoolStore provides an interface to node pool persistence.

type NodePoolValidator

type NodePoolValidator interface {
	// ValidateNew validates a new node pool descriptor.
	ValidateNew(ctx context.Context, cluster Cluster, rawNodePool NewRawNodePool) error
}

NodePoolValidator validates a node pool descriptor.

func NewCommonNodePoolValidator

func NewCommonNodePoolValidator(labelValidator LabelValidator) NodePoolValidator

NewCommonNodePoolValidator returns a new NodePoolValidator that validates common fields found in all node pool types.

func NewDistributionNodePoolValidator

func NewDistributionNodePoolValidator(validators map[string]NodePoolValidator) NodePoolValidator

NewDistributionNodePoolValidator returns a new NodePoolValidator that allows registering validators for Kubernetes distributions.

type NodePoolValidators

type NodePoolValidators []NodePoolValidator

NodePoolValidators combines different node pool validators into one.

func (NodePoolValidators) ValidateNew

func (v NodePoolValidators) ValidateNew(ctx context.Context, cluster Cluster, rawNodePool NewRawNodePool) error

ValidateNew validates a new node pool descriptor.

type NotFoundError

type NotFoundError struct {
	OrganizationID uint
	ClusterID      uint
	ClusterName    string
}

NotFoundError is returned if a cluster cannot be found.

func (NotFoundError) Details

func (e NotFoundError) Details() []interface{}

Details returns error details.

func (NotFoundError) Error

func (NotFoundError) Error() string

Error implements the error interface.

func (NotFoundError) NotFound

func (NotFoundError) NotFound() bool

NotFound tells a client that this error is related to a resource being not found. Can be used to translate the error to status codes for example.

func (NotFoundError) ServiceError

func (NotFoundError) ServiceError() bool

ServiceError tells the consumer whether this error is caused by invalid input supplied by the client. Client errors are usually returned to the consumer without retrying the operation.

type NotReadyError

type NotReadyError struct {
	OrganizationID uint
	ID             uint
	Name           string
}

NotReadyError is returned when a cluster is not ready for certain actions.

func (NotReadyError) Conflict

func (NotReadyError) Conflict() bool

Conflict tells a client that this error is related to a conflicting request. Can be used to translate the error to status codes for example.

func (NotReadyError) Details

func (e NotReadyError) Details() []interface{}

Details returns error details.

func (NotReadyError) Error

func (NotReadyError) Error() string

Error implements the error interface.

func (NotReadyError) IsBusinessError

func (NotReadyError) IsBusinessError() bool

IsBusinessError tells the transport layer whether this error should be translated into the transport format or an internal error should be returned instead. Deprecated: use ServiceError instead.

func (NotReadyError) ServiceError

func (NotReadyError) ServiceError() bool

ServiceError tells the consumer whether this error is caused by invalid input supplied by the client. Client errors are usually returned to the consumer without retrying the operation.

type NotSupportedDistributionError

type NotSupportedDistributionError struct {
	ID           uint
	Cloud        string
	Distribution string

	Message string
}

NotSupportedDistributionError is returned if an API does not support a certain distribution.

func (NotSupportedDistributionError) BadRequest

func (NotSupportedDistributionError) BadRequest() bool

BadRequest tells a client that this error is related to an invalid request. Can be used to translate the error to status codes for example.

func (NotSupportedDistributionError) Details

func (e NotSupportedDistributionError) Details() []interface{}

Details returns error details.

func (NotSupportedDistributionError) Error

Error implements the error interface.

func (NotSupportedDistributionError) IsBusinessError

func (NotSupportedDistributionError) IsBusinessError() bool

IsBusinessError tells the transport layer whether this error should be translated into the transport format or an internal error should be returned instead. Deprecated: use ServiceError instead.

func (NotSupportedDistributionError) ServiceError

func (NotSupportedDistributionError) ServiceError() bool

ServiceError tells the consumer whether this error is caused by invalid input supplied by the client. Client errors are usually returned to the consumer without retrying the operation.

type RawNodePoolList

type RawNodePoolList []interface{}

RawNodePoolList is an unstructured, distribution specific descriptor for a node pool list.

type RawNodePoolUpdate

type RawNodePoolUpdate map[string]interface{}

RawNodePoolUpdate is an unstructured, distribution specific descriptor for a node pool update.

type Service

type Service interface {
	// UpdateCluster updates the specified cluster.
	UpdateCluster(ctx context.Context, clusterIdentifier Identifier, clusterUpdate ClusterUpdate) (err error)

	// DeleteCluster deletes the specified cluster. It returns true if the cluster is already deleted.
	DeleteCluster(ctx context.Context, clusterIdentifier Identifier, options DeleteClusterOptions) (deleted bool, err error)

	// CreateNodePools creates a new node pool in a cluster.
	CreateNodePools(ctx context.Context, clusterID uint, rawNodePools map[string]NewRawNodePool) error

	// UpdateNodePool updates an existing node pool in a cluster.
	UpdateNodePool(ctx context.Context, clusterID uint, nodePoolName string, rawNodePoolUpdate RawNodePoolUpdate) (processID string, err error)

	// DeleteNodePool deletes a node pool from a cluster.
	DeleteNodePool(ctx context.Context, clusterID uint, name string) (deleted bool, err error)

	// ListNodePools lists node pools from a cluster.
	ListNodePools(ctx context.Context, clusterID uint) (nodePoolList RawNodePoolList, err error)
}

Service provides an interface to clusters.

func NewService

func NewService(
	clusters Store,
	clusterManager Manager,
	clusterGroupManager ClusterGroupManager,
	distributions map[string]Service,
	nodePools NodePoolStore,
	nodePoolValidator NodePoolValidator,
	nodePoolProcessor NodePoolProcessor,
) Service

NewService returns a new Service instance

type Store

type Store interface {
	// GetCluster returns a generic Cluster.
	// Returns an error with the NotFound behavior when the cluster cannot be found.
	GetCluster(ctx context.Context, id uint) (Cluster, error)

	// GetClusterByName returns a generic Cluster.
	// Returns an error with the NotFound behavior when the cluster cannot be found.
	GetClusterByName(ctx context.Context, orgID uint, clusterName string) (Cluster, error)

	// SetStatus sets the cluster status.
	SetStatus(ctx context.Context, id uint, status string, statusMessage string) error
}

Store provides an interface to the generic Cluster model persistence.

type ValidationError

type ValidationError struct {
	// contains filtered or unexported fields
}

ValidationError is returned when a request is semantically invalid.

func NewValidationError

func NewValidationError(message string, violations []string) ValidationError

NewValidationError returns a new ValidationError.

func (ValidationError) Error

func (e ValidationError) Error() string

Error implements the error interface.

func (ValidationError) ServiceError

func (ValidationError) ServiceError() bool

ServiceError tells the consumer whether this error is caused by invalid input supplied by the client. Client errors are usually returned to the consumer without retrying the operation.

func (ValidationError) Validation

func (ValidationError) Validation() bool

Validation tells a client that this error is related to a semantic validation of the request. Can be used to translate the error to status codes for example.

func (ValidationError) Violations

func (e ValidationError) Violations() []string

Violations returns details of the failed validation.

Jump to

Keyboard shortcuts

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