shared

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2020 License: Apache-2.0 Imports: 19 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 - Annotation DNS subdomain prefix
	KdDomainBase = "kubedirector.bluedata.io"

	// DefaultServiceType - default service type if not specified in
	// the configCR
	DefaultServiceType = "LoadBalancer"
)
View Source
const (
	EventReasonNoEvent = ""
	EventReasonCluster = "Cluster"
	EventReasonRole    = "Role"
	EventReasonMember  = "Member"
	EventReasonConfig  = "Config"
)

Event reason constants for recording events

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

Settings for appCatalog

View Source
const (
	// KubeDirectorFinalizerID is added to KubeDirector objects' finalizers
	// to prevent them from being deleted before we can clean up.
	KubeDirectorFinalizerID = "kubedirector.bluedata.io/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 Client

func Client() k8sClient.Client

Client getter ...

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 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 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 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 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 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 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 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 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.

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