clusterclient

package
v0.0.0-...-b25b198 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2023 License: Apache-2.0 Imports: 78 Imported by: 0

Documentation

Overview

Package clusterclient implements generic functions for talking to cluster

Index

Constants

View Source
const (
	CheckResourceInterval = 5 * time.Second
	CheckClusterInterval  = 10 * time.Second

	CheckAutoscalerDeploymentTimeout = 2 * time.Minute
	AVIResourceCleanupTimeout        = 2 * time.Minute
	PackageInstallPollInterval       = 10 * time.Second
	PackageInstallTimeout            = 10 * time.Minute
)

constants regarding timeout and configs

View Source
const (
	AWSBootstrapCredentialsSecret   = "capa-manager-bootstrap-credentials" // #nosec
	AzureBootstrapCredentialsSecret = "capz-manager-bootstrap-credentials" // #nosec
	AzureControllerManagerDeploy    = "capz-controller-manager"
	KeyAzureClientID                = "client-id"
	KeyAzureSubsciptionID           = "subscription-id"
	KeyAzureClientSecret            = "client-secret"
	KeyAzureTenantID                = "tenant-id"
	KeyAWSCredentials               = "credentials"
	KeyVSphereCredentials           = "credentials.yaml"
	KeyVSphereCsiConfig             = "values.yaml"
	KeyVSphereCpiConfig             = "values.yaml"
	KeyCAInSecret                   = "ca.crt"
	CapvNamespace                   = "capv-system"
	CapzNamespace                   = "capz-system"
)

constants related to credentials

View Source
const (
	TKGOperationInfoKey                  = "TKGOperationInfo"
	TKGOperationLastObservedTimestampKey = "TKGOperationLastObservedTimestamp"
	TKGVersionKey                        = "TKGVERSION"
	CAPAControllerNamespace              = "capa-system"
	CAPACredentialsSecretName            = "capa-manager-bootstrap-credentials"
	CAPAControllerDeploymentName         = "capa-controller-manager"
)

constants related to tkg operation info that are used for adding annotations to the clusters

View Source
const (
	OperationTypeUpgrade = "Upgrade"
	OperationTypeCreate  = "Create"
)

Operation type constants

View Source
const (
	ErrUnableToGetPackage = "unable to get the package: '%s' in namespace: '%s'"
)

Variables

View Source
var (
	// Sleep implements time.Sleep and used indirectly to mock for unit tests
	Sleep = time.Sleep
)

Functions

func UpdateCoreDNSImageRepositoryInKubeadmConfigMap

func UpdateCoreDNSImageRepositoryInKubeadmConfigMap(kubedmconfigmap *corev1.ConfigMap, newImageRepository string) error

UpdateCoreDNSImageRepositoryInKubeadmConfigMap updates coredns imageRepository in kubeadm-config configMap

func VerifyAVIResourceCleanupFinished

func VerifyAVIResourceCleanupFinished(obj crtclient.Object) error

VerifyAVIResourceCleanupFinished verifies that avi objects clean up finished.

func VerifyAutoscalerDeploymentAvailable

func VerifyAutoscalerDeploymentAvailable(obj crtclient.Object) error

VerifyAutoscalerDeploymentAvailable verifies autoscaler deployment's availability

func VerifyCRSAppliedSuccessfully

func VerifyCRSAppliedSuccessfully(obj crtclient.ObjectList) error

VerifyCRSAppliedSuccessfully verifies that all CRS objects are applied successfully after cluster creation

func VerifyClusterInitialized

func VerifyClusterInitialized(obj crtclient.Object) error

VerifyClusterInitialized verifies the cluster is initialized or not (this is required before reading the kubeconfig secret)

func VerifyClusterReady

func VerifyClusterReady(obj crtclient.Object) error

VerifyClusterReady verifies the cluster is ready or not (this is required before starting the move operation)

func VerifyDeploymentAvailable

func VerifyDeploymentAvailable(obj crtclient.Object) error

VerifyDeploymentAvailable verifies the deployment has at least one replica running under it or not

func VerifyKubeadmControlPlaneReplicas

func VerifyKubeadmControlPlaneReplicas(obj crtclient.ObjectList) error

