multicluster

package
v1.6.3 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2022 License: Apache-2.0 Imports: 46 Imported by: 6

Documentation

Index

Constants

View Source
const (
	// ClusterGateWayEngine cluster-gateway cluster management solution
	ClusterGateWayEngine = "cluster-gateway"
	// OCMEngine ocm cluster management solution
	OCMEngine = "ocm"
)
View Source
const (
	// ClusterLocalName specifies the local cluster
	ClusterLocalName = pkgmulticluster.Local
)

Variables

View Source
var (
	// ErrClusterExists cluster already exists
	ErrClusterExists = ClusterManagementError(fmt.Errorf("cluster already exists"))
	// ErrClusterNotExists cluster not exists
	ErrClusterNotExists = ClusterManagementError(fmt.Errorf("no such cluster"))
	// ErrReservedLocalClusterName reserved cluster name is used
	ErrReservedLocalClusterName = ClusterManagementError(fmt.Errorf("cluster name `local` is reserved for kubevela hub cluster"))
	// ErrDetectClusterGateway fail to wait for ClusterGateway service ready
	ErrDetectClusterGateway = ClusterManagementError(fmt.Errorf("failed to wait for cluster gateway, unable to use multi-cluster"))
)
View Source
var (
	// ClusterGatewaySecretNamespace the namespace where cluster-gateway secret locates
	ClusterGatewaySecretNamespace = "vela-system"
)

Functions

func AliasCluster added in v1.3.1

func AliasCluster(ctx context.Context, cli client.Client, clusterName string, aliasName string) error

AliasCluster alias cluster

func ClusterNameInContext added in v1.2.0

func ClusterNameInContext(ctx context.Context) string

ClusterNameInContext extract cluster name from context

func ContextInLocalCluster added in v1.2.0

func ContextInLocalCluster(ctx context.Context) context.Context

ContextInLocalCluster create context in local cluster

func ContextWithClusterName

func ContextWithClusterName(ctx context.Context, clusterName string) context.Context

ContextWithClusterName create context with multi-cluster by cluster name

func CreateBootstrapConfigMapIfNotExists added in v1.4.3

func CreateBootstrapConfigMapIfNotExists(ctx context.Context, cli client.Client) error

CreateBootstrapConfigMapIfNotExists alternative to https://github.com/kubernetes/kubernetes/blob/v1.24.1/cmd/kubeadm/app/phases/bootstraptoken/clusterinfo/clusterinfo.go#L43

func DetachCluster added in v1.2.0

func DetachCluster(ctx context.Context, cli client.Client, clusterName string, options ...DetachClusterOption) error

DetachCluster detach cluster by name, if cluster is using by application, it will return error

func GetClusterGatewayService

func GetClusterGatewayService(ctx context.Context, c client.Client) (*apiregistrationv1.ServiceReference, error)

GetClusterGatewayService get cluster gateway backend service reference if service is ready, service is returned and no error is returned if service exists but is not ready, both service and error are returned if service does not exist, only error is returned

func GetVersionInfoFromCluster added in v1.6.0

func GetVersionInfoFromCluster(ctx context.Context, clusterName string, cfg *rest.Config) (types.ClusterVersion, error)

GetVersionInfoFromCluster will add remote cluster version info into secret annotation

func GetVersionInfoFromObject added in v1.6.0

func GetVersionInfoFromObject(ctx context.Context, cli client.Client, clusterName string) types.ClusterVersion

GetVersionInfoFromObject will get cluster version info from virtual cluster, it will fall back to control plane cluster version if any error occur

func InitClusterInfo added in v1.6.0

func InitClusterInfo(cfg *rest.Config) error

InitClusterInfo will initialize control plane cluster info

func Initialize

func Initialize(restConfig *rest.Config, autoUpgrade bool) (client.Client, error)

Initialize prepare multicluster environment by checking cluster gateway service in clusters and hack rest config to use cluster gateway if cluster gateway service is not ready, it will wait up to 5 minutes

func IsClusterDisconnect added in v1.2.0

func IsClusterDisconnect(err error) bool

IsClusterDisconnect check if error is cluster disconnect

func IsClusterNotExists added in v1.2.0

func IsClusterNotExists(err error) bool

IsClusterNotExists check if error is cluster not exists

func IsNotFoundOrClusterNotExists added in v1.2.0

func IsNotFoundOrClusterNotExists(err error) bool

IsNotFoundOrClusterNotExists check if error is not found or cluster not exists

func ListExistingClusterSecrets added in v1.2.0

func ListExistingClusterSecrets(ctx context.Context, c client.Client) ([]v1.Secret, error)

ListExistingClusterSecrets list existing cluster secrets

func RenameCluster added in v1.2.0

func RenameCluster(ctx context.Context, k8sClient client.Client, oldClusterName string, newClusterName string) error

