helpers

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2023 License: Apache-2.0 Imports: 44 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FeatureGatesTypeValid             = "ValidFeatureGates"
	FeatureGatesReasonAllValid        = "FeatureGatesAllValid"
	FeatureGatesReasonInvalidExisting = "InvalidFeatureGatesExisting"
)
View Source
const (
	// ClusterManagerDefaultNamespace is the default namespace of clustermanager
	ClusterManagerDefaultNamespace = "open-cluster-management-hub"
	// KlusterletDefaultNamespace is the default namespace of klusterlet
	KlusterletDefaultNamespace = "open-cluster-management-agent"
	// BootstrapHubKubeConfig is the secret name of bootstrap kubeconfig secret to connect to hub
	BootstrapHubKubeConfig = "bootstrap-hub-kubeconfig"
	// HubKubeConfig is the secret name of kubeconfig secret to connect to hub with mtls
	HubKubeConfig = "hub-kubeconfig-secret"
	// ExternalHubKubeConfig is the secret name of kubeconfig secret to connecting to the hub cluster.
	ExternalHubKubeConfig = "external-hub-kubeconfig"
	// ExternalManagedKubeConfig is the secret name of kubeconfig secret to connecting to the managed cluster
	// Only applicable to Hosted mode, klusterlet-operator uses it to install resources on the managed cluster.
	ExternalManagedKubeConfig = "external-managed-kubeconfig"
	// ExternalManagedKubeConfigRegistration is the secret name of kubeconfig secret to connecting to the managed cluster
	// Only applicable to Hosted mode, registration-agent uses it to connect to the managed cluster.
	ExternalManagedKubeConfigRegistration = "external-managed-kubeconfig-registration"
	// ExternalManagedKubeConfigWork is the secret name of kubeconfig secret to connecting to the managed cluster
	// Only applicable to Hosted mode, work-agent uses it to connect to the managed cluster.
	ExternalManagedKubeConfigWork = "external-managed-kubeconfig-work"

	RegistrationWebhookSecret  = "registration-webhook-serving-cert"
	RegistrationWebhookService = "cluster-manager-registration-webhook"
	WorkWebhookSecret          = "work-webhook-serving-cert" // #nosec G101
	WorkWebhookService         = "cluster-manager-work-webhook"

	SignerSecret      = "signer-secret"
	CaBundleConfigmap = "ca-bundle-configmap"
)

Variables

View Source
var (
	DefaultHubRegistrationFeatureGates = []operatorapiv1.FeatureGate{
		{Feature: "DefaultClusterSet", Mode: operatorapiv1.FeatureGateModeTypeEnable},
	}
	DefaultSpokeRegistrationFeatureGates = []operatorapiv1.FeatureGate{
		{Feature: "AddonManagement", Mode: operatorapiv1.FeatureGateModeTypeEnable},
	}
)

Functions

func AgentNamespace

func AgentNamespace(klusterlet *operatorapiv1.Klusterlet) string

AgentNamespace returns the namespace to deploy the agents. It is on the managed cluster in the Default mode, and on the management cluster in the Hosted mode.

func ApplyDirectly

func ApplyDirectly(
	ctx context.Context,
	client kubernetes.Interface,
	apiExtensionClient apiextensionsclient.Interface,
	recorder events.Recorder,
	cache resourceapply.ResourceCache,
	manifests resourceapply.AssetFunc,
	files ...string) []resourceapply.ApplyResult

func ApplyEndpoints

func ApplyEndpoints(ctx context.Context, client coreclientv1.EndpointsGetter, required *corev1.Endpoints) (*corev1.Endpoints, bool, error)

func BuildFeatureCondition

func BuildFeatureCondition(invalidMsgs ...string) metav1.Condition

func CleanUpStaticObject

func CleanUpStaticObject(
	ctx context.Context,
	client kubernetes.Interface,
	apiExtensionClient apiextensionsclient.Interface,
	apiRegistrationClient apiregistrationclient.APIServicesGetter,
	manifests resourceapply.AssetFunc,
	file string) error