VerifyKubeadmControlPlaneReplicas verifies the KubeadmControlPlane has all the required replicas (this is required before starting the move operation)

func VerifyMachineDeploymentsReplicas

func VerifyMachineDeploymentsReplicas(obj crtclient.ObjectList) error

VerifyMachineDeploymentsReplicas verifies the MachineDeployment has all the required replicas (this is required before starting the move operation)

func VerifyMachinesReady

func VerifyMachinesReady(obj crtclient.ObjectList) error

VerifyMachinesReady verifies the machine are ready or not (this is required before starting the move operation)

func VerifyPackageInstallReconciledSuccessfully

func VerifyPackageInstallReconciledSuccessfully(obj crtclient.Object) error

VerifyPackageInstallReconciledSuccessfully verifies that packageInstall reconcile successfully

Types

type ApplyFileOptions

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

ApplyFileOptions configures a kubectl apply, whether it is recursive or not

type Client

type Client interface {
	// MergeAndUseConfig takes a kubeconfig as a string, merges it into the client's kubeconfig
	// path, and return current and previous kube contexts. The current context is also updated in said
	// path to use the new context added. This allows other client-side tools like kubectl, and
	// octant to interact with the cluster associated with the context without additional configuration.
	MergeAndUseConfigForCluster(kubeConfig []byte, overrideContextName string) (string, string, error)

	// MergeConfigForCluster merges a kubeconfig into the client's kubeconfig path.
	MergeConfigForCluster(kubeConfig []byte, mergeFile string) error

	// Apply applies a yaml string to a cluster
	Apply(string) error
	// ApplyFile runs kubectl apply on a file/url every `interval` until it succeeds or a timeout is reached.
	ApplyFile(string) error
	// ApplyFileRecursively runs kubectl apply recursively in certain namespace on a dir/url every `interval` until it succeeds or a timeout is reached.
	ApplyFileRecursively(string, string) error
	// WaitForClusterInitialized waits for a cluster to be initialized so the kubeconfig file can be fetched
	WaitForClusterInitialized(clusterName string, namespace string) error
	// WaitForControlPlaneAvailable wait for cluster API server is ready to receive requests
	WaitForControlPlaneAvailable(clusterName string, namespace string) error
	// WaitForClusterReady for a cluster to be fully provisioned and so ready to be moved
	// If checkReplicas is true, will also ensure that the number of ready
	// replicas matches the expected number in the cluster's spec
	WaitForClusterReady(clusterName string, namespace string, checkReplicas bool) error
	// WaitForClusterDeletion waits for cluster object to be deleted
	WaitForClusterDeletion(clusterName string, namespace string) error
	// WaitForDeployment for a deployment to be fully available
	WaitForDeployment(deploymentName string, namespace string) error
	// WaitForAutoscalerDeployment waits for the autoscaler deployment to be available
	WaitForAutoscalerDeployment(deploymentName string, namespace string) error
	// ApplyPatchForAutoScalerDeployment update autoscaler by patch image
	ApplyPatchForAutoScalerDeployment(tkgBomClient tkgconfigbom.Client, clusterName string, k8sVersion string, namespace string) error
	// WaitForAVIResourceCleanUp waits for the avi resource clean up finished
	WaitForAVIResourceCleanUp(statefulSetName, namespace string) error
	// WaitForPackageInstall waits for the package to be installed successfully
	WaitForPackageInstall(packageName, namespace string, packageInstallTimeout time.Duration) error
	// WaitK8sVersionUpdateForCPNodes waits for k8s version to be updated
	WaitK8sVersionUpdateForCPNodes(clusterName, namespace, kubernetesVersion string, workloadClusterClient Client) error
	// WaitK8sVersionUpdateForWorkerNodes waits for k8s version to be updated in all worker nodes
	WaitK8sVersionUpdateForWorkerNodes(clusterName, namespace, kubernetesVersion string, workloadClusterClient Client) error
	// GetKubeConfigForCluster returns the admin kube config for accessing the cluster
	GetKubeConfigForCluster(clusterName string, namespace string, pollOptions *PollOptions) ([]byte, error)
	// GetPackage returns the package for given package name in a given namespace
	GetPackage(carvelPkgName, carvelPkgNamespace string) (*kapppkgv1alpha1.Package, error)
	// GetSecretValue returns the value for a given key in a Secret
	GetSecretValue(secretName, key, namespace string, pollOptions *PollOptions) ([]byte, error)
	// GetCurrentNamespace returns the namespace from the current context in the kubeconfig file
	GetCurrentNamespace() (string, error)
	// CreateNamespace creates namespace if missing
	CreateNamespace(name string) error
	// UseContext updates current-context in the kubeconfig file
	// also updates the clientset of clusterclient to point to correct cluster
	UseContext(contextName string) error

	// GetResource gets the kubernetes resource passed as reference either directly or with polling mechanism
	// resourceReference is a reference to resource struct you want to retrieve
	// resourceName is name of the resource to get
	// namespace is namespace in which the resource to be searched, if empty current namespace will be used
	// postVerify verifies the resource with some state once it is retrieved from kubernetes, pass nil if nothing to verify
	// pollOptions use this if you want to continuously poll for object if error occurs, pass nil if don't want polling
	// Note: Make sure resource you are retrieving is added into Scheme with init function below
	GetResource(resourceReference interface{}, resourceName, namespace string, postVerify PostVerifyrFunc, pollOptions *PollOptions) error
	// GetResourceList gets the list kubernetes resources passed as reference either directly or with polling mechanism
	// resourceReference is a reference to resource struct you want to retrieve
	// resourceName is name of the resource to get
	// namespace is namespace in which the resource to be searched, if empty current namespace will be used
	// postVerify verifies the resource with some state once it is retrieved from kubernetes, pass nil if nothing to verify
	// pollOptions use this if you want to continuously poll for object if error occurs, pass nil if don't want polling
	// Note: Make sure resource you are retrieving is added into Scheme with init function below
	GetResourceList(resourceReference interface{}, clusterName, namespace string, postVerify PostVerifyListrFunc, pollOptions *PollOptions) error

	// ListResources lists the kubernetes resources, pass reference of the object you want to get
	// Note: Make sure resource you are retrieving is added into Scheme in init function below
	ListResources(resourceReference interface{}, option ...crtclient.ListOption) error
	// DeleteResource deletes the kubernetes resource, pass reference of the object you want to delete
	DeleteResource(resourceReference interface{}) error
	// PatchResource patches the kubernetes resource with procide patch string
	// resourceReference is a reference to resource struct you want to retrieve
	// resourceName is name of the resource to patch
	// namespace is namespace in which the resource to be searched, if empty current namespace will be used
	// patchJSONString is string representation of json of resource configuration
	// pollOptions use this if you want to continuously poll and patch the object if error occurs, pass nil if don't want polling
	PatchResource(resourceReference interface{}, resourceName, namespace, patchJSONString string, patchType types.PatchType, pollOptions *PollOptions) error
	// CreateResource creates the kubernetes resource
	// resourceReference is a reference to resource struct you want to create
	// resourceName is name of the resource to create
	// namespace is namespace in which the resource to be created, if empty current namespace will be used
	// opts is options for resource creation
	CreateResource(resourceReference interface{}, resourceName, namespace string, opts ...crtclient.CreateOption) error
	// UpdateResource updates the kubernetes resource
	// resourceReference is a reference to resource struct you want to create
	// resourceName is name of the resource to create
	// namespace is namespace in which the resource to be created, if empty current namespace will be used
	// opts is options for resource creation
	UpdateResource(resourceReference interface{}, resourceName, namespace string, opts ...crtclient.UpdateOption) error
	// UpdateResourceWithPolling wraps the UpdateResource function and allows the caller to retry the function until it succeeds
	UpdateResourceWithPolling(resourceReference interface{}, resourceName, namespace string, pollOptions *PollOptions, opts ...crtclient.UpdateOption) error
	// ExportCurrentKubeconfigToFile saves the current kubeconfig to temporary file and returns the file
	ExportCurrentKubeconfigToFile() (string, error)
	// GetCurrentKubeconfigFile returns currently used kubeconfig file path based on default loading rules
	GetCurrentKubeconfigFile() string
	// GetCurrentClusterName returns the current clusterName based on current context from kubeconfig file
	// If context parameter is not empty, then return clusterName corresponding to the context
	GetCurrentClusterName(context string) (string, error)
	// GetCurrentKubeContext returns the current kube context
	GetCurrentKubeContext() (string, error)
	// IsRegionalCluster() checks if the current kube context point to a management cluster
	IsRegionalCluster() error
	// GetRegionalClusterDefaultProviderName returns the default provider name of provider type
	GetRegionalClusterDefaultProviderName(providerType clusterctlv1.ProviderType) (string, error)
	// ListClusters lists workload cluster managed by a management cluster in a given namespace
	ListClusters(namespace string) ([]capi.Cluster, error)
	// DeleteCluster deletes cluster in the given namespace
	DeleteCluster(clusterName string, namespace string) error
	// GetKubernetesVersion gets kubernetes server version for a given cluster
	GetKubernetesVersion() (string, error)
	// GetDeployment gets deployment object in the specified namespace
	GetDeployment(deploymentName string, namespace string) (appsv1.Deployment, error)
	// GetMDObjectForCluster gets machine deployment object of worker nodes for cluster
	GetMDObjectForCluster(clusterName string, namespace string) ([]capi.MachineDeployment, error)
	// GetClusterControlPlaneNodeObject gets cluster control plane node for cluster
	GetKCPObjectForCluster(clusterName string, namespace string) (*controlplanev1.KubeadmControlPlane, error)
	// GetMachineObjectsForCluster gets control-plane machine and worker machine lists for cluster
	GetMachineObjectsForCluster(clusterName string, namespace string) (map[string]capi.Machine, map[string]capi.Machine, error)
	// UpdateReplicas updates the replica count for the given resource
	UpdateReplicas(resourceReference interface{}, resourceName, resourceNameSpace string, replicaCount int32) error
	// IsPacificRegionalCluster checks if the cluster pointed to by kubeconfig  is Pacific management cluster(supervisor)
	IsPacificRegionalCluster() (bool, error)
	// GetPacificClusterObject gets Pacific cluster object
	GetPacificClusterObject(clusterName, namespace string) (*tkgsv1alpha2.TanzuKubernetesCluster, error)
	// WaitForPacificCluster waits for the Vsphere-pacific provider workload cluster to be fully provisioned
	WaitForPacificCluster(clusterName string, namespace string) error
	// ListPacificClusterObjects returns TanzuKubernetesClusterList object
	ListPacificClusterObjects(apiVersion string, listOptions *crtclient.ListOptions) ([]interface{}, error)
	// ScalePacificClusterControlPlane scales Pacific workload cluster control plane
	ScalePacificClusterControlPlane(clusterName, namespace string, controlPlaneCount int32) error
	// ScalePacificClusterWorkerNodes scales Pacific workload cluster worker nodes
	ScalePacificClusterWorkerNodes(clusterName, namespace string, workersCount int32) error
	// LoadCurrentKubeconfigBytes returns the current kubeconfig with current regional context in bytes
	LoadCurrentKubeconfigBytes() ([]byte, error)

	// CloneWithTimeout returns a new client with the same attributes of the current one except for get client timeout settings
	CloneWithTimeout(getClientTimeout time.Duration) Client
	// GetVCClientAndDataCenter returns vsphere client and datacenter name by reading on cluster resources
	GetVCClientAndDataCenter(clusterName, clusterNamespace, vsphereMachineTemplateObjectName string, vcClientFactory vc.VcClientFactory) (vc.Client, string, error)
	// PatchK8SVersionToPacificCluster patches the Pacific TKC object to update the k8s version on the cluster
	PatchK8SVersionToPacificCluster(clusterName, namespace string, kubernetesVersion string) error
	// WaitForPacificClusterK8sVersionUpdate waits for the Pacific TKC cluster to update k8s version
	WaitForPacificClusterK8sVersionUpdate(clusterName, namespace, kubernetesVersion string) error
	// PatchClusterWithOperationStartedStatus applies patch to cluster objects annotations
	// with operation status information which includes type of operation, start time and timeout
	// This information along with operation last observed timestamp will be used to determine
	// stalled state of the cluster
	PatchClusterWithOperationStartedStatus(clusterName, namespace, operationType string, timeout time.Duration) error
	// PatchClusterObjectWithTKGVersion applies patch to cluster objects based on given tkgVersion string
	PatchClusterObjectWithTKGVersion(clusterName, clusterNamespace, tkgVersion string) error
	// PatchClusterObjectAnnotations applies patch to cluster objects to update annotation with specified key:value
	PatchClusterObjectAnnotations(clusterName, namespace, key, value string) error
	// GetManagementClusterTKGVersion returns the TKG version of a management cluster based on the
	// annotation value present in cluster object
	GetManagementClusterTKGVersion(mgmtClusterName, clusterNamespace string) (string, error)
	// PatchCalicoNodeDaemonSetWithNewNodeSelector patches calico daemonset with new nodeSelector
	PatchCalicoNodeDaemonSetWithNewNodeSelector(selectorKey, selectorValue string) error
	// PatchCalicoKubeControllerDeploymentWithNewNodeSelector patches calico-kube-controller deployment with new nodeSelector
	PatchCalicoKubeControllerDeploymentWithNewNodeSelector(selectorKey, selectorValue string) error
	// PatchImageRepositoryInKubeProxyDaemonSet updates kubeproxy daemonset with new/custom image repository
	PatchImageRepositoryInKubeProxyDaemonSet(newImageRepository string) error
	// PatchKappControllerLastAppliedAnnotation ensures the kapp-controller deployment on the cluster has last-applied annotation
	PatchKappControllerLastAppliedAnnotation(namespace string) error
	// PatchClusterAPIAWSControllersToUseEC2Credentials ensures that the Cluster API Provider AWS
	// controller is pinned to control plane nodes and is running without static credentials such
	// that Cluster API AWS runs using the EC2 instance profile attached to the control plane node.
	// This is done by zeroing out the credentials secret for CAPA, causing the AWS SDK to fall back
	// to the default credential provider chain. We additionally patch the deployment to ensure
	// the controller has node affinity to only run on the control plane nodes.
	// This should NOT be used when running Cluster API Provider AWS on managed control planes, e.g. EKS
	PatchClusterAPIAWSControllersToUseEC2Credentials() error
	// PatchCoreDNSImageRepositoryInKubeadmConfigMap updates kubeadm-config configMap with new/custom image repository
	PatchCoreDNSImageRepositoryInKubeadmConfigMap(newImageRepository string) error
	// PatchClusterObjectWithOptionalMetadata applies patch to cluster objects based on given optional metadata
	// under the key provided as metadataKey (e.g. annotations, labels) where the value is in the form of a
	// map[string]string (e.g. [Description]some-description) where the key is the name of the metadata property.
	PatchClusterObjectWithOptionalMetadata(clusterName, clusterNamespace, metadataKey string, metadata map[string]string) (string, error)
	// PatchClusterObject patches cluster object with specified json patch
	PatchClusterObject(clusterName, clusterNamespace string, patchJSONString string) error
	// PatchClusterObject patches cluster object with specified json patch with poll options
	PatchClusterObjectWithPollOptions(clusterName, clusterNamespace, patchJSONString string, pollOptions *PollOptions) error
	// DeleteExistingKappController deletes the kapp-controller that already exists in the cluster.
	DeleteExistingKappController() error
	// UpdateAWSCNIIngressRules updates the cniIngressRules field for the AWSCluster resource.
	UpdateAWSCNIIngressRules(clusterName, clusterNamespace string, newRule capav1beta2.CNIIngressRule) error
	// AddCEIPTelemetryJob creates telemetry cronjob component on cluster
	AddCEIPTelemetryJob(clusterName, providerName string, bomConfig *tkgconfigbom.BOMConfiguration, isProd, labels, httpProxy, httpsProxy, noProxy string) error
	// RemoveCEIPTelemetryJob deletes telemetry cronjob component on cluster
	RemoveCEIPTelemetryJob(clusterName string) error
	// HasCEIPTelemetryJob checks if telemetry cronjob component is on cluster
	HasCEIPTelemetryJob(clusterName string) (bool, error)
	// GetPacificTKCAPIVersion gets the Pacific TKC API version
	GetPacificTKCAPIVersion() (string, error)
	// GetPacificTanzuKubernetesReleases returns the list of TanzuKubernetesRelease versions if TKr object is available in TKGS
	GetPacificTanzuKubernetesReleases() ([]string, error)
	// GetVCCredentialsFromSecret gets the vSphere username and password used to deploy the cluster
	// Deprecated: use GetVCCredentialsFromCluster() method instead which would use both clustername and namespace to get the VC credentials
	GetVCCredentialsFromSecret(string) (string, string, error)
	// GetVCCredentialsFromCluster gets the vSphere username and password used to deploy the cluster
	GetVCCredentialsFromCluster(string, string) (string, string, error)
	// GetVCServer gets the vSphere server that used to deploy the cluster
	GetVCServer() (string, error)
	// GetAWSEncodedCredentialsFromSecret gets the AWS base64 credentials used to deploy the cluster
	GetAWSCredentialsFromSecret() (string, error)
	// GetAzureCredentialsFromSecret gets the Azure base64 credentials used to deploy the cluster
	GetAzureCredentialsFromSecret() (azureclient.Credentials, error)
	// GetAzureCredentialsFromIdentity gets the Azure base64 credentials from AzureClusterIdentity
	GetAzureCredentialsFromIdentity(identityName string, identityNamespace string) (azureclient.Credentials, error)
	// UpdateCapvManagerBootstrapCredentialsSecret updates the vsphere creds used by the capv provider
	UpdateCapvManagerBootstrapCredentialsSecret(username string, password string) error
	// UpdateVsphereIdentityRefSecret updates vsphere cluster identityRef secret
	UpdateVsphereIdentityRefSecret(clusterName, namespace, username, password string) error
	// UpdateVsphereCloudProviderCredentialsSecret updates the vsphere creds used by the vsphere cloud provider
	UpdateVsphereCloudProviderCredentialsSecret(clusterName string, namespace string, username string, password string) error
	// UpdateVsphereCsiConfigSecret updates the vsphere csi config secret
	UpdateVsphereCsiConfigSecret(clusterName string, namespace string, username string, password string) error
	// UpdateCapzManagerBootstrapCredentialsSecret updates the azure creds used by the capz provider
	UpdateCapzManagerBootstrapCredentialsSecret(tenantID string, clientID string, clientSecret string) error
	// GetAzureClusterName gets AzureCluster Name and Namespace
	GetAzureClusterName(clusterName string, namespace string) (string, string, error)
	// GetKubeadmControlPlaneName gets KubeadmControlPlane Name and Namespace
	GetKubeadmControlPlaneName(clusterName, namespace string) (string, string, error)
	// UpdateAzureClusterIdentity returns whether the cluster used the same azure cluster identityRef with the management cluster
	CheckUnifiedAzureClusterIdentity(clusterName string, namespace string) (bool, error)
	// UpdateAzureClusterIdentity updates the azure cluster identityRef used by the capz provider
	UpdateAzureClusterIdentity(clusterName string, namespace string, tenantID string, clientID string, clientSecret string) error
	// GetCAPZControllerManagerDeploymentsReplicas gets current replicas for the capz-controller-manager deployment
	GetCAPZControllerManagerDeploymentsReplicas() (int32, error)
	// UpdateCAPZControllerManagerDeploymentReplicas update the capz-controller-manager deployment replicas
	UpdateCAPZControllerManagerDeploymentReplicas(replicas int32) error
	// UpdateAzureKCP recycles KCP for the azure cloud provider
	UpdateAzureKCP(clusterName string, namespace string) error
	// GetClientSet gets one clientset used to generate objects list
	GetClientSet() CrtClient
	// GetPinnipedIssuerURLAndCA fetches Pinniped supervisor IssuerURL and IssuerCA data from management cluster
	GetPinnipedIssuerURLAndCA() (string, string, error)
	// GetTanzuKubernetesReleases returns the TKr's with 'tkrName' prefix match. If tkrName is not provided it returns all the available TKr's
	GetTanzuKubernetesReleases(tkrName string) ([]runv1alpha1.TanzuKubernetesRelease, error)
	// GetBomConfigMap returns configmap associated w3ith the tkrNameLabel
	GetBomConfigMap(tkrNameLabel string) (corev1.ConfigMap, error)
	// GetClusterResolvedTanzuKubernetesRelease gets the resolved TKR for the management cluster
	GetClusterResolvedTanzuKubernetesRelease() (*runv1alpha3.TanzuKubernetesRelease, error)
	// GetClusterResolvedOSImagesFromTKR get a list of OSImage resource from the resolved TKR
	GetClusterResolvedOSImagesFromTKR(*runv1alpha3.TanzuKubernetesRelease) ([]*runv1alpha3.OSImage, error)
	// GetClusterInfrastructure gets cluster infrastructure name like VSphereCluster, AWSCluster, AzureCluster
	GetClusterInfrastructure() (string, error)
	// ActivateTanzuKubernetesReleases activates TanzuKubernetesRelease
	// Deprecated: This would not be supported from TKR API version v1alpha3,
	// user can use go client to set the labels to activate/deactivate the TKR
	ActivateTanzuKubernetesReleases(tkrName string) error
	// DeactivateTanzuKubernetesReleases deactivates TanzuKubernetesRelease
	// Deprecated: This would not be supported from TKR API version v1alpha3,
	// user can use go client to set the labels to activate/deactivate the TKR
	DeactivateTanzuKubernetesReleases(tkrName string) error
	// IsClusterRegisteredToTMC returns true if cluster is registered to Tanzu Mission Control
	IsClusterRegisteredToTMC() (bool, error)
	// ListCLIPluginResources lists CLIPlugin resources across all namespaces
	ListCLIPluginResources() ([]cliv1alpha1.CLIPlugin, error)
	// VerifyCLIPluginCRD returns true if CRD exists else return false
	VerifyCLIPluginCRD() (bool, error)
	// IsClusterClassBased check whether cluster is ClusterClass based or not
	IsClusterClassBased(clusterName, namespace string) (bool, error)
	// GetClusterStatusInfo returns the cluster status information
	GetClusterStatusInfo(clusterName, namespace string, workloadClusterClient Client) ClusterStatusInfo
	// GetCLIPluginImageRepositoryOverride returns map of image repository override
	GetCLIPluginImageRepositoryOverride() (map[string]string, error)
	// VerifyExistenceOfCRD returns true if CRD exists else return false
	VerifyExistenceOfCRD(resourceName, resourceGroup string) (bool, error)
	// RemoveMatchingMetadataFromResources removes matching metadata (labels or annotations) for specified resource types
	RemoveMatchingMetadataFromResources(gvk schema.GroupVersionKind, namespace string, metadataKey string, keysToRemove []string) error
}

