multicluster

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2024 License: Apache-2.0 Imports: 27 Imported by: 0

Documentation

Overview

Package multicluster contains functions to add and retrieve multi cluster from context

Index

Constants

This section is empty.

Variables

View Source
var ClusterGVR = ClusterRegistryGroupVersion.WithResource("clusters")
View Source
var ClusterRegistryGVK = ClusterRegistryGroupVersion.WithKind("Cluster")
View Source
var ClusterRegistryGroupVersion = schema.GroupVersion{Group: "clusterregistry.k8s.io", Version: "v1alpha1"}
View Source
var ErrDoesNotHaveEndpoints = errors.New("cluster object does not have spec.kubernetesApiEndpoints.serverEndpoints")
View Source
var ErrDoesNotHaveServerAddress = errors.New("cluster object does not have spec.kubernetesApiEndpoints.serverEndpoints.serverAddress")
View Source
var ErrDoesNotHaveToken = errors.New("secret does not have data.token")
View Source
var ErrNilReference = errors.New("nil reference for clusterRef object")
View Source
var ErrNoNameProvided = errors.New("name must be provided")
View Source
var ErrNoNamespaceProvided = errors.New("namespace must be provided")

Functions

func ClusterNames added in v0.7.0

func ClusterNames(ctx context.Context) []string

ClusterNames return a cluster name list in context

func ClusterProxyHost added in v0.11.0

func ClusterProxyHost(proxyHost string, proxyPath string, clusterName string) (string, error)

ClusterProxyHost constructs a complete proxy URL by replacing the cluster name placeholder in the proxy path It takes the proxy host and path, replaces the "{name}" placeholder with the actual cluster name, and returns the formatted proxy URL.

func ClusterResourceAttributes added in v0.9.0

func ClusterResourceAttributes(verb string) authv1.ResourceAttributes

ClusterResourceAttributes returns a ResourceAttribute object to be used in a filter

func IgnoreForbidden added in v0.7.0

func IgnoreForbidden(ctx context.Context) bool

IgnoreForbidden return a ignore forbidden flag in context

func WithClusterNames added in v0.7.0

func WithClusterNames(ctx context.Context, names []string) context.Context

WithClusterNames adds cluster names to the context

func WithIgnoreForbidden added in v0.7.0

func WithIgnoreForbidden(ctx context.Context, ignoreForbidden bool) context.Context

WithIgnoreForbidden adds ignore forbidden flag to the context

func WithMultiCluster

func WithMultiCluster(ctx context.Context, clt Interface) context.Context

WithMultiCluster adds a multi cluster client to the context

Types

type AuthInfo

type AuthInfo struct {
	// User references an object that contains implementation-specific details
	// about how a user should authenticate against this cluster.
	// +optional
	User *ObjectReference `json:"user,omitempty" protobuf:"bytes,1,opt,name=user"`

	// Controller references an object that contains implementation-specific
	// details about how a controller should authenticate. A simple use case for
	// this would be to reference a secret in another namespace that stores a
	// bearer token that can be used to authenticate against this cluster's API
	// server.
	Controller *ObjectReference `json:"controller,omitempty" protobuf:"bytes,2,opt,name=controller"`
}

AuthInfo holds information that describes how a client can get credentials to access the cluster. For example, OAuth2 client registration endpoints and supported flows, or Kerberos server locations.

type ClientGetter added in v0.9.0

type ClientGetter interface {
	GetClient(ctx context.Context, clusterRef *corev1.ObjectReference, scheme *runtime.Scheme) (clt client.Client, err error)
}

ClientGetter interface get client for a clusterRef and given scheme

type Cluster

type Cluster struct {
	metav1.TypeMeta `json:",inline"`
	// Standard object's metadata.
	// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
	// +optional
	metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`

	// Spec is the specification of the cluster. This may or may not be
	// reconciled by an active controller.
	// +optional
	Spec ClusterSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`

	// Status is the status of the cluster.
	// +optional
	Status ClusterStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
}

