shared

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2022 License: Apache-2.0 Imports: 24 Imported by: 5

Documentation

Overview

Package shared implements utility routines, data structures, and constants used by multiple other KubeDirector packages.

Index

Constants

View Source
const (
	// DefaultSvcDomainBase contains the initial segments used to build FQDNs
	// for cluster members
	DefaultSvcDomainBase = ".svc.cluster.local"

	// KubeDirectorNamespaceEnvVar is the constant for env variable MY_NAMESPACE
	// which is the namespace of the kubedirector pod.
	KubeDirectorNamespaceEnvVar = "MY_NAMESPACE"

	// KubeDirectorGlobalConfig is the name of the kubedirector config CR
	KubeDirectorGlobalConfig = "kd-global-config"

	// KdDomainBase is the prefix for label and annotation keys.
	KdDomainBase = "kubedirector.hpe.com"

	// ClusterLabel is a label placed on every created statefulset, pod, and
	// service, with a value of the KubeDirectorCluster CR name.
	ClusterLabel = KdDomainBase + "/kdcluster"

	// RestoringLabel is the label placed on a kdcluster while it and objects
	// it depends on are being restored from a backup.
	RestoringLabel = KdDomainBase + "/restoring"

	// StatusBackupAnnotation is the annotation placed on a kdcluster when
	// writing status, to indicate whether or not a status backup exists.
	StatusBackupAnnotation = KdDomainBase + "/status-backup-exists"

	// DefaultServiceType - default service type if not specified in
	// the configCR
	DefaultServiceType = "LoadBalancer"

	// DefaultNamingScheme - default naming scheme if not specified in
	// the configCR
	DefaultNamingScheme = "UID"

	// ConfigCliLoc is the root directory for installing configcli scripts
	// and python modules within the member container, if the role asks for
	// the new setup layout.
	ConfigCliLoc = "/usr/local"

	// ConfigCliLegacyLoc is the root directory for installing configcli scripts
	// and python modules within the member container, if the role uses the
	// old setup layout.
	ConfigCliLegacyLoc = "/usr"
)
View Source
const (
	EventReasonNoEvent   = ""
	EventReasonCluster   = "Cluster"
	EventReasonRole      = "Role"
	EventReasonMember    = "Member"
	EventReasonConfig    = "Config"
	EventReasonConfigMap = "ConfigMap"
	EventReasonSecret    = "Secret"
)

Event reason constants for recording events

View Source
const (
	AppCatalogLocal  = "local"
	AppCatalogSystem = "system"
)

Settings for appCatalog

View Source
const (
	ConnectionsIncrementor = KdDomainBase + "/connUpdateCounter"
)

Used by configmap, secret and cluster reconciler to update connection changes

View Source
const (
	HashChangeIncrementor = KdDomainBase + "/hashChangeCounter"
)

Used as a counter for number of times the hash of connections changes, which is an indicator of the number of times the connections change

View Source
const (
	// KubeDirectorFinalizerID is added to KubeDirector objects' finalizers
	// to prevent them from being deleted before we can clean up.
	KubeDirectorFinalizerID = "kubedirector.hpe.com/cleanup"
)

Variables

This section is empty.

Functions

func AddGlobalConfig added in v0.3.0

func AddGlobalConfig(config *kdv1.KubeDirectorConfig)

AddGlobalConfig adds the globalConfig CR data

func AnyClusters added in v0.7.0

func AnyClusters() bool

AnyClusters returns true if any clusters have been registered.

func ClientSet added in v0.3.0

func ClientSet() kubernetes.Interface

ClientSet getter ...

func ClustersUsingApp added in v0.3.0

func ClustersUsingApp(
	appNamespace string,
	appID string,
) []string

ClustersUsingApp returns the list of clusters referencing the given app.

func Config added in v0.3.0

func Config() *rest.Config

Config getter ...

func Create added in v0.4.0

func Create(
	ctx context.Context,
	obj runtime.Object,
) error

Create uses the split client. Should write back directly to K8s, but we'll use the split client in case it ever wants to use the knowledge that we are changing the object.

func Delete added in v0.4.0

func Delete(
	ctx context.Context,
	obj runtime.Object,
	opts ...k8sClient.DeleteOption,
) error

Delete uses the split client. Should write back directly to K8s, but we'll use the split client in case it ever wants to use the knowledge that we are deleting the object.

func EnsureClusterAppReference added in v0.3.0

func EnsureClusterAppReference(
	clusterNamespace string,
	clusterName string,
	appCatalog string,
	appID string,
)

EnsureClusterAppReference notes that an app type is in use by this cluster. The cluster namespace and name are stored in a map indexed by the app CR's namespace+name. Note that we only expect this to be called once per cluster in the current design, but we will still protect against storing duplicates.

func EnsureFinalizer added in v0.3.0

func EnsureFinalizer(
	cr KubeDirectorObject,
)

EnsureFinalizer adds the KubeDirector finalizer into the CR's finalizers list (if it is not in there).

