common

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2025 License: Apache-2.0 Imports: 52 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// OwnerLabel -
	OwnerLabel = "osp-director"
	// GroupLabel -
	GroupLabel = OwnerLabel + ".openstack.org"
	// OwnerUIDLabelSelector -
	OwnerUIDLabelSelector = GroupLabel + "/uid"
	// OwnerNameSpaceLabelSelector -
	OwnerNameSpaceLabelSelector = GroupLabel + "/namespace"
	// OwnerNameLabelSelector -
	OwnerNameLabelSelector = GroupLabel + "/name"
	// OwnerControllerNameLabelSelector -
	OwnerControllerNameLabelSelector = GroupLabel + "/controller"

	// OSPHostnameLabelSelector - Tripleo Hostname
	OSPHostnameLabelSelector = GroupLabel + "/osphostname"

	// MustGatherSecret - Label placed on secrets that are safe to collect with must-gater
	MustGatherSecret = GroupLabel + "/must-gather-secret"

	// FinalizerName -
	FinalizerName = GroupLabel

	// ServiceAccountAnnotationName -
	ServiceAccountAnnotationName = "kubernetes.io/service-account.name"

	// TripleOServicesDefaultKeyName -
	TripleOServicesDefaultKeyName = "ServicesDefault"

	// TripleOPacemakerServiceName -
	TripleOPacemakerServiceName = "OS::TripleO::Services::Pacemaker"

	// TripleORolesDataFile -
	TripleORolesDataFile = "roles_data.yaml"

	// CustomServiceConfigFileName - file name used to add the service customizations
	CustomServiceConfigFileName = "custom.conf"
)
View Source
const (
	// BITSIZE -
	BITSIZE int = 4096
)
View Source
const (

	// PasswordMaxDepth , max depth of nested maps inside the pwd hirarchy.
	// Used when recursive converting existing password secret data from
	// map[interface{}]interface{} into nested maps of type map[string]interface{}.
	PasswordMaxDepth = 32
)

Variables

This section is empty.

Functions

func AssignIP

func AssignIP(assignIPDetails AssignIPDetails) (net.IPNet, []ospdirectorv1beta1.IPReservation, error)

AssignIP assigns an IP using a range and a reserve list.

func BigIntToIP

func BigIntToIP(inipint big.Int) net.IP

BigIntToIP converts a big.Int to a net.IP

func CreateOrGetCustomConfigMap

func CreateOrGetCustomConfigMap(
	ctx context.Context,
	r ReconcilerCommon,
	configMap *corev1.ConfigMap,
) (string, error)

CreateOrGetCustomConfigMap -

func CreateOrGetHostname

func CreateOrGetHostname(
	hostStore HostnameStore,
	host *Hostname,
) error

CreateOrGetHostname -

func CreateOrUpdatePvc

CreateOrUpdatePvc -

func CreateOrUpdateSecret

func CreateOrUpdateSecret(
	ctx context.Context,
	r ReconcilerCommon,
	obj metav1.Object,
	secret *corev1.Secret,
) (string, controllerutil.OperationResult, error)

CreateOrUpdateSecret -

func DeleteJob

func DeleteJob(
	ctx context.Context,
	job *batchv1.Job,
	kclient kubernetes.Interface,
	log logr.Logger,
) (bool, error)

DeleteJob func kclient required to properly cleanup the job depending pods with DeleteOptions

func DeletePodsWithLabel

func DeletePodsWithLabel(
	ctx context.Context,
	r ReconcilerCommon,
	obj metav1.Object,
	labelSelectorMap map[string]string,
) error

DeletePodsWithLabel - Delete all pods in namespace of the obj matching label selector

func DeleteReplicasetsWithLabel

func DeleteReplicasetsWithLabel(
	ctx context.Context,
	r ReconcilerCommon,
	obj metav1.Object,
	labelSelectorMap map[string]string,
) error

DeleteReplicasetsWithLabel - Delete all replicasets in namespace of the obj matching label selector

func DeleteSecretsWithLabel

func DeleteSecretsWithLabel(
	ctx context.Context,
	r ReconcilerCommon,
	obj metav1.Object,
	labelSelectorMap map[string]string,
) error

DeleteSecretsWithLabel - Delete all secrets in namespace of the obj matching label selector

func DeleteSecretsWithName

func DeleteSecretsWithName(
	ctx context.Context,
	r ReconcilerCommon,
	cond *shared.Condition,
	name string,
	namespace string,
) error

DeleteSecretsWithName - Delete names secret object in namespace

func DeleteServicesWithLabel