RenameCluster rename cluster

func RequestRawK8sAPIForCluster added in v1.6.0

func RequestRawK8sAPIForCluster(ctx context.Context, path, clusterName string, cfg *rest.Config) ([]byte, error)

RequestRawK8sAPIForCluster will request multi-cluster K8s API with raw client, such as /healthz, /version, etc

func ResourcesWithClusterName added in v1.2.0

func ResourcesWithClusterName(clusterName string, objs ...*unstructured.Unstructured) []*unstructured.Unstructured

ResourcesWithClusterName set cluster name for resources

func SetClusterVersionInfo added in v1.6.0

func SetClusterVersionInfo(ctx context.Context, cfg *rest.Config, clusterName string) error

SetClusterVersionInfo update cluster version info into virtual cluster object

func UpgradeExistingClusterSecret added in v1.1.4

func UpgradeExistingClusterSecret(ctx context.Context, c client.Client) error

UpgradeExistingClusterSecret upgrade outdated cluster secrets in v1.1.1 to latest

func WaitUntilClusterGatewayReady

func WaitUntilClusterGatewayReady(ctx context.Context, c client.Client, maxRetry int, interval time.Duration) (svc *apiregistrationv1.ServiceReference, err error)

WaitUntilClusterGatewayReady wait cluster gateway service to be ready to serve

Types

type ClusterInfo added in v1.2.0

type ClusterInfo struct {
	Nodes             *corev1.NodeList
	WorkerNumber      int
	MasterNumber      int
	MemoryCapacity    resource.Quantity
	CPUCapacity       resource.Quantity
	PodCapacity       resource.Quantity
	MemoryAllocatable resource.Quantity
	CPUAllocatable    resource.Quantity
	PodAllocatable    resource.Quantity
	StorageClasses    *storagev1.StorageClassList
}

ClusterInfo describes the basic information of a cluster

func GetClusterInfo added in v1.2.0

func GetClusterInfo(_ctx context.Context, k8sClient client.Client, clusterName string) (*ClusterInfo, error)

GetClusterInfo retrieves current cluster info from cluster

type ClusterManagementError added in v1.2.0

type ClusterManagementError error

ClusterManagementError multicluster management error

type ClusterMetrics added in v1.3.0

type ClusterMetrics struct {
	IsConnected         bool
	ClusterInfo         *ClusterInfo
	ClusterUsageMetrics *ClusterUsageMetrics
}

ClusterMetrics describes the metrics of a cluster

type ClusterMetricsHelper added in v1.3.0

type ClusterMetricsHelper interface {
	Refresh() error
}

ClusterMetricsHelper is the interface that provides operations for cluster metrics

type ClusterMetricsMgr added in v1.3.0

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

ClusterMetricsMgr manage metrics of clusters

func NewClusterMetricsMgr added in v1.3.0

func NewClusterMetricsMgr(ctx context.Context, kubeClient client.Client, refreshPeriod time.Duration) (*ClusterMetricsMgr, error)

NewClusterMetricsMgr will create a cluster metrics manager

func (*ClusterMetricsMgr) Refresh added in v1.3.0

func (cmm *ClusterMetricsMgr) Refresh() ([]VirtualCluster, error)

Refresh will re-collect cluster metrics and refresh cache

func (*ClusterMetricsMgr) Start added in v1.3.0

func (cmm *ClusterMetricsMgr) Start(ctx context.Context)

Start will start polling cluster api to collect metrics

type ClusterNameMapper added in v1.4.0

type ClusterNameMapper interface {
	GetClusterName(string) string
}

ClusterNameMapper mapper for cluster names

func NewClusterNameMapper added in v1.4.0

func NewClusterNameMapper(ctx context.Context, c client.Client) (ClusterNameMapper, error)

NewClusterNameMapper load all clusters and return the mapper of their names

type ClusterUsageMetrics added in v1.3.0

type ClusterUsageMetrics struct {
	CPUUsage    resource.Quantity
	MemoryUsage resource.Quantity
}

ClusterUsageMetrics describes the usage metrics of a cluster

func GetClusterMetricsFromMetricsAPI added in v1.3.0

func GetClusterMetricsFromMetricsAPI(ctx context.Context, k8sClient client.Client, clusterName string) (*ClusterUsageMetrics, error)

GetClusterMetricsFromMetricsAPI retrieves current cluster metrics based on GetNodeMetricsFromMetricsAPI

type ContextKey added in v1.6.0

type ContextKey string

ContextKey defines the key in context

const KubeConfigContext ContextKey = "kubeConfig"

KubeConfigContext marks the kubeConfig object in context

type DetachClusterArgs added in v1.2.4

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

DetachClusterArgs args for detaching cluster

type DetachClusterManagedClusterKubeConfigPathOption added in v1.2.4