func Get added in v0.4.0

func Get(
	ctx context.Context,
	key types.NamespacedName,
	obj runtime.Object,
) error

Get will first try a GET through the split client. If this returns 404, it will try the direct client. Cf. https://github.com/bluek8s/kubedirector/issues/267

func GetAllowRestoreWithoutConnections added in v0.7.0

func GetAllowRestoreWithoutConnections() bool

GetAllowRestoreWithoutConnections extracts the flag definition from the globalConfig CR data if present, otherwise returns false.

func GetBackupClusterStatus added in v0.7.0

func GetBackupClusterStatus() bool

GetBackupClusterStatus extracts the flag definition from the globalConfig CR data if present, otherwise returns false.

func GetDefaultNamingScheme added in v0.5.2

func GetDefaultNamingScheme() string

GetDefaultNamingScheme extracts the flag definition from the globalConfig CR data if present, otherwise returns false

func GetDefaultServiceType added in v0.3.0

func GetDefaultServiceType() string

GetDefaultServiceType extracts the default service type from the globalConfig CR data if present, otherwise returns the default value (NodePort).

func GetDefaultStorageClass added in v0.3.0

func GetDefaultStorageClass() string

GetDefaultStorageClass extracts the default storage class from the globalConfig CR data if present, otherwise returns an empty string

func GetKubeDirectorNamespace

func GetKubeDirectorNamespace() (string, error)

GetKubeDirectorNamespace is a utility function to fetch the namespace where kubedirector is running

func GetMasterEncryptionKey added in v0.7.0

func GetMasterEncryptionKey() (string, error)

GetMasterEncryptionKey extracts the master encryption key from the globalConfig CR data if present, otherwise return an error. Note: If config exists the key should be generated by webhook or reconcile

func GetNativeSystemdSupport added in v0.3.0

func GetNativeSystemdSupport() bool

GetNativeSystemdSupport extracts the flag definition from the globalConfig CR data if present, otherwise returns false

func GetPodAnnotations added in v0.7.0

func GetPodAnnotations() map[string]string

GetPodAnnotations returns the pod annotations specified in the config, or nil if no config.

func GetPodLabels added in v0.7.0

func GetPodLabels() map[string]string

GetPodLabels returns the pod labels specified in the config, or nil if no config.

func GetRequiredSecretPrefix added in v0.3.0

func GetRequiredSecretPrefix() string

GetRequiredSecretPrefix returns a string that must prefix-match a secret name in order to allow that secret to be mounted by us. May be emptystring if no match required.

func GetServiceAnnotations added in v0.7.0

func GetServiceAnnotations() map[string]string

GetServiceAnnotations returns the service annotations specified in the config, or nil if no config.

func GetServiceLabels added in v0.7.0

func GetServiceLabels() map[string]string

GetServiceLabels returns the service labels specified in the config, or nil if no config.

func GetSvcClusterDomainBase added in v0.3.1

func GetSvcClusterDomainBase() string

GetSvcClusterDomainBase extracts the default svc cluster domain from the globalConfig CR data if present, otherwise returns the default value (NodePort).

func HasFinalizer added in v0.3.1

func HasFinalizer(
	cr KubeDirectorObject,
) bool

HasFinalizer checks whether the KubeDirector finalizer is among the CR's finalizers list.

func List added in v0.4.0

func List(
	ctx context.Context,
	list runtime.Object,
	opts ...k8sClient.ListOption,
) error

List uses the split client. Currently we don't have usecases where we would need to fall back to the direct client if the list has zero items, and it would be somewhat involved to examine the list object here to determine the zero-items case. We do however want to fall back to the direct client if isNotFoundInCache is true.

func ListIsUnique added in v0.2.0

func ListIsUnique(
	list []string,
) bool

ListIsUnique is a utility function that checks if a given slice of strings is free of duplicates.

func LogError

func LogError(
	logger logr.Logger,
	err error,
	obj runtime.Object,
	eventReason string,
	msg string,
)

LogError logs the given message at Error level.

func LogErrorf

func LogErrorf(
	logger logr.Logger,
	err error,
	obj runtime.Object,
	eventReason string,
	format string,
	args ...interface{},
)

LogErrorf logs the given message format and payload at Error level.

func LogEvent added in v0.2.0

func LogEvent(
	obj runtime.Object,
	eventType string,
	eventReason string,
	msg string,
)

LogEvent posts an event to event recorder with the given msg using the CR object as reference

func LogEventf added in v0.2.0

func LogEventf(
	obj runtime.Object,
	eventType string,
	eventReason string,
	format string,
	args ...interface{},
)

LogEventf posts an event to event recorder with the given message format and payload using the CR object as reference

func LogInfo

func LogInfo(
	logger logr.Logger,
	obj runtime.Object,
	eventReason string,
	msg string,
)

LogInfo logs the given message at Info level.

func LogInfof