func DeleteServicesWithLabel(
	ctx context.Context,
	r ReconcilerCommon,
	obj metav1.Object,
	labelSelectorMap map[string]string,
) error

DeleteServicesWithLabel - Delete all services in namespace of the obj matching label selector

func DistributePods

func DistributePods(
	selectorKey string,
	selectorValues []string,
	topologyKey string,
) *corev1.Affinity

DistributePods - returns rule to ensure that two replicas of the same selector should not run if possible on the same worker node

func EncodePrivateKeyToPEM

func EncodePrivateKeyToPEM(privateKey *rsa.PrivateKey) string

EncodePrivateKeyToPEM encodes Private Key from RSA to PEM format

func EnsureConfigMaps

func EnsureConfigMaps(
	ctx context.Context,
	r ReconcilerCommon,
	obj metav1.Object,
	cms []Template,
	envVars *map[string]EnvSetter,
) error

EnsureConfigMaps - get all configmaps required, verify they exist and add the hash to env and status

func EnsureSecrets

func EnsureSecrets(
	ctx context.Context,
	r ReconcilerCommon,
	obj metav1.Object,
	sts []Template,
	envVars *map[string]EnvSetter,
) error

EnsureSecrets - get all secrets required, verify they exist and add the hash to env and status

func ExecuteTemplate

func ExecuteTemplate(templateFile string, data interface{}) (string, error)

ExecuteTemplate creates a template from the file and execute it with the specified data

func ExecuteTemplateData

func ExecuteTemplateData(templateData string, data interface{}) (string, error)

ExecuteTemplateData creates a template from string and execute it with the specified data

func ExecuteTemplateFile

func ExecuteTemplateFile(filename string, data interface{}) (string, error)

ExecuteTemplateFile creates a template from the file and execute it with the specified data Note: mschuppert - can be removed when all operators switched

to the above ones.

func GeneratePassword

func GeneratePassword(pType string) interface{}

GeneratePassword - creates a password for a password type

func GeneratePasswords

func GeneratePasswords() map[string]interface{}

GeneratePasswords creates the passwords for a tripleo deployment

func GeneratePasswordsMap

func GeneratePasswordsMap() map[string]interface{}

GeneratePasswordsMap - generate map from passwordNames()

func GeneratePrivateKey

func GeneratePrivateKey(bitSize int) (*rsa.PrivateKey, error)

GeneratePrivateKey creates a RSA Private Key of specified byte size

func GeneratePublicKey

func GeneratePublicKey(privatekey *rsa.PublicKey) (string, error)

GeneratePublicKey take a rsa.PublicKey and return bytes suitable for writing to .pub file returns in the format "ssh-rsa ..."

func GetAllNetworkAttachmentDefinitions

func GetAllNetworkAttachmentDefinitions(
	ctx context.Context,
	r ReconcilerCommon,
	obj metav1.Object,
) (map[string]networkv1.NetworkAttachmentDefinition, error)

GetAllNetworkAttachmentDefinitions - get all NetworkAttachmentDefinition

func GetAllPodsWithLabel

func GetAllPodsWithLabel(
	ctx context.Context,
	r ReconcilerCommon,
	labelSelectorMap map[string]string,
	namespace string,
) (*corev1.PodList, error)

GetAllPodsWithLabel - get all pods from namespace with a specific label

func GetAllTemplates

func GetAllTemplates(path string, kind string, templateType string, version string) []string

GetAllTemplates get all files from a templates sub folder

func GetCidrParts

func GetCidrParts(cidr string) (string, int, error)

GetCidrParts - returns addr and cidr suffix

func GetConfigMap

func GetConfigMap(
	ctx context.Context,
	r ReconcilerCommon,
	object client.Object,
	cond *shared.Condition,
	conditionDetails shared.ConditionDetails,
	configMapName string,
	requeueTimeout int,
) (*corev1.ConfigMap, ctrl.Result, error)

GetConfigMap - Get config map

if the config map is not found, requeue after requeueTimeout in seconds

func GetConfigMapAndHashWithName

func GetConfigMapAndHashWithName(
	ctx context.Context,
	r ReconcilerCommon,
	configMapName string,
	namespace string,
) (*corev1.ConfigMap, string, error)

GetConfigMapAndHashWithName -

func GetConfigMaps

func GetConfigMaps(
	ctx context.Context,
	r ReconcilerCommon,
	obj runtime.Object,
	configMaps []string,
	namespace string,
	envVars *map[string]EnvSetter,
) ([]ospdirectorv1beta1.Hash, error)

GetConfigMaps - get all configmaps required, verify they exist and add the hash to env and status