type DetachClusterManagedClusterKubeConfigPathOption string

DetachClusterManagedClusterKubeConfigPathOption configure the managed cluster kubeconfig path while detach ocm cluster

func (DetachClusterManagedClusterKubeConfigPathOption) ApplyToArgs added in v1.2.4

ApplyToArgs apply to args

type DetachClusterOption added in v1.2.4

type DetachClusterOption interface {
	ApplyToArgs(args *DetachClusterArgs)
}

DetachClusterOption option for detach cluster

type FakeClient added in v1.2.0

type FakeClient struct {
	client.Client
	// contains filtered or unexported fields
}

FakeClient set default client and multicluster clients

func NewFakeClient added in v1.2.0

func NewFakeClient(baseClient client.Client) *FakeClient

NewFakeClient create a new fake client

func (*FakeClient) AddCluster added in v1.2.0

func (c *FakeClient) AddCluster(cluster string, cli client.Client)

AddCluster add cluster to client map

func (*FakeClient) Create added in v1.2.0

func (c *FakeClient) Create(ctx context.Context, obj client.Object, opts ...client.CreateOption) error

Create saves the object obj in the Kubernetes cluster.

func (*FakeClient) Delete added in v1.2.0

func (c *FakeClient) Delete(ctx context.Context, obj client.Object, opts ...client.DeleteOption) error

Delete deletes the given obj from Kubernetes cluster.

func (*FakeClient) DeleteAllOf added in v1.2.0

func (c *FakeClient) DeleteAllOf(ctx context.Context, obj client.Object, opts ...client.DeleteAllOfOption) error

DeleteAllOf deletes all objects of the given type matching the given options.

func (*FakeClient) Get added in v1.2.0

func (c *FakeClient) Get(ctx context.Context, key client.ObjectKey, obj client.Object) error

Get retrieves an obj for the given object key from the Kubernetes Cluster. obj must be a struct pointer so that obj can be updated with the response returned by the Server.

func (*FakeClient) List added in v1.2.0

func (c *FakeClient) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error

List retrieves list of objects for a given namespace and list options. On a successful call, Items field in the list will be populated with the result returned from the server.

func (*FakeClient) Patch added in v1.2.0

func (c *FakeClient) Patch(ctx context.Context, obj client.Object, patch client.Patch, opts ...client.PatchOption) error

Patch patches the given obj in the Kubernetes cluster. obj must be a struct pointer so that obj can be updated with the content returned by the Server.

func (*FakeClient) Update added in v1.2.0

func (c *FakeClient) Update(ctx context.Context, obj client.Object, opts ...client.UpdateOption) error

Update updates the given obj in the Kubernetes cluster. obj must be a struct pointer so that obj can be updated with the content returned by the Server.

type JoinClusterArgs added in v1.2.4

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

JoinClusterArgs args for join cluster

type JoinClusterCreateNamespaceOption added in v1.2.4

type JoinClusterCreateNamespaceOption string

JoinClusterCreateNamespaceOption create namespace when join cluster, if empty, no creation

func (JoinClusterCreateNamespaceOption) ApplyToArgs added in v1.2.4

func (op JoinClusterCreateNamespaceOption) ApplyToArgs(args *JoinClusterArgs)

ApplyToArgs apply to args

type JoinClusterEngineOption added in v1.2.4

type JoinClusterEngineOption string

JoinClusterEngineOption configure engine for join cluster, either cluster-gateway or ocm

func (JoinClusterEngineOption) ApplyToArgs added in v1.2.4

func (op JoinClusterEngineOption) ApplyToArgs(args *JoinClusterArgs)

ApplyToArgs apply to args

type JoinClusterOCMOptions added in v1.2.4

type JoinClusterOCMOptions struct {
	IoStreams              cmdutil.IOStreams
	HubConfig              *rest.Config
	InClusterBootstrap     *bool
	TrackingSpinnerFactory func(string) *spinner.Spinner
}

JoinClusterOCMOptions options used when joining clusters by ocm, only support cli for now

func (JoinClusterOCMOptions) ApplyToArgs added in v1.2.4

func (op JoinClusterOCMOptions) ApplyToArgs(args *JoinClusterArgs)

ApplyToArgs apply to args

type JoinClusterOption added in v1.2.4

type JoinClusterOption interface {
	ApplyToArgs(args *JoinClusterArgs)
}

JoinClusterOption option for join cluster

type KubeClusterConfig added in v1.2.4

type KubeClusterConfig struct {
	FilePath        string
	ClusterName     string
	CreateNamespace string
	*clientcmdapi.Config
	*clientcmdapi.Cluster
	*clientcmdapi.AuthInfo

	// Logs records intermediate logs (which do not return error) during running
	Logs bytes.Buffer
}

KubeClusterConfig info for cluster management