func ClusterManagerConfigmapQueueKeyFunc

func ClusterManagerConfigmapQueueKeyFunc(clusterManagerLister operatorlister.ClusterManagerLister) factory.ObjectQueueKeyFunc

func ClusterManagerDeploymentQueueKeyFunc

func ClusterManagerDeploymentQueueKeyFunc(clusterManagerLister operatorlister.ClusterManagerLister) factory.ObjectQueueKeyFunc

func ClusterManagerNamespace

func ClusterManagerNamespace(clustermanagername string, mode operatorapiv1.InstallMode) string

func ClusterManagerQueueKeyFunc

func ClusterManagerQueueKeyFunc(clusterManagerLister operatorlister.ClusterManagerLister) factory.ObjectQueueKeyFunc

func ConvertToFeatureGateFlags

func ConvertToFeatureGateFlags(component string, features []operatorapiv1.FeatureGate,
	defaultFeatureGates map[featuregate.Feature]featuregate.FeatureSpec) ([]string, string)

func DetermineReplica

func DetermineReplica(ctx context.Context, kubeClient kubernetes.Interface, mode operatorapiv1.InstallMode, kubeVersion *version.Version) int32

DetermineReplica determines the replica of deployment based on: - mode: if it is Hosted mode will return 1 - kube version: if the kube version is less than v1.14 reutn 1 - node: list master nodes in the cluster and return 1 if the number of master nodes is equal or less than 1. Return 3 otherwise.

func DetermineReplicaByNodes

func DetermineReplicaByNodes(ctx context.Context, kubeClient kubernetes.Interface) int32

DetermineReplicaByNodes determines the replica of deployment based on: list master nodes in the cluster and return 1 if the number of master nodes is equal or less than 1. Return 3 otherwise.

func FeatureGateEnabled

func FeatureGateEnabled(features []operatorapiv1.FeatureGate,
	defaultFeatures map[featuregate.Feature]featuregate.FeatureSpec, featureName featuregate.Feature) bool

FeatureGateEnabled checks if a feature is enabled or disabled in operator API, or fallback to use the the default setting

func FindClusterManagerByNamespace

func FindClusterManagerByNamespace(namespace string, clusterManagers []*operatorapiv1.ClusterManager) (*operatorapiv1.ClusterManager, error)

func FindGenerationStatus

func FindGenerationStatus(generationStatuses []operatorapiv1.GenerationStatus, generation operatorapiv1.GenerationStatus) *operatorapiv1.GenerationStatus

func FindKlusterletByNamespace

func FindKlusterletByNamespace(klusterlets []*operatorapiv1.Klusterlet, namespace string) *operatorapiv1.Klusterlet

func FindRelatedResourcesStatus

func FindRelatedResourcesStatus(
	relatedResourcesStatuses []operatorapiv1.RelatedResourceMeta,
	relatedResource operatorapiv1.RelatedResourceMeta) *operatorapiv1.RelatedResourceMeta

func GenerateRelatedResource

func GenerateRelatedResource(objBytes []byte) (operatorapiv1.RelatedResourceMeta, error)

func GetHubKubeconfig

func GetHubKubeconfig(ctx context.Context,
	operatorKubeconfig *rest.Config,
	operatorClient kubernetes.Interface,
	clustermamagerName string,
	clustermanagerMode operatorapiv1.InstallMode) (*rest.Config, error)

GetHubKubeconfig is used to get the kubeconfig of the hub cluster. If it's Default mode, the kubeconfig of the hub cluster should equal to the operator cluster's kubeconfig and mostly, it's the InClusterConfig. If it's Hosted mode, the kubeconfig of the hub cluster is stored as a secret under clustermanager namespace.

func KlusterletDeploymentQueueKeyFunc

