cluster

package module
v0.0.0-...-b1c2c33 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: Apache-2.0 Imports: 8 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorInvalidChannel        error = errors.New("invalid channel provided")
	ErrorInvalidCredentials    error = errors.New("invalid credentials provided")
	ErrorInvalidOptions        error = errors.New("invalid options provided")
	ErrorInvalidWorkerPool     error = errors.New("invalid worker pool")
	ErrorCreatingPool          error = errors.New("cannot create worker pool")
	ErrorNoCredentialsProvided error = errors.New("no credentials provided")
	ErrorCannotSubmitTask      error = errors.New("cannot submit task to worker pool")
	ErrorCannotGetClient       error = errors.New("cannot get client")
	ErrorCannotGetRegions      error = errors.New("cannot get regions list")
	ErrorInvalidClusterName    error = errors.New("invalid cluster name provided")
	ErrorInvalidRegionName     error = errors.New("invalid region name provided")
	ErrorClusterNotReady       error = errors.New("cluster is not ready")
)

Functions

This section is empty.

Types

type Cluster

type Cluster struct {
	Name              string
	ID                string
	EndpointAddress   string
	CaCertificateData string
	Platform          Platform
	Location          string
	CreatedAt         time.Time
	Status            Status
	StatusOther       *string
	OriginalObject    interface{}
}

type ClustersRetriever

type ClustersRetriever interface {
	Retrieve(ctx context.Context, opt ...RetrieveOption) (*RetrieveResults, error)
	GetCluster(ctx context.Context, location string, name string) (DiscoveredCluster, error)
}

type DiscoveredCluster

type DiscoveredCluster interface {
	// GetData returns the data of the cluster formatted as a `Cluster` struct.
	// The original object can also be retrieved from it. Check `Cluster`
	// documentation for more.
	GetData() (*Cluster, error)
	// GetToken will ask the cloud provider to generate a token that can be
	// used to authenticate to the cluster.
	GetToken(context.Context) (*token.Token, error)
	// GetConfig will make use of `GetToken` alongside with the cluster data
	// to generate a config that can be used to generate a client for the
	// cluster or a manager for controller-runtime package.
	//
	// Please bear in mind that this config is tied to the token generated by
	// the cloud provider an may not live for long.
	GetConfig(context.Context) (*rest.Config, error)
	// GetClientset will return a Kubernetes client set that you can use to
	// perform operations on the cluster.
	//
	// Please bear in mind that this config is tied to the token generated by
	// the cloud provider an may not live for long.
	GetClientset(context.Context) (*kubernetes.Clientset, error)
}

DiscoveredCluster contains data and functions to either retrieve the data of a cluster or to authenticate and interact with that cluster.

type Platform

type Platform int32
const (
	UNSPECIFIED Platform = iota
	GKE
	EKS
	AKS
)

type RegionError

type RegionError struct {
	Region      string
	ClusterName *string
	Error       error
}

type RetrieveOption

type RetrieveOption func(opts *RetrieveOptions) error

func WithKeepChannelAlive

func WithKeepChannelAlive() RetrieveOption

func WithMaxWorkers

func WithMaxWorkers(workers uint) RetrieveOption

Set the maximum number of workers, or concurrent tasks.

By default, retrievers will try to maximize concurrency and prioritize non-blocking operations, especially in case many regions need to be queried. This option sets a limit on the concurrent tasks that can be performed.

This option will have no effect in case you are providing you own worker pool, in which case you will have to limit concurrency on your own.

Providing `0` will make it use the default value (100).

func WithRegions

func WithRegions(regions ...string) RetrieveOption

Get clusters running *exclusively* in the regions.

This function will provide de-duplication automatically, but will *not* validate whether the regions are enabled for the cloud accout or if they actually exist.

func WithResultChannel

func WithResultChannel(clustersChan chan<- DiscoveredCluster) RetrieveOption

Send results to this channel. The retriever will send clusters to this channel as soon as it finds them.

Once done, the retriever will close this channel to signal that there is no more data to send.

Make sure your channel is buffered before sending it to the retriever to avoid performance penalties in case you expect many clusters to be found.

func WithWorkerPool

func WithWorkerPool(workerPool *ants.Pool) RetrieveOption

Sets a custom worker pool.

This is useful in case you are already using a worker pool for your own purposes and want to re-use your idle workers to perform these tasks.

type RetrieveOptions

type RetrieveOptions struct {
	Regions          map[string]bool
	ClustersChan     chan<- DiscoveredCluster
	KeepChannelAlive bool
	MaxWorkers       uint
	WorkerPool       *ants.Pool
}

type RetrieveResults

type RetrieveResults struct {
	DiscoveredClusters []DiscoveredCluster
	Errors             []RegionError
}

type Status

type Status int32
const (
	Creating Status = iota
	Active
	Stopping
	Inactive
	Updating
	Deleted
	Other
)

Directories

Path Synopsis
internal
utils
Package utils contains code that is used by the cluster package and must not be exposed publicly, or that is has no utility outside of the cluster package.
Package utils contains code that is used by the cluster package and must not be exposed publicly, or that is has no utility outside of the cluster package.

Jump to

Keyboard shortcuts

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