Cluster is the Schema for the clusters API +k8s:deepcopy-gen=false

type ClusterCondition

type ClusterCondition struct {
	// Type is the type of the cluster condition.
	Type ClusterConditionType `json:"type" protobuf:"bytes,1,opt,name=type,casttype=ClusterConditionType"`

	// Status is the status of the condition. One of True, False, Unknown.
	Status v1.ConditionStatus `json:"status" protobuf:"bytes,2,opt,name=status,casttype=ConditionStatus"`

	// LastHeartbeatTime is the last time this condition was updated.
	// +optional
	LastHeartbeatTime metav1.Time `json:"lastHeartbeatTime,omitempty" protobuf:"bytes,3,opt,name=lastHeartbeatTime"`

	// LastTransitionTime is the last time the condition changed from one status to another.
	// +optional
	LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty" protobuf:"bytes,4,opt,name=lastTransitionTime"`

	// Reason is a (brief) reason for the condition's last status change.
	// +optional
	Reason string `json:"reason,omitempty" protobuf:"bytes,5,opt,name=reason"`

	// Message is a human-readable message indicating details about the last status change.
	// +optional
	Message string `json:"message,omitempty" protobuf:"bytes,6,opt,name=message"`
}

ClusterCondition contains condition information for a cluster.

type ClusterConditionType

type ClusterConditionType string

ClusterConditionType marks the kind of cluster condition being reported.

const (
	// ClusterOK means that the cluster is "OK".
	//
	// Since the cluster registry does not have a standard status controller, the
	// meaning of this condition is defined by the environment in which the
	// cluster is running. It is expected to mean that the cluster is reachable by
	// a controller that is reporting on its status, and that the cluster is ready
	// to have workloads scheduled.
	ClusterOK ClusterConditionType = "OK"
)

type ClusterFilter added in v0.9.0

type ClusterFilter func(ctx context.Context, clusterRef corev1.ObjectReference) bool

ClusterFilter for filter cluster reousrces

func CustomResourceDefinitionExists added in v0.9.0

func CustomResourceDefinitionExists(cliGetter ClientGetter, CRDName string) ClusterFilter

CustomResourceDefinitionExists returns true if the CRD exists in the cluster

type ClusterList added in v0.9.0

