helpers

package
v0.0.0-...-890bf4a Latest Latest
Warning

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

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

Documentation

Overview

TODO add unit test for the following functions, right now they are only covered in e2e

Index

Constants

This section is empty.

Variables

View Source
var DeployOnOCP bool = true

DeployOnOCP is set once at the beginning

Functions

func AddManagedClusterFinalizer

func AddManagedClusterFinalizer(modified *bool, managedCluster *clusterv1.ManagedCluster, finalizer string)

AddManagedClusterFinalizer add a finalizer to a managed cluster

func ApplyCustomResourceDefinitionV1Beta1

In order to support ocp 311, copy this func from old library-go

func ApplyResources

func ApplyResources(clientHolder *ClientHolder, recorder events.Recorder,
	scheme *runtime.Scheme, owner metav1.Object, objs ...runtime.Object) (bool, error)

ApplyResources apply resources, includes: serviceaccount, secret, deployment, clusterrole, clusterrolebinding, crdv1beta1, crdv1, manifestwork and klusterlet

func AssertManifestWorkFinalizer

func AssertManifestWorkFinalizer(ctx context.Context, runtimeClient client.Client, recorder events.Recorder,
	cluster *clusterv1.ManagedCluster, works int) error

AssertManifestWorkFinalizer add/remove manifest finalizer for a managed cluster, this func will send request to api server to update managed cluster.

func ContainAuthError

func ContainAuthError(err error) bool

func ContainInternalServerError

func ContainInternalServerError(err error) bool

func DeleteAutoImportSecret

func DeleteAutoImportSecret(ctx context.Context, kubeClient kubernetes.Interface,
	secret *corev1.Secret, recorder events.Recorder) error

DeleteAutoImportSecret delete the auto-import-secret if the secret does not have the keeping annotation

func DeleteManagedClusterAddons

func DeleteManagedClusterAddons(
	ctx context.Context,
	runtimeClient client.Client,
	recorder events.Recorder,
	cluster *clusterv1.ManagedCluster) error

DeleteManagedClusterAddons deletes all managedclusteraddons for the managed cluster

func DeleteManifestWork

func DeleteManifestWork(ctx context.Context, workClient workclient.Interface, recorder events.Recorder,
	namespace, name string) error

DeleteManifestWork triggers the deletion action of the manifestwork

func DeleteManifestWorkWithSelector

func DeleteManifestWorkWithSelector(ctx context.Context, workClient workclient.Interface, recorder events.Recorder,
	cluster *clusterv1.ManagedCluster, works []workv1.ManifestWork,
	ignoredSelector func(clusterName string, manifestWork workv1.ManifestWork) bool) error

DeleteManifestWorkWithSelector deletes manifestworks but ignores the ignoredSelector selected manifestworks

func DetermineKlusterletMode

func DetermineKlusterletMode(cluster *clusterv1.ManagedCluster) operatorv1.InstallMode

DetermineKlusterletMode gets the klusterlet deploy mode for the managed cluster.

func ForceDeleteAllManagedClusterAddons

func ForceDeleteAllManagedClusterAddons(
	ctx context.Context,
	runtimeClient client.Client,
	recorder events.Recorder,
	clusterName string) error

ForceDeleteAllManagedClusterAddons delete all managed cluster addons forcefully

func ForceDeleteAllManifestWorks

func ForceDeleteAllManifestWorks(ctx context.Context, workClient workclient.Interface, recorder events.Recorder,
	manifestWorks []workv1.ManifestWork) error

ForceDeleteAllManifestWorks delete all manifestworks forcefully

func ForceDeleteManagedClusterAddon

func ForceDeleteManagedClusterAddon(
	ctx context.Context,
	runtimeClient client.Client,
	recorder events.Recorder,
	addonNamespace, addonName string) error

ForceDeleteManagedClusterAddon will delete the managedClusterAddon regardless of finalizers.

func ForceDeleteManifestWork

func ForceDeleteManifestWork(ctx context.Context, workClient workclient.Interface, recorder events.Recorder,
	namespace, name string) error

ForceDeleteManifestWork will delete the manifestwork regardless of finalizers.

func GetComponentNamespace

func GetComponentNamespace() (string, error)

func GetHostingCluster

func GetHostingCluster(cluster *clusterv1.ManagedCluster) (string, error)

GetHostingCluster gets the hosting cluster name from the managed cluster annotation

func GetMaxConcurrentReconciles

func GetMaxConcurrentReconciles() int

GetMaxConcurrentReconciles get the max concurrent reconciles from MAX_CONCURRENT_RECONCILES env, if the reconciles cannot be found, return 1

