Documentation ¶
Overview ¶
Package shared implements utility routines, data structures, and constants used by multiple other KubeDirector packages.
Index ¶
- Constants
- func AddGlobalConfig(config *kdv1.KubeDirectorConfig)
- func AnyClusters() bool
- func ClientSet() kubernetes.Interface
- func ClustersUsingApp(appNamespace string, appID string) []string
- func Config() *rest.Config
- func Create(ctx context.Context, obj runtime.Object) error
- func Delete(ctx context.Context, obj runtime.Object, opts ...k8sClient.DeleteOption) error
- func EnsureClusterAppReference(clusterNamespace string, clusterName string, appCatalog string, appID string)
- func EnsureFinalizer(cr KubeDirectorObject)
- func Get(ctx context.Context, key types.NamespacedName, obj runtime.Object) error
- func GetAllowRestoreWithoutConnections() bool
- func GetBackupClusterStatus() bool
- func GetDefaultNamingScheme() string
- func GetDefaultServiceType() string
- func GetDefaultStorageClass() string
- func GetKubeDirectorNamespace() (string, error)
- func GetMasterEncryptionKey() (string, error)
- func GetNativeSystemdSupport() bool
- func GetPodAnnotations() map[string]string
- func GetPodLabels() map[string]string
- func GetRequiredSecretPrefix() string
- func GetServiceAnnotations() map[string]string
- func GetServiceLabels() map[string]string
- func GetSvcClusterDomainBase() string
- func HasFinalizer(cr KubeDirectorObject) bool
- func List(ctx context.Context, list runtime.Object, opts ...k8sClient.ListOption) error
- func ListIsUnique(list []string) bool
- func LogError(logger logr.Logger, err error, obj runtime.Object, eventReason string, ...)
- func LogErrorf(logger logr.Logger, err error, obj runtime.Object, eventReason string, ...)
- func LogEvent(obj runtime.Object, eventType string, eventReason string, msg string)
- func LogEventf(obj runtime.Object, eventType string, eventReason string, format string, ...)
- func LogInfo(logger logr.Logger, obj runtime.Object, eventReason string, msg string)
- func LogInfof(logger logr.Logger, obj runtime.Object, eventReason string, format string, ...)
- func OwnerReferences(cr KubeDirectorObject) []metav1.OwnerReference
- func OwnerReferencesPresent(cr KubeDirectorObject, currentRefs []metav1.OwnerReference) bool
- func Patch(ctx context.Context, originalObj runtime.Object, modifiedObj runtime.Object) error
- func RemoveClusterAppReference(clusterNamespace string, clusterName string, appCatalog string, appID string)
- func RemoveFinalizer(cr KubeDirectorObject)
- func RemoveGlobalConfig()
- func ServiceType(crServicetype string) corev1.ServiceType
- func SetClient(c k8sClient.Client)
- func StatusUpdate(ctx context.Context, obj runtime.Object) error
- func StrPtr(s string) *string
- func StringInList(test string, list []string) bool
- func Update(ctx context.Context, obj runtime.Object) error
- type KubeDirectorObject
- type StatusGen
- type StatusGens
- func (s *StatusGens) DeleteStatusGen(uid types.UID)
- func (s *StatusGens) ReadStatusGen(uid types.UID) (StatusGen, bool)
- func (s *StatusGens) StatusGenCount() int
- func (s *StatusGens) ValidateStatusGen(uid types.UID)
- func (s *StatusGens) WriteStatusGen(uid types.UID, newGenUID string)
- func (s *StatusGens) WriteValidatedStatusGen(uid types.UID, newGenUID string)
Constants ¶
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" )
const ( EventReasonNoEvent = "" EventReasonCluster = "Cluster" EventReasonRole = "Role" EventReasonMember = "Member" EventReasonConfig = "Config" EventReasonConfigMap = "ConfigMap" EventReasonSecret = "Secret" )
Event reason constants for recording events
const ( AppCatalogLocal = "local" AppCatalogSystem = "system" )
Settings for appCatalog
const (
ConnectionsIncrementor = KdDomainBase + "/connUpdateCounter"
)
Used by configmap, secret and cluster reconciler to update connection changes
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
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 ClustersUsingApp ¶ added in v0.3.0
ClustersUsingApp returns the list of clusters referencing the given app.
func Create ¶ added in v0.4.0
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
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
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 ¶
GetKubeDirectorNamespace is a utility function to fetch the namespace where kubedirector is running
func GetMasterEncryptionKey ¶ added in v0.7.0
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
GetPodAnnotations returns the pod annotations specified in the config, or nil if no config.
func GetPodLabels ¶ added in v0.7.0
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
GetServiceAnnotations returns the service annotations specified in the config, or nil if no config.
func GetServiceLabels ¶ added in v0.7.0
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
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
ListIsUnique is a utility function that checks if a given slice of strings is free of duplicates.
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
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 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
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 StatusUpdate ¶ added in v0.4.0
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 StringInList ¶
StringInList is a utility function that checks if a given string is present at least once in the given slice of strings.
Types ¶
type KubeDirectorObject ¶ added in v0.3.0
KubeDirectorObject is an interface that most KubeDirector CRs implement. Currently it's used to add/remove the KubeDirector finalizer from KubeDirector resources.
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.