type ClusterList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`

	Items []Cluster `json:"items"`
}

ClusterList represents a list of clusters

type ClusterManager added in v0.9.0

type ClusterManager struct {
	Concurrent int
	Filters    []ClusterFilter
}

ClusterManager manages clusters collection by filters

func (*ClusterManager) FilterClusters added in v0.9.0

func (m *ClusterManager) FilterClusters(ctx context.Context, clusterRefs []corev1.ObjectReference) []corev1.ObjectReference

FilterClusters returns a filtered list of clusters

type ClusterRegistryClient

type ClusterRegistryClient struct {
	dynamic.Interface
	// contains filtered or unexported fields
}

ClusterRegistryClient implements the deprecated cluster registry cluster resource multi cluster client https://github.com/kubernetes-retired/cluster-registry/blob/master/pkg/apis/clusterregistry/v1alpha1/types.go

func (*ClusterRegistryClient) GetClient

func (m *ClusterRegistryClient) GetClient(ctx context.Context, clusterRef *corev1.ObjectReference, scheme *runtime.Scheme) (clt client.Client, err error)

GetClient returns a client using the cluster configuration

func (*ClusterRegistryClient) GetConfig

func (m *ClusterRegistryClient) GetConfig(ctx context.Context, clusterRef *corev1.ObjectReference) (config *rest.Config, err error)

GetConfig returns the configuration based on the Cluster

func (*ClusterRegistryClient) GetConfigFromCluster

func (m *ClusterRegistryClient) GetConfigFromCluster(ctx context.Context, cluster *unstructured.Unstructured) (config *rest.Config, err error)

func (*ClusterRegistryClient) GetDynamic

func (m *ClusterRegistryClient) GetDynamic(ctx context.Context, clusterRef *corev1.ObjectReference) (dyn dynamic.Interface, err error)

GetDynamic returns a dynamic client using the cluster configuration

func (*ClusterRegistryClient) GetNamespaceClusters added in v0.7.0

func (m *ClusterRegistryClient) GetNamespaceClusters(ctx context.Context, namespace string) (clusterRefs []corev1.ObjectReference, err error)

GetNamespaceClusters returns a list of clusters related by namespace

func (*ClusterRegistryClient) ListClustersNamespaces

func (m *ClusterRegistryClient) ListClustersNamespaces(ctx context.Context, namespace string) (clusterNamespaces map[*corev1.ObjectReference][]corev1.Namespace, err error)

ListClustersNamespaces will list namespace with name "namespace" in all clusters

func (*ClusterRegistryClient) StartWarmUpClientCache added in v0.7.0

func (m *ClusterRegistryClient) StartWarmUpClientCache(ctx context.Context)

StartWarmUpClientCache used to start warming the client cache, only needs to be called once.

type ClusterRegistryClientOption added in v0.11.0

type ClusterRegistryClientOption func(*ClusterRegistryClient)

ClusterRegistryClientOption functions for configuring a ClusterRegistryClient

func ClusterProxyInsecure added in v0.11.0

func ClusterProxyInsecure(insecure bool) ClusterRegistryClientOption

ClusterProxyInsecure allows specifying whether the client should use an insecure connection.

func ClusterProxyOption added in v0.11.0

func ClusterProxyOption(proxyHost string, proxyPath string) ClusterRegistryClientOption

ClusterProxyOption sets the proxy host and path for the cluster registry client

type ClusterSpec

type ClusterSpec struct {
	// KubernetesAPIEndpoints represents the endpoints of the API server for this
	// cluster.
	// +optional
	KubernetesAPIEndpoints KubernetesAPIEndpoints `json:"kubernetesApiEndpoints,omitempty" protobuf:"bytes,1,opt,name=kubernetesApiEndpoints"`

	// AuthInfo contains public information that can be used to authenticate
	// to and authorize with this cluster. It is not meant to store private
	// information (e.g., tokens or client certificates) and cluster registry
	// implementations are not expected to provide hardened storage for
	// secrets.
	// +optional
	AuthInfo AuthInfo `json:"authInfo,omitempty" protobuf:"bytes,2,opt,name=authInfo"`
}

ClusterSpec contains the specification of a cluster.

type ClusterStatus

type ClusterStatus struct {
	// Conditions contains the different condition statuses for this cluster.
	Conditions []ClusterCondition `json:"conditions,omitempty" protobuf:"bytes,1,rep,name=conditions"`
}

ClusterStatus contains the status of a cluster.

type ConfigGetter added in v0.10.0

type ConfigGetter interface {
	GetConfig(ctx context.Context, clusterRef *corev1.ObjectReference) (config *rest.Config, err error)
	GetConfigFromCluster(ctx context.Context, cluster *unstructured.Unstructured) (config *rest.Config, err error)
}

ConfigGetter interface get config for a clusterRef

type CrossClusterSubjectReview added in v0.7.0

type CrossClusterSubjectReview struct {
	ClusterParameter string
	ClusterNamespace string
	// contains filtered or unexported fields
}

CrossClusterSubjectReview describe a struct to get the client of special cluster and simulate the requesting user

func NewCrossClusterSubjectReview added in v0.7.0

func NewCrossClusterSubjectReview(mClient Interface, scheme *runtime.Scheme, restMapper meta.RESTMapper) *CrossClusterSubjectReview

NewCrossClusterSubjectReview constructs a new CrossClusterSubjectReview

func (*CrossClusterSubjectReview) GetClient added in v0.7.0

func (c *CrossClusterSubjectReview) GetClient(ctx context.Context, req *restful.Request) (client.Client, error)

GetClient get k8s client of the specified cluster and simulate the requesting user

func (*CrossClusterSubjectReview) SetClusterNamespace added in v0.7.0

func (c *CrossClusterSubjectReview) SetClusterNamespace(ns string)

SetClusterNamespace set the namespace which the cluster resource is stored in

func (*CrossClusterSubjectReview) SetClusterParameter added in v0.7.0

func (c *CrossClusterSubjectReview) SetClusterParameter(parameter string)

SetClusterParameter sets the cluster parameter name

type Interface

type Interface interface {
	GetDynamic(ctx context.Context, clusterRef *corev1.ObjectReference) (dyn dynamic.Interface, err error)

	// ListClustersNamespaces lists all namespaces in all clusters
	// TODO: add this method to the interface and implementation
	ListClustersNamespaces(ctx context.Context, namespace string) (clusterNamespaces map[*corev1.ObjectReference][]corev1.Namespace, err error)
	// StartWarmUpClientCache used to start warming the client cache, only needs to be called once.
	StartWarmUpClientCache(ctx context.Context)

	// ClientGetter for getting client for a clusterRef and given scheme
	ClientGetter

	// NamespaceClustersGetter for getting list of clusters related by special namespace
	NamespaceClustersGetter

	// ConfigGetter for getting config for a clusterRef
	ConfigGetter
}

Interface interface for a multi-cluster functionality

func MultiCluster

func MultiCluster(ctx context.Context) Interface

MultiCluster returns a multicluster client in context

func NewClusterRegistryClient

func NewClusterRegistryClient(config *rest.Config, options ...ClusterRegistryClientOption) (Interface, error)

NewClusterRegistryClient initiates a ClusterRegistryClient

func NewClusterRegistryClientOrDie

func NewClusterRegistryClientOrDie(config *rest.Config, options ...ClusterRegistryClientOption) Interface

NewClusterRegistryClientOrDie initiates a ClusterRegistryClient and panics if it fails

type KubernetesAPIEndpoints

type KubernetesAPIEndpoints struct {
	// ServerEndpoints specifies the address(es) of the Kubernetes API server’s
	// network identity or identities.
	// +optional
	ServerEndpoints []ServerAddressByClientCIDR `json:"serverEndpoints,omitempty" protobuf:"bytes,1,rep,name=serverEndpoints"`

	// CABundle contains the certificate authority information.
	// +optional
	CABundle []byte `json:"caBundle,omitempty" protobuf:"bytes,2,opt,name=caBundle"`
}

KubernetesAPIEndpoints represents the endpoints for one and only one Kubernetes API server.

type NamespaceClustersGetter added in v0.9.0

type NamespaceClustersGetter interface {
	GetNamespaceClusters(ctx context.Context, namespace string) ([]corev1.ObjectReference, error)
}

NamespaceClustersGetter interface get list of clusters related by special namespace

type ObjectReference

type ObjectReference struct {
	// Kind contains the kind of the referent, e.g., Secret or ConfigMap
	// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds
	// +optional
	Kind string `json:"kind,omitempty" protobuf:"bytes,1,opt,name=kind"`

	// Name contains the name of the referent.
	// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
	// +optional
	Name string `json:"name,omitempty" protobuf:"bytes,2,opt,name=name"`

	// Namespace contains the namespace of the referent.
	// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/
	// +optional
	Namespace string `json:"namespace,omitempty" protobuf:"bytes,3,opt,name=namespace"`
}

ObjectReference contains enough information to let you inspect or modify the referred object.

type ServerAddressByClientCIDR

type ServerAddressByClientCIDR struct {
	// The CIDR with which clients can match their IP to figure out if they should
	// use the corresponding server address.
	// +optional
	ClientCIDR string `json:"clientCIDR,omitempty" protobuf:"bytes,1,opt,name=clientCIDR"`
	// Address of this server, suitable for a client that matches the above CIDR.
	// This can be a hostname, hostname:port, IP or IP:port.
	// +optional
	ServerAddress string `json:"serverAddress,omitempty" protobuf:"bytes,2,opt,name=serverAddress"`
}

ServerAddressByClientCIDR helps clients determine the server address that they should use, depending on the ClientCIDR that they match.

Jump to

Keyboard shortcuts

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