func KlusterletDeploymentQueueKeyFunc(klusterletLister operatorlister.KlusterletLister) factory.ObjectQueueKeyFunc

func KlusterletNamespace

func KlusterletNamespace(klusterlet *operatorapiv1.Klusterlet) string

KlusterletNamespace returns the klusterlet namespace on the managed cluster.

func KlusterletSecretQueueKeyFunc

func KlusterletSecretQueueKeyFunc(klusterletLister operatorlister.KlusterletLister) factory.ObjectQueueKeyFunc

func LoadClientConfigFromSecret

func LoadClientConfigFromSecret(secret *corev1.Secret) (*rest.Config, error)

LoadClientConfigFromSecret returns a client config loaded from the given secret

func NumOfUnavailablePod

func NumOfUnavailablePod(deployment *appsv1.Deployment) int32

NumOfUnavailablePod is to check if a deployment is in degraded state.

func RemoveRelatedResourcesStatus

func RemoveRelatedResourcesStatus(
	relatedResourcesStatuses *[]operatorapiv1.RelatedResourceMeta,
	relatedResource operatorapiv1.RelatedResourceMeta)

func RemoveRelatedResourcesStatuses

func RemoveRelatedResourcesStatuses(
	relatedResourcesStatuses *[]operatorapiv1.RelatedResourceMeta,
	rmRelatedResourcesStatus operatorapiv1.RelatedResourceMeta)

func RemoveRelatedResourcesStatusesWithObj

func RemoveRelatedResourcesStatusesWithObj(
	relatedResourcesStatuses *[]operatorapiv1.RelatedResourceMeta, objData []byte)

func SetGenerationStatuses

func SetGenerationStatuses(generationStatuses *[]operatorapiv1.GenerationStatus, newGenerationStatus operatorapiv1.GenerationStatus)

func SetRelatedResourcesStatuses

func SetRelatedResourcesStatuses(
	relatedResourcesStatuses *[]operatorapiv1.RelatedResourceMeta,
	newRelatedResourcesStatus operatorapiv1.RelatedResourceMeta)

func SetRelatedResourcesStatusesWithObj

func SetRelatedResourcesStatusesWithObj(
	relatedResourcesStatuses *[]operatorapiv1.RelatedResourceMeta, objData []byte)

func SyncKubeConfigSecret

func SyncKubeConfigSecret(ctx context.Context, secretName, secretNamespace, kubeconfigPath string,
	templateKubeconfig *rest.Config, secretClient coreclientv1.SecretsGetter,
	tokenGetter TokenGetterFunc, recorder events.Recorder) error

func SyncSecret

func SyncSecret(ctx context.Context, client, targetClient coreclientv1.SecretsGetter, recorder events.Recorder,
	sourceNamespace, sourceName, targetNamespace, targetName string, ownerRefs []metav1.OwnerReference) (*corev1.Secret, bool, error)

SyncSecret forked from: https://github.com/openshift/library-go/blob/d9cdfbd844ea08465b938c46a16bed2ea23207e4/pkg/operator/resource/resourceapply/core.go#L357, add an addition targetClient parameter to support sync secret to another cluster.

Types

type RequeueError

type RequeueError struct {
	RequeueTime time.Duration
	Message     string
}

func NewRequeueError

func NewRequeueError(msg string, requeueTime time.Duration) *RequeueError

func (*RequeueError) Error

func (r *RequeueError) Error() string

type TokenGetterFunc

type TokenGetterFunc func() ([]byte, []byte, error)

func SATokenCreater

func SATokenCreater(ctx context.Context, saName, saNamespace string, saClient kubernetes.Interface) TokenGetterFunc

SATokenCreater create the saToken of target sa.

func SATokenGetter

func SATokenGetter(ctx context.Context, saName, saNamespace string, saClient kubernetes.Interface) TokenGetterFunc

SATokenGetter get the saToken of target sa. If there is not secrets in the sa, use the tokenrequest to get a token.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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