func GetCustomFencingRoles

func GetCustomFencingRoles(customBinaryData map[string][]byte) ([]string, error)

GetCustomFencingRoles - return a list of any custom roles included in custom tarball that require fencing support

func GetDataFromSecret

func GetDataFromSecret(
	ctx context.Context,
	r ReconcilerCommon,
	object client.Object,
	cond *shared.Condition,
	conditionDetails shared.ConditionDetails,
	secretName string,
	requeueTimeout int,
	key string,
) (string, ctrl.Result, error)

GetDataFromSecret - Get data from Secret

if the secret or data is not found, requeue after requeueTimeout in seconds

func GetFencingRoles

func GetFencingRoles() []string

GetFencingRoles - roles that normally require fencing

func GetIPRange

func GetIPRange(ip net.IP, ipnet net.IPNet) (net.IP, net.IP, error)

GetIPRange returns the first and last IP in a range

func GetLabels

func GetLabels(obj metav1.Object, controller string, custom map[string]string) map[string]string

GetLabels - get labelselector for CR

func GetOr

func GetOr(m map[string]interface{}, key, fallback string) interface{}

GetOr returns the value of m[key] if it exists, fallback otherwise. As a special case, it also returns fallback if the value of m[key] is the empty string

func GetSecret

func GetSecret(
	ctx context.Context,
	r ReconcilerCommon,
	secretName string,
	secretNamespace string,
) (*corev1.Secret, string, error)

GetSecret -

func GetSecrets

func GetSecrets(
	ctx context.Context,
	r ReconcilerCommon,
	secretNamespace string,
	labelSelectorMap map[string]string,
) (*corev1.SecretList, error)

GetSecrets -

func GetServicesListWithLabel

func GetServicesListWithLabel(
	ctx context.Context,
	r ReconcilerCommon,
	namespace string,
	labelSelectorMap map[string]string,
) (*corev1.ServiceList, error)

GetServicesListWithLabel - Get all services in namespace of the obj matching label selector

func GetTemplateData

func GetTemplateData(t Template) (map[string]string, error)

GetTemplateData -

func GetTemplatesPath

func GetTemplatesPath() string

GetTemplatesPath get path to templates, either running local or deployed as container

func GetVirtualMachineInstances

func GetVirtualMachineInstances(
	ctx context.Context,
	r ReconcilerCommon,
	namespace string,
	labelSelectorMap map[string]string,
) (*virtv1.VirtualMachineInstanceList, error)

GetVirtualMachineInstances -

func GetVirtualMachines

func GetVirtualMachines(
	ctx context.Context,
	r ReconcilerCommon,
	namespace string,
	labelSelectorMap map[string]string,
) (*virtv1.VirtualMachineList, error)

GetVirtualMachines -

func IPToBigInt

func IPToBigInt(IPv6Addr net.IP) *big.Int

IPToBigInt converts a net.IP to a big.Int

func IsInterfaceMap

func IsInterfaceMap(v interface{}) bool

IsInterfaceMap - check if type interface{} is a map

func IsJSON

func IsJSON(s string) error

IsJSON check if string is json format

func IsSet

func IsSet(m map[string]interface{}, key string) interface{}

IsSet returns the value of m[key] if key exists, otherwise false Different from getOr because it will return zero values.

func IterateForAssignment

func IterateForAssignment(assignIPDetails AssignIPDetails) (net.IP, []ospdirectorv1beta1.IPReservation, error)

IterateForAssignment iterates given an IP/IPNet and a list of reserved IPs

func LogErrorForObject

func LogErrorForObject(r ReconcilerCommon,
	err error, msg string, object metav1.Object, params ...interface{})

LogErrorForObject -

func LogForObject

func LogForObject(r ReconcilerCommon,
	msg string, object metav1.Object, params ...interface{})

LogForObject -

func MergeEnvs

func MergeEnvs(envs []corev1.EnvVar, newEnvs EnvSetterMap) []corev1.EnvVar

MergeEnvs - merge envs

func MergeMaps

func MergeMaps(baseMap map[string]interface{}, extraMaps ...map[string]interface{}) map[string]interface{}

MergeMaps - merge two or more maps

func MergeVolumeMounts

func MergeVolumeMounts(vols []corev1.VolumeMount, newVols []corev1.VolumeMount) []corev1.VolumeMount

MergeVolumeMounts - merge container volume mounts in-place

func MergeVolumes

func MergeVolumes(vols []corev1.Volume, newVols []corev1.Volume) []corev1.Volume

MergeVolumes - merge pod volumes in-place

func ObjectHash

func ObjectHash(i interface{}) (string, error)