func LogInfof(
	logger logr.Logger,
	obj runtime.Object,
	eventReason string,
	format string,
	args ...interface{},
)

LogInfof logs the given message format and payload at Info level.

func OwnerReferences added in v0.7.0

func OwnerReferences(
	cr KubeDirectorObject,
) []metav1.OwnerReference

OwnerReferences creates an owner reference spec that identifies the custom resource as the owner.

func OwnerReferencesPresent added in v0.7.0

func OwnerReferencesPresent(
	cr KubeDirectorObject,
	currentRefs []metav1.OwnerReference,
) bool

OwnerReferencesPresent determines whether the desired references (from the ownerReferences func) are present in the CR.

func Patch added in v0.7.0

func Patch(
	ctx context.Context,
	originalObj runtime.Object,
	modifiedObj runtime.Object,
) error

Patch uses the split client. Should write back directly to K8s, but we'll use the split client in case it ever wants to use the knowledge that we are changing the object.

func RemoveClusterAppReference added in v0.3.0

func RemoveClusterAppReference(
	clusterNamespace string,
	clusterName string,
	appCatalog string,
	appID string,
)

RemoveClusterAppReference notes that an app type is no longer in use by this cluster. The cluster namespace+name is removed from the list of such references marked against the app's namespace+name. Note that we only expect this to be called when a reference to the cluster does exist; but if for some reason the reference does not exist this call is a NOP.

func RemoveFinalizer added in v0.3.0

func RemoveFinalizer(
	cr KubeDirectorObject,
)

RemoveFinalizer removes the KubeDirector finalizer from the CR's finalizers list (if it is in there).

func RemoveGlobalConfig added in v0.3.0

func RemoveGlobalConfig()

RemoveGlobalConfig removes the current globalConfig

func ServiceType added in v0.3.0

func ServiceType(
	crServicetype string,
) corev1.ServiceType

ServiceType is a utility function that converts serviceType string to Kubedirector-Plus supported service types as a corev1.ServiceType returns corev1.ServiceTypeNodePort if crServicetype is not ClusterIP or LoadBalancer

func SetClient added in v0.3.0

func SetClient(
	c k8sClient.Client,
)

SetClient setter ...

func StatusUpdate added in v0.4.0

func StatusUpdate(
	ctx context.Context,
	obj runtime.Object,
) error

StatusUpdate uses the split client. Should write back directly to K8s, but we'll use the split client in case it ever wants to use the knowledge that we are changing the object.

func StrPtr

func StrPtr(s string) *string

StrPtr convert a string to a pointer

func StringInList

func StringInList(
	test string,
	list []string,
) bool

StringInList is a utility function that checks if a given string is present at least once in the given slice of strings.

func Update added in v0.4.0

func Update(
	ctx context.Context,
	obj runtime.Object,
) error

Update uses the split client. Should write back directly to K8s, but we'll use the split client in case it ever wants to use the knowledge that we are changing the object.

Types

type KubeDirectorObject added in v0.3.0

type KubeDirectorObject interface {
	runtime.Object
	metav1.Object
}

KubeDirectorObject is an interface that most KubeDirector CRs implement. Currently it's used to add/remove the KubeDirector finalizer from KubeDirector resources.

type StatusGen added in v0.3.0

type StatusGen struct {
	UID       string
	Validated bool
}

StatusGen informs whether the enclosed UID has been validated.

type StatusGens added in v0.3.0

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

StatusGens provides thread safe access to a map of StatusGen's.

func NewStatusGens added in v0.3.0

func NewStatusGens() *StatusGens

NewStatusGens is a StatusGens constructor

func (*StatusGens) DeleteStatusGen added in v0.3.0

func (s *StatusGens) DeleteStatusGen(uid types.UID)

DeleteStatusGen provides thread safe delete of a status gen.

func (*StatusGens) ReadStatusGen added in v0.3.0

func (s *StatusGens) ReadStatusGen(uid types.UID) (StatusGen, bool)

ReadStatusGen provides thread safe read of a status gen UID string and validated flag.

func (*StatusGens) StatusGenCount added in v0.3.0

func (s *StatusGens) StatusGenCount() int

StatusGenCount provides thread safe number of current status gens.

func (*StatusGens) ValidateStatusGen added in v0.3.0

func (s *StatusGens) ValidateStatusGen(uid types.UID)

ValidateStatusGen provides thread safe mark-validated of a status gen.

func (*StatusGens) WriteStatusGen added in v0.3.0

func (s *StatusGens) WriteStatusGen(uid types.UID, newGenUID string)

WriteStatusGen provides thread safe write of a status gen UID string. The validated flag will begin as false.

func (*StatusGens) WriteValidatedStatusGen added in v0.3.0

func (s *StatusGens) WriteValidatedStatusGen(uid types.UID, newGenUID string)

WriteValidatedStatusGen does WriteStatusGen + ValidateStatusGen atomically.

Jump to

Keyboard shortcuts

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