Client provides various aspects of interaction with a Kubernetes cluster provisioned by TKG

func NewClient

func NewClient(kubeConfigPath string, context string, options Options) (Client, error)

NewClient creates new clusterclient from kubeconfig file and poller if kubeconfig path is empty it gets default path if options.poller is nil it creates default poller. You should only pass custom poller for unit testing if options.crtClientFactory is nil it creates default CrtClientFactory

type ClusterClientFactory

type ClusterClientFactory interface {
	NewClient(kubeConfigPath, context string, options Options) (Client, error)
}

ClusterClientFactory a factory for creating cluster clients

func NewClusterClientFactory

func NewClusterClientFactory() ClusterClientFactory

NewClusterClientFactory creates new clusterclient factory

type ClusterStatusInfo

type ClusterStatusInfo struct {
	KubernetesVersion    string
	ClusterObject        *capi.Cluster
	KCPObject            *controlplanev1.KubeadmControlPlane
	MDObjects            []capi.MachineDeployment
	CPMachineObjects     map[string]capi.Machine
	WorkerMachineObjects map[string]capi.Machine
	RetrievalError       error
}

ClusterStatusInfo defines the cluster status involving all main components

type CrtClient

type CrtClient interface {
	crtclient.Client
}

CrtClient clientset interface

