common

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2022 License: Apache-2.0 Imports: 53 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"
	// HostRemovalAnnotation - Annotation key placed on VM or BMH resources to target them for scale-down
	HostRemovalAnnotation = GroupLabel + "/delete-host"

	// 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"
)
View Source
const (
	// BITSIZE -
	BITSIZE int = 4096
)

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(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(r ReconcilerCommon, obj metav1.Object, secret *corev1.Secret) (string, controllerutil.OperationResult, error)

CreateOrUpdateSecret -

func DeleteJob

func DeleteJob(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(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(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(r ReconcilerCommon, obj metav1.Object, labelSelectorMap map[string]string) error

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

func DeleteSecretsWithName added in v1.2.0

func DeleteSecretsWithName(
	r ReconcilerCommon,
	cond *ospdirectorv1beta1.Condition,
	name string,
	namespace string,
) error

DeleteSecretsWithName - Delete names secret object in namespace

func DeleteServicesWithLabel

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

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

func EncodePrivateKeyToPEM

func EncodePrivateKeyToPEM(privateKey *rsa.PrivateKey) string

EncodePrivateKeyToPEM encodes Private Key from RSA to PEM format

func EnsureConfigMaps

func EnsureConfigMaps(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(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

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

func ExecuteTemplateData

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

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

func ExecuteTemplateFile

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

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 GeneratePasswords

func GeneratePasswords() map[string]interface{}

GeneratePasswords creates the passwords for a tripleo deployment

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(r ReconcilerCommon, obj metav1.Object) (map[string]networkv1.NetworkAttachmentDefinition, error)

GetAllNetworkAttachmentDefinitions - get all NetworkAttachmentDefinition

func GetAllPodsWithLabel

func GetAllPodsWithLabel(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 GetBmhHosts

func GetBmhHosts(r ReconcilerCommon, namespace string, labelSelector map[string]string) (*metal3v1alpha1.BareMetalHostList, error)

GetBmhHosts -

func GetCidrParts added in v1.2.0

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

GetCidrParts - returns addr and cidr suffix

func GetConfigMap added in v1.2.0

func GetConfigMap(
	r ReconcilerCommon,
	object client.Object,
	cond *ospdirectorv1beta1.Condition,
	conditionDetails ospdirectorv1beta1.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(r ReconcilerCommon, configMapName string, namespace string) (*corev1.ConfigMap, string, error)

GetConfigMapAndHashWithName -

func GetConfigMaps

func GetConfigMaps(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 added in v1.2.0

func GetDataFromSecret(
	r ReconcilerCommon,
	object client.Object,
	cond *ospdirectorv1beta1.Condition,
	conditionDetails ospdirectorv1beta1.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 GetDeletionAnnotatedBmhHosts

func GetDeletionAnnotatedBmhHosts(r ReconcilerCommon, namespace string, labelSelector map[string]string) ([]string, error)

GetDeletionAnnotatedBmhHosts -

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(r ReconcilerCommon, secretName string, secretNamespace string) (*corev1.Secret, string, error)

GetSecret -

func GetSecrets

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

GetSecrets -

func GetServicesListWithLabel

func GetServicesListWithLabel(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

GetTemplateData -

func GetTemplatesPath

func GetTemplatesPath() string

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

func GetVirtualMachineInstances

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

GetVirtualMachineInstances -

func GetVirtualMachines

func GetVirtualMachines(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 InitMap

func InitMap(m *map[string]string)

InitMap - Inititialise a map to an empty map if it is nil.

func IsIPv4

func IsIPv4(ip net.IP) bool

IsIPv4 checks if an IP is v4.

func IsIPv6

func IsIPv6(ip net.IP) bool

IsIPv6 checks if an IP is v6.

func IsJSON added in v1.2.0

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 added in v1.2.0

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

LogErrorForObject -

func LogForObject added in v1.2.0

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 MergeStringMaps added in v1.2.0

func MergeStringMaps(baseMap map[string]string, extraMaps ...map[string]string) map[string]string

MergeStringMaps - merge two or more string->map maps

func ObjectHash

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

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

func OpenStackBackupOverridesReconcile added in v1.2.0

func OpenStackBackupOverridesReconcile(client client.Client, instance InstanceCommon) (bool, error)

OpenStackBackupOverridesReconcile - Should a controller pause reconciliation for a particular resource given potential backup operations?

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(job *batchv1.Job, client client.Client, log logr.Logger) (bool, error)

WaitOnJob func

func WrapErrorForObject added in v1.2.0

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 added in v1.2.0

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 added in v1.2.0

type List []Pair

List -

func SortMapByValue

func SortMapByValue(in map[string]string) List

SortMapByValue -

func (List) Len added in v1.2.0

func (p List) Len() int

func (List) Less added in v1.2.0

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

func (List) Swap added in v1.2.0

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

type Pair added in v1.2.0

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