func JoinClusterByKubeConfig added in v1.2.0

func JoinClusterByKubeConfig(ctx context.Context, cli client.Client, kubeconfigPath string, clusterName string, options ...JoinClusterOption) (*KubeClusterConfig, error)

JoinClusterByKubeConfig add child cluster by kubeconfig path, return cluster info and error

func LoadKubeClusterConfigFromFile added in v1.2.4

func LoadKubeClusterConfigFromFile(filepath string) (*KubeClusterConfig, error)

LoadKubeClusterConfigFromFile create KubeClusterConfig from kubeconfig file

func (*KubeClusterConfig) PostRegistration added in v1.4.3

func (clusterConfig *KubeClusterConfig) PostRegistration(ctx context.Context, cli client.Client) error

PostRegistration try to create namespace after cluster registered. If failed, cluster will be unregistered.

func (*KubeClusterConfig) RegisterByVelaSecret added in v1.2.4

func (clusterConfig *KubeClusterConfig) RegisterByVelaSecret(ctx context.Context, cli client.Client) error

RegisterByVelaSecret create cluster secrets for KubeVela to use

func (*KubeClusterConfig) RegisterClusterManagedByOCM added in v1.2.4

func (clusterConfig *KubeClusterConfig) RegisterClusterManagedByOCM(ctx context.Context, cli client.Client, args *JoinClusterArgs) error

RegisterClusterManagedByOCM create ocm managed cluster for use TODO(somefive): OCM ManagedCluster only support cli join now

func (*KubeClusterConfig) SetClusterName added in v1.2.4

func (clusterConfig *KubeClusterConfig) SetClusterName(clusterName string) *KubeClusterConfig

SetClusterName set cluster name if not empty

func (*KubeClusterConfig) SetCreateNamespace added in v1.2.4

func (clusterConfig *KubeClusterConfig) SetCreateNamespace(createNamespace string) *KubeClusterConfig

SetCreateNamespace set create namespace, if empty, no namespace will be created

func (*KubeClusterConfig) Validate added in v1.2.4

func (clusterConfig *KubeClusterConfig) Validate() error

Validate check if config is valid for join

type MatchVirtualClusterLabels added in v1.2.4

type MatchVirtualClusterLabels map[string]string

MatchVirtualClusterLabels filters the list/delete operation of cluster list

func (MatchVirtualClusterLabels) ApplyToDeleteAllOf added in v1.2.4

func (m MatchVirtualClusterLabels) ApplyToDeleteAllOf(opts *client.DeleteAllOfOptions)

ApplyToDeleteAllOf applies this configuration to the given a List options.

func (MatchVirtualClusterLabels) ApplyToList added in v1.2.4

func (m MatchVirtualClusterLabels) ApplyToList(opts *client.ListOptions)

ApplyToList applies this configuration to the given list options.

type VirtualCluster added in v1.2.4

type VirtualCluster struct {
	Name     string
	Alias    string
	Type     v1alpha1.CredentialType
	EndPoint string
	Accepted bool
	Labels   map[string]string
	Metrics  *ClusterMetrics
	Object   client.Object
}

VirtualCluster contains base info of cluster, it unifies the difference between different cluster implementations like cluster secret or ocm managed cluster

func FindVirtualClustersByLabels added in v1.2.4

func FindVirtualClustersByLabels(ctx context.Context, c client.Client, labels map[string]string) ([]VirtualCluster, error)

FindVirtualClustersByLabels will get all virtual clusters with matched labels in control plane

func GetVirtualCluster added in v1.2.4

func GetVirtualCluster(ctx context.Context, c client.Client, clusterName string) (vc *VirtualCluster, err error)

GetVirtualCluster returns virtual cluster with given clusterName

func ListVirtualClusters added in v1.2.4

func ListVirtualClusters(ctx context.Context, c client.Client) ([]VirtualCluster, error)

ListVirtualClusters will get all registered clusters in control plane

func NewVirtualClusterFromLocal added in v1.3.0

func NewVirtualClusterFromLocal() *VirtualCluster

NewVirtualClusterFromLocal return virtual cluster corresponding to local cluster

func NewVirtualClusterFromManagedCluster added in v1.2.4

func NewVirtualClusterFromManagedCluster(managedCluster *clusterv1.ManagedCluster) (*VirtualCluster, error)

NewVirtualClusterFromManagedCluster extract virtual cluster from ocm managed cluster

func NewVirtualClusterFromSecret added in v1.2.4

func NewVirtualClusterFromSecret(secret *corev1.Secret) (*VirtualCluster, error)

NewVirtualClusterFromSecret extract virtual cluster from cluster secret

func (*VirtualCluster) FullName added in v1.3.1

func (vc *VirtualCluster) FullName() string

FullName the name with alias if available

Jump to

Keyboard shortcuts

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