type CrtClientFactory

type CrtClientFactory interface {
	NewClient(config *rest.Config, options crtclient.Options) (crtclient.Client, error)
}

CrtClientFactory is a interface to create controller runtime client

type DiscoveryClient

type DiscoveryClient interface {
	discovery.DiscoveryInterface
}

DiscoveryClient discovery client interface

type DiscoveryClientFactory

type DiscoveryClientFactory interface {
	NewDiscoveryClientForConfig(config *rest.Config) (discovery.DiscoveryInterface, error)
}

DiscoveryClientFactory is a interface to create discovery client

type DynamicClient

type DynamicClient interface {
	dynamic.Interface
}

type DynamicClientFactory

type DynamicClientFactory interface {
	NewDynamicClientForConfig(config *rest.Config) (dynamic.Interface, error)
}

DynamicClientFactory is a interface to create adynamic client

type GetterFunc

type GetterFunc func() (interface{}, error)

GetterFunc is a function which should be used as closure

type JSONPatch

type JSONPatch struct {
	Op    string `json:"op"`
	Path  string `json:"path"`
	Value string `json:"value"`
}

JSONPatch patch used for patching of object using patch of type JSONPatchType

type OperationStatus

type OperationStatus struct {
	Operation               string `json:"Operation"`
	OperationStartTimestamp string `json:"OperationStartTimestamp"`
	OperationTimeout        int    `json:"OperationTimeout"`
}

