multicluster

package
v1.2.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2021 License: Apache-2.0 Imports: 30 Imported by: 6

Documentation

Index

Constants

View Source
const (
	// ClusterContextKey is the name of cluster using in client http context
	ClusterContextKey = contextKey("ClusterName")
	// ClusterLabelKey specifies which cluster the target k8s object should locate
	ClusterLabelKey = "cluster.oam.dev/clusterName"
	// ClusterLocalName specifies the local cluster
	ClusterLocalName = "local"
)

Variables

View Source
var (
	// ErrClusterExists cluster already exists
	ErrClusterExists = ClusterManagementError(fmt.Errorf("cluster already exists"))
	// ErrReservedLocalClusterName reserved cluster name is used
	ErrReservedLocalClusterName = ClusterManagementError(fmt.Errorf("cluster name `local` is reserved for kubevela hub cluster"))
)
View Source
var (
	// ClusterGatewaySecretNamespace the namespace where cluster-gateway secret locates
	ClusterGatewaySecretNamespace string
)

Functions

func ContextWithClusterName

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

ContextWithClusterName create context with multi-cluster by cluster name

func DetachCluster added in v1.2.0

func DetachCluster(ctx context.Context, k8sClient client.Client, clusterName string) error

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

func FormatProxyURL

func FormatProxyURL(clusterName, originalPath string) string

FormatProxyURL will format the request API path by the cluster gateway resources rule

func GarbageCollectionForAllResourceTrackers

func GarbageCollectionForAllResourceTrackers(ctx context.Context, c client.Client, app *v1beta1.Application) error

GarbageCollectionForAllResourceTrackers run garbage collection in sub clusters and remove all ResourceTrackers, including managed cluster

func GarbageCollectionForAllResourceTrackersInSubCluster

func GarbageCollectionForAllResourceTrackersInSubCluster(ctx context.Context, c client.Client, app *v1beta1.Application) error

GarbageCollectionForAllResourceTrackersInSubCluster run garbage collection in sub clusters and remove all ResourceTrackers

func GarbageCollectionForOutdatedResourcesInSubClusters

func GarbageCollectionForOutdatedResourcesInSubClusters(ctx context.Context, c client.Client, app *v1beta1.Application, gcHandler func(context.Context) error) error

GarbageCollectionForOutdatedResourcesInSubClusters run garbage collection in sub clusters and remove outdated ResourceTrackers with their associated resources

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 GetMulticlusterKubernetesClient added in v1.2.0

func GetMulticlusterKubernetesClient() (client.Client, *rest.Config, error)

GetMulticlusterKubernetesClient get client with multicluster function enabled

func GetMutableClusterSecret added in v1.2.0

func GetMutableClusterSecret(ctx context.Context, c client.Client, clusterName string) (*v1.Secret, error)

GetMutableClusterSecret retrieves the cluster secret and check if any application is using the cluster

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 JoinClusterByKubeConfig added in v1.2.0

func JoinClusterByKubeConfig(_ctx context.Context, k8sClient client.Client, kubeconfigPath string, clusterName string) (*api.Cluster, error)

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

func ListExistingClusterSecrets added in v1.2.0

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

ListExistingClusterSecrets list existing cluster secrets

func NewClusterGatewayRoundTripperWrapperGenerator added in v1.2.0

func NewClusterGatewayRoundTripperWrapperGenerator(clusterName string) transport.WrapperFunc

NewClusterGatewayRoundTripperWrapperGenerator create RoundTripper WrapperFunc that redirect requests to target cluster

func NewSecretModeMultiClusterRoundTripper

func NewSecretModeMultiClusterRoundTripper(rt http.RoundTripper) http.RoundTripper

NewSecretModeMultiClusterRoundTripper will re-write the API path to one of the multi-cluster resource for a request if context has the value

func NewSecretModeMultiClusterRoundTripperForCluster added in v1.2.0

func NewSecretModeMultiClusterRoundTripperForCluster(rt http.RoundTripper, clusterName string) http.RoundTripper

NewSecretModeMultiClusterRoundTripperForCluster will re-write the API path to the specific cluster

func RenameCluster added in v1.2.0

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

RenameCluster rename cluster

func SetClusterName

func SetClusterName(obj *unstructured.Unstructured, clusterName string)

SetClusterName set cluster name for 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             *v1.NodeList
	WorkerNumber      int
	MasterNumber      int
	MemoryCapacity    resource.Quantity
	CPUCapacity       resource.Quantity
	PodCapacity       resource.Quantity
	MemoryAllocatable resource.Quantity
	CPUAllocatable    resource.Quantity
	PodAllocatable    resource.Quantity
	StorageClasses    *v14.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

Jump to

Keyboard shortcuts

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