func GetMergedKlusterletConfigWithGlobal

func GetMergedKlusterletConfigWithGlobal(
	klusterletconfigName string,
	kcLister listerklusterletconfigv1alpha1.KlusterletConfigLister,
) (*klusterletconfigv1alpha1.KlusterletConfig, error)

func GetNodeSelectorFromManagedClusterAnnotations

func GetNodeSelectorFromManagedClusterAnnotations(clusterAnnotations map[string]string) (map[string]string, error)

func GetTolerationsFromManagedClusterAnnotations

func GetTolerationsFromManagedClusterAnnotations(clusterAnnotations map[string]string) ([]corev1.Toleration, error)

func ImportManagedClusterFromSecret

func ImportManagedClusterFromSecret(client *ClientHolder, restMapper meta.RESTMapper, recorder events.Recorder,
	importSecret *corev1.Secret) (bool, error)

ImportManagedClusterFromSecret use managed cluster client to import managed cluster from import-secret

func ImportingResourcesApplied

func ImportingResourcesApplied(condition *metav1.Condition) bool

func IsAPIExtensionV1Supported

func IsAPIExtensionV1Supported(kubeVersion string) bool

IsAPIExtensionV1Supported if the cluster can support the crdv1, return true

func IsClusterUnavailable

func IsClusterUnavailable(cluster *clusterv1.ManagedCluster) bool

IsClusterUnavailable checks whether the cluster is unavilable

func IsKubeVersionChanged

func IsKubeVersionChanged(objectOld, objectNew runtime.Object) bool

func IsManifestWorksAvailable

func IsManifestWorksAvailable(ctx context.Context, client workclient.Interface,
	namespace string, names ...string) (bool, error)

func ListManagedClusterAddons

func ListManagedClusterAddons(ctx context.Context, runtimeClient client.Client, clusterName string) (
	*addonv1alpha1.ManagedClusterAddOnList, error)

ListManagedClusterAddons lists all managedclusteraddons for the managed cluster

func ManifestsEqual

func ManifestsEqual(newManifests, oldManifests []workv1.Manifest) bool

ManifestsEqual if two manifests are equal, return true

func MustCreateAssetFromTemplate

func MustCreateAssetFromTemplate(name string, tb []byte, config interface{}) []byte

MustCreateAssetFromTemplate render a template with its configuration If it's failed, this function will panic

func MustCreateObject

func MustCreateObject(raw []byte) runtime.Object

MustCreateObject translate object from raw bytes to runtime object

func MustCreateObjectFromTemplate

func MustCreateObjectFromTemplate(file string, template []byte, config interface{}) runtime.Object

MustCreateObjectFromTemplate render a template to a runtime object with its configuration If it's failed, this function will panic

func NewEventRecorder

func NewEventRecorder(kubeClient kubernetes.Interface, controllerName string) events.Recorder

func NewManagedClusterImportSucceededCondition

func NewManagedClusterImportSucceededCondition(s metav1.ConditionStatus, reason, message string) metav1.Condition

func NoManagedClusterAddons

func NoManagedClusterAddons(ctx context.Context, runtimeClient client.Client, clusterName string) (bool, error)

NoManagedClusterAddons checks whether there are managedclusteraddons for the managed cluster

func NoPendingManifestWorks

func NoPendingManifestWorks(ctx context.Context, log logr.Logger,
	clusterName string, manifestWorks []workv1.ManifestWork,
	ignoredSelector WorkSelector) (bool, error)

NoPendingManifestWorks checks whether there are pending manifestworks for the managed cluster

func RemoveManagedClusterFinalizer

func RemoveManagedClusterFinalizer(ctx context.Context, runtimeClient client.Client, recorder events.Recorder,
	managedCluster *clusterv1.ManagedCluster, finalizer string) error

RemoveManagedClusterFinalizer remove a finalizer from a managed cluster

func ResourceIsNotFound

func ResourceIsNotFound(err error) bool

func SplitYamls

func SplitYamls(yamls []byte) [][]byte

SplitYamls split yamls with sperator `---`

func SupportPriorityClass

func SupportPriorityClass(cluster *clusterv1.ManagedCluster) (bool, error)

func UpdateManagedClusterBootstrapSecret

func UpdateManagedClusterBootstrapSecret(client *ClientHolder, importSecret *corev1.Secret,
	recorder events.Recorder) (bool, error)

UpdateManagedClusterBootstrapSecret update the bootstrap secret on the managed cluster

func UpdateManagedClusterStatus

func UpdateManagedClusterStatus(client client.Client, managedClusterName string, cond metav1.Condition) error