ObjectHash creates a deep object hash and return it as a safe encoded string

func PasswordNames

func PasswordNames() []string

PasswordNames returns an array with all service passwords used by tripleo

func RecursiveMergeMaps

func RecursiveMergeMaps(
	dst, src map[string]interface{},
	maxDepth int) (map[string]interface{},
	error,
)

RecursiveMergeMaps recursively merges the src into dst maps.

func RemoveIndex

func RemoveIndex(s []string, index int) []string

RemoveIndex - remove int from slice

func SSHKeySecret

func SSHKeySecret(name string, namespace string, labels map[string]string) (*corev1.Secret, error)

SSHKeySecret - func

func StringInSlice

func StringInSlice(a string, list []string) bool

StringInSlice - is string in slice

func WaitOnJob

func WaitOnJob(
	ctx context.Context,
	job *batchv1.Job,
	client client.Client,
	log logr.Logger,
) (bool, error)

WaitOnJob func

func WrapErrorForObject

func WrapErrorForObject(msg string, object client.Object, err error) error

WrapErrorForObject -

Types

type AssignIPDetails

type AssignIPDetails struct {
	IPnet      net.IPNet
	RangeStart net.IP
	RangeEnd   net.IP
	// RoleReservelist - Reservelist of all reservations of the role
	RoleReservelist []ospdirectorv1beta1.IPReservation
	// Reservelist - Reservelist of all reservations
	Reservelist   []ospdirectorv1beta1.IPReservation
	ExcludeRanges []string
	HostRef       string
	Hostname      string
	VIP           bool
	Deleted       bool
}

AssignIPDetails -

type AssignmentError

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

AssignmentError defines an IP assignment error.

func (AssignmentError) Error

func (a AssignmentError) Error() string

type EnvSetter

type EnvSetter func(*corev1.EnvVar)

EnvSetter -

func EnvDownwardAPI

func EnvDownwardAPI(field string) EnvSetter

EnvDownwardAPI - set env from FieldRef->FieldPath, e.g. status.podIP

func EnvValue

func EnvValue(value string) EnvSetter

EnvValue -

type EnvSetterMap

type EnvSetterMap map[string]EnvSetter

EnvSetterMap -

type Hostname

type Hostname struct {
	Basename string
	Hostname string
	HostRef  string
	VIP      bool
}

Hostname - details

type HostnameStore

type HostnameStore interface {
	GetHostnames() map[string]string
}

HostnameStore -

type InstanceCommon

type InstanceCommon interface {
	// Place anything we want from "inherited" (metav1 types, etc) funcs here
	GetName() string
	GetNamespace() string

	// Place our types' custom funcs here
	IsReady() bool
}

InstanceCommon - common OSP-D resource instance interface

type List

type List []Pair

List -

func SortMapByValue

func SortMapByValue(in map[string]string) List

SortMapByValue -

func (List) Len

func (p List) Len() int

func (List) Less

func (p List) Less(i, j int) bool

func (List) Swap

func (p List) Swap(i, j int)

type Pair

type Pair struct {
	Key   string
	Value string
}

Pair -

type Pvc

type Pvc struct {
	Name         string
	Namespace    string
	Size         string
	Labels       map[string]string
	StorageClass string
	AccessMode   []corev1.PersistentVolumeAccessMode
}

Pvc - pvc details

type ReconcilerCommon

type ReconcilerCommon interface {
	GetClient() client.Client
	GetKClient() kubernetes.Interface
	GetLogger() logr.Logger
	GetScheme() *runtime.Scheme
}

ReconcilerCommon - common reconciler interface

type TType

type TType string

TType - TemplateType

const (
	// TemplateTypeScripts - config type
	TemplateTypeScripts TType = "bin"
	// TemplateTypeConfig - config type
	TemplateTypeConfig TType = "config"
	// TemplateTypeCustom - custom config type
	TemplateTypeCustom TType = "custom"
	// TemplateTypeNone - none type, don't add configs from a directory, only files from AdditionalData
	TemplateTypeNone TType = "none"
)

type Template

type Template struct {
	Name               string
	Namespace          string
	Type               TType
	InstanceType       string
	SecretType         corev1.SecretType // Secrets only, defaults to "Opaque"
	AdditionalTemplate map[string]string
	CustomData         map[string]string
	Labels             map[string]string
	Annotations        map[string]string
	ConfigOptions      map[string]interface{}
	SkipSetOwner       bool // skip setting ownership on the associated configmap
	Version            shared.OSPVersion
}

Template - config map and secret details

Jump to

Keyboard shortcuts

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