OperationStatus describes current status of running operation this struct is used for patching cluster object with the last invoked operation information. This information combined with TKGOperationLastObservedTimestamp will be used for determining stalled state of a cluster

type Options

type Options struct {
	GetClientInterval time.Duration
	GetClientTimeout  time.Duration
	OperationTimeout  time.Duration
	// contains filtered or unexported fields
}

Options provides way to customize creation of clusterClient

func NewOptions

func NewOptions(poller Poller, crtClientFactory CrtClientFactory, discoveryClientFactory DiscoveryClientFactory, verificationClientFactory *VerificationClientFactory) Options

NewOptions returns new options

type PollOptions

type PollOptions struct {
	Interval time.Duration
	Timeout  time.Duration
}

PollOptions is options for polling

func NewPollOptions

func NewPollOptions(interval, timeout time.Duration) *PollOptions

NewPollOptions returns new poll options

type Poller

type Poller interface {
	// PollImmediate is a wrapper on top of wait.PollImmediate
	// use this function to exercise your condition function with unit tests
	PollImmediate(interval, timeout time.Duration, condition wait.ConditionFunc) error

	// PollImmediateWithGetter is a generic implementation of polling mechanism
	// it will periodically call getterFunc and will return error based on the getterFunc error message if any
	PollImmediateWithGetter(interval, timeout time.Duration, getterFunc GetterFunc) (interface{}, error)

	// PollImmediateInfinite is a wrapper on top of wait.PollImmediateInfinite
	PollImmediateInfinite(interval time.Duration, condition wait.ConditionFunc) error

	// PollImmediateInfiniteWithGetter is a generic implementation of polling mechanism
	// it will periodically call getterFunc and will return error based on the getterFunc error message if any
	PollImmediateInfiniteWithGetter(interval time.Duration, getterFunc GetterFunc) error
}

Poller implements polling helper functions

func NewPoller

func NewPoller() Poller

NewPoller returns new poller

type PostVerifyListrFunc

type PostVerifyListrFunc func(obj crtclient.ObjectList) error

PostVerifyListrFunc is a function which should be used as closure

type PostVerifyrFunc

type PostVerifyrFunc func(obj crtclient.Object) error

PostVerifyrFunc is a function which should be used as closure

type VerificationClientFactory

type VerificationClientFactory struct {
	VerifyKubernetesUpgradeFunc func(clusterStatusInfo *ClusterStatusInfo, newK8sVersion string) error
	GetVCClientAndDataCenter    func(clusterName, clusterNamespace, vsphereMachineTemplateObjectName string) (vc.Client, string, error)
}

VerificationClientFactory clusterclient verification factory implements functions regarding verification which can be replaced with fake implementation for unit testing

Jump to

Keyboard shortcuts

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