UpdateManagedClusterStatus update managed cluster status

func ValidateHostedImportSecret

func ValidateHostedImportSecret(importSecret *corev1.Secret) error

ValidateHostedImportSecret validate hosted mode managed cluster import secret

func ValidateImportSecret

func ValidateImportSecret(importSecret *corev1.Secret) error

ValidateImportSecret validate managed cluster import secret

func ValidateKlusterletMode

func ValidateKlusterletMode(mode operatorv1.InstallMode) error

Types

type ApplyResourcesFunc

type ApplyResourcesFunc func(backupRestore bool, client *ClientHolder, restMapper meta.RESTMapper,
	recorder events.Recorder, importSecret *corev1.Secret) (bool, error)

ApplyResourcesFunc is a function to apply resources to the manged cluster to import it to the hub

type ClientHolder

type ClientHolder struct {
	KubeClient          kubernetes.Interface
	APIExtensionsClient apiextensionsclient.Interface
	OperatorClient      operatorclient.Interface
	RuntimeClient       client.Client
	ImageRegistryClient imageregistry.Interface
	WorkClient          workclient.Interface
}

func GenerateImportClientFromKubeConfigSecret

func GenerateImportClientFromKubeConfigSecret(secret *corev1.Secret) (reconcile.Result, *ClientHolder, meta.RESTMapper, error)

GenerateImportClientFromKubeConfigSecret generate a client from a given secret that contains a kubeconfig

func GenerateImportClientFromKubeTokenSecret

func GenerateImportClientFromKubeTokenSecret(secret *corev1.Secret) (reconcile.Result, *ClientHolder, meta.RESTMapper, error)

GenerateImportClientFromKubeTokenSecret generate a client from a given secret that contains kube apiserver and token

func GenerateImportClientFromRosaCluster

func GenerateImportClientFromRosaCluster(getter *RosaKubeConfigGetter, secret *corev1.Secret) (reconcile.Result, *ClientHolder, meta.RESTMapper, error)

GenerateImportClientFromRosaCluster generate a client from a given secret that contains rosa cluster info

type GenerateClientHolderFunc

type GenerateClientHolderFunc func(secret *corev1.Secret) (reconcile.Result, *ClientHolder, meta.RESTMapper, error)

GenerateClientHolderFunc is a function to generate the managed cluster client holder which is used to import cluster(apply resources to the managed cluster)

type ImportHelper

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

ImportHelper is used to helper controller to import managed cluster

func NewImportHelper

func NewImportHelper(informerHolder *source.InformerHolder,
	recorder events.Recorder, log logr.Logger) *ImportHelper

func (*ImportHelper) Import

func (i *ImportHelper) Import(backupRestore bool, clusterName string,
	managedClusterKubeClientSecret *corev1.Secret, lastRetry, totalRetry int) (
	reconcile.Result, metav1.Condition, bool, int, error)

Import uses the managedClusterKubeClientSecret to generate a managed cluster client, then use this client to import the managed cluster, return condition when finished apply

func (*ImportHelper) WithApplyResourcesFunc

func (i *ImportHelper) WithApplyResourcesFunc(f ApplyResourcesFunc) *ImportHelper

func (*ImportHelper) WithGenerateClientHolderFunc

func (i *ImportHelper) WithGenerateClientHolderFunc(f GenerateClientHolderFunc) *ImportHelper

type RosaKubeConfigGetter

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

func NewRosaKubeConfigGetter

func NewRosaKubeConfigGetter() *RosaKubeConfigGetter

func (*RosaKubeConfigGetter) Cleanup

func (g *RosaKubeConfigGetter) Cleanup() error

func (*RosaKubeConfigGetter) KubeConfig

func (g *RosaKubeConfigGetter) KubeConfig() (bool, *clientcmdapi.Config, error)

func (*RosaKubeConfigGetter) SetAPIServerURL

func (g *RosaKubeConfigGetter) SetAPIServerURL(apiServer string)

func (*RosaKubeConfigGetter) SetClusterID

func (g *RosaKubeConfigGetter) SetClusterID(clusterID string)

func (*RosaKubeConfigGetter) SetRetryTimes

func (g *RosaKubeConfigGetter) SetRetryTimes(retryTimes string)

func (*RosaKubeConfigGetter) SetToken

func (g *RosaKubeConfigGetter) SetToken(token string)

func (*RosaKubeConfigGetter) SetTokenURL

func (g *RosaKubeConfigGetter) SetTokenURL(tokenURL string)

type WorkSelector

type WorkSelector func(string, workv1.ManifestWork) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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