utils

package
v0.0.0-...-676ee26 Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BucketGenerateName = "odrbucket"

	// s3
	S3ProfilePrefix    = "s3profile"
	S3Endpoint         = "s3CompatibleEndpoint"
	S3BucketName       = "s3Bucket"
	S3ProfileName      = "s3ProfileName"
	S3Region           = "s3Region"
	AwsAccessKeyId     = "AWS_ACCESS_KEY_ID"
	AwsSecretAccessKey = "AWS_SECRET_ACCESS_KEY"

	// ramen
	RamenHubOperatorConfigName = "ramen-hub-operator-config"

	//handlers
	RookSecretHandlerName = "rook"
	S3SecretHandlerName   = "s3"
	DRModeAnnotationKey   = "multicluster.openshift.io/mode"
)
View Source
const (
	SourceLabel           SecretLabelType = "BLUE"
	DestinationLabel      SecretLabelType = "GREEN"
	InternalLabel         SecretLabelType = "INTERNAL"
	IgnoreLabel           SecretLabelType = "IGNORE"
	SecretLabelTypeKey                    = "multicluster.odf.openshift.io/secret-type"
	CreatedByLabelKey                     = "multicluster.odf.openshift.io/created-by"
	NamespaceKey                          = "namespace"
	StorageClusterNameKey                 = "storage-cluster-name"
	SecretDataKey                         = "secret-data"
	SecretOriginKey                       = "secret-origin"
	MirrorPeerSecret                      = "mirrorpeersecret"
	RookTokenKey                          = "token"
	ClusterTypeKey                        = "cluster_type"
	HubRecoveryLabel                      = "cluster.open-cluster-management.io/backup"
)

Variables

View Source
var OriginMap = map[string]string{"RookOrigin": "rook", "S3Origin": "S3"}
View Source
var SourceOrDestinationPredicate = predicate.Funcs{
	CreateFunc: func(e event.CreateEvent) bool {
		return IsSecretSource(e.Object) || IsSecretInternal(e.Object)
	},
	DeleteFunc: func(e event.DeleteEvent) bool {
		return IsSecretSource(e.Object) || IsSecretDestination(e.Object)
	},
	UpdateFunc: func(e event.UpdateEvent) bool {
		return (IsSecretSource(e.ObjectOld) && IsSecretSource(e.ObjectNew)) ||
			(IsSecretDestination(e.ObjectOld) && IsSecretDestination(e.ObjectNew)) ||
			IsSecretInternal(e.ObjectOld) && IsSecretInternal(e.ObjectNew)
	},
	GenericFunc: func(_ event.GenericEvent) bool {
		return false
	},
}

SourceOrDestinationPredicate is a predicate that matches events that check whether a secret has required source or destination labels or not.

Functions

func ComposePredicates

func ComposePredicates(predicates ...predicate.Predicate) predicate.Predicate

ComposePredicates will compose a variable number of predicates and return a predicate that will allow events that are allowed by any of the given predicates.

func ContainsPeerRef

func ContainsPeerRef(slice []multiclusterv1alpha1.PeerRef, peerRef *multiclusterv1alpha1.PeerRef) bool

ContainsPeerRef checks if a slice of PeerRef contains the provided PeerRef

func ContainsString

func ContainsString(slice []string, s string) bool

ContainsString checks if a slice of strings contains the provided string

func ContainsSubject

func ContainsSubject(slice []rbacv1.Subject, subject *rbacv1.Subject) bool

func ContainsSuffix

func ContainsSuffix(slice []string, s string) bool

func CreateDestinationSecret

func CreateDestinationSecret(secretNameAndNamespace types.NamespacedName,
	storageClusterNameAndNamespace types.NamespacedName,
	secretData []byte, secretOrigin string) *corev1.Secret

CreateDestinationSecret creates a destination secret

func CreatePeerRefFromSecret

func CreatePeerRefFromSecret(secret *corev1.Secret) (multiclusterv1alpha1.PeerRef, error)

CreatePeerRefFromSecret function creates a 'PeerRef' object from the internal secret details

func CreateSourceSecret

func CreateSourceSecret(secretNameAndNamespace types.NamespacedName,
	storageClusterNameAndNamespace types.NamespacedName,
	secretData []byte, SecretOrigin string) *corev1.Secret

CreateSourceSecret creates a source secret

func CreateUniqueName

func CreateUniqueName(params ...string) string

CreateUniqueName function creates a sha512 hex sum from the given parameters

func CreateUniqueReplicationId

func CreateUniqueReplicationId(clusterFSIDs map[string]string) (string, error)

func CreateUniqueSecretName

func CreateUniqueSecretName(managedCluster, storageClusterNamespace, storageClusterName string, prefix ...string) string

CreateUniqueSecretName function creates a name of 40 chars using sha512 hex sum from the given parameters

func DoesAnotherMirrorPeerPointToPeerRef

func DoesAnotherMirrorPeerPointToPeerRef(ctx context.Context, rc client.Client, peerRef *multiclusterv1alpha1.PeerRef) (bool, error)

DoesAnotherMirrorPeerPointToPeerRef checks if another mirrorpeer is pointing to the provided peer ref

func FetchAllCephClusters

func FetchAllCephClusters(ctx context.Context, client client.Client) (*rookv1.CephClusterList, error)

func FetchAllSecretsWithLabel

func FetchAllSecretsWithLabel(ctx context.Context, rc client.Client, namespace string, secretLabelType SecretLabelType) ([]corev1.Secret, error)

FetchAllSecretsWithLabel will get all the internal secrets in the namespace and with the provided label if the namespace is empty, it will fetch from all the namespaces if the label type is 'Ignore', it will fetch all the internal secrets (both source and destination)

func FetchSecretWithName

func FetchSecretWithName(ctx context.Context, rc client.Client, secretName types.NamespacedName) (*corev1.Secret, error)

func FindMatchingSecretWithPeerRef

func FindMatchingSecretWithPeerRef(peerRef multiclusterv1alpha1.PeerRef, secrets []corev1.Secret) *corev1.Secret

func FnvHash

func FnvHash(s string) uint32

fnv64a is a 64-bit non-cryptographic hash algorithm with a low collision and a high distribution rate. https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function

func GetCurrentStorageClusterRef

func GetCurrentStorageClusterRef(mp *multiclusterv1alpha1.MirrorPeer, spokeClusterName string) (*multiclusterv1alpha1.StorageClusterRef, error)

func GetEnv

func GetEnv(key, defaultValue string) string

func GetPeerRefForSpokeCluster

func GetPeerRefForSpokeCluster(mp *multiclusterv1alpha1.MirrorPeer, spokeClusterName string) (*multiclusterv1alpha1.PeerRef, error)

GetPeerRefForSpokeCluster returns the peer ref for the cluster name

func GetSecretNameByPeerRef

func GetSecretNameByPeerRef(pr multiclusterv1alpha1.PeerRef, prefix ...string) string

func HasHubRecoveryLabels

func HasHubRecoveryLabels(secret *corev1.Secret) bool

func IsSecretDestination

func IsSecretDestination(obj client.Object) bool

IsSecretDestination returns true if the provided object is a secret with Destination label

func IsSecretInternal

func IsSecretInternal(obj client.Object) bool

IsSecretInternal returns true if the provided object is a secret with Inernal label

func IsSecretSource

func IsSecretSource(obj client.Object) bool

IsSecretSource returns true if the provided object is a secret with Source label

func RemoveMirrorPeer

func RemoveMirrorPeer(slice []multiclusterv1alpha1.MirrorPeer, mirrorPeer multiclusterv1alpha1.MirrorPeer) (result []multiclusterv1alpha1.MirrorPeer)

RemoveMirrorPeer removes the given mirrorPeer from the slice and returns the new slice

func RemoveString

func RemoveString(slice []string, s string) (result []string)

RemoveString removes a given string from a slice and returns the new slice

func ScaleDeployment

func ScaleDeployment(ctx context.Context, client client.Client, deploymentName string, namespace string, replicas int32) (bool, error)

func ValidateDestinationSecret

func ValidateDestinationSecret(sourceSecret *corev1.Secret) error

ValidateDestinationSecret validates whether the given secret is a Destination type

func ValidateInternalSecret

func ValidateInternalSecret(internalSecret *corev1.Secret, expectedLabel SecretLabelType) error

func ValidateS3Secret

func ValidateS3Secret(data map[string][]byte) bool

func ValidateSourceSecret

func ValidateSourceSecret(sourceSecret *corev1.Secret) error

ValidateSourceSecret validates whether the given secret is a Source type

Types

type ClusterType

type ClusterType string
const (
	CONVERGED                     ClusterType = "Converged"
	EXTERNAL                      ClusterType = "External"
	UNKNOWN                       ClusterType = "Unknown"
	CephClusterReplicationIdLabel             = "replicationid.multicluster.openshift.io"
)

func GetClusterType

func GetClusterType(storageClusterName string, namespace string, client client.Client) (ClusterType, error)

type HubToken

type HubToken struct {
	Token   string `json:"token"`
	Cluster string `json:"cluster"`
}

type RookToken

type RookToken struct {
	FSID      string `json:"fsid"`
	Namespace string `json:"namespace"`
	MonHost   string `json:"mon_host"`
	ClientId  string `json:"client_id"`
	Key       string `json:"key"`
}

func UnmarshalHubSecret

func UnmarshalHubSecret(hubSecret *corev1.Secret) (*RookToken, error)

func UnmarshalRookSecret

func UnmarshalRookSecret(rookSecret *corev1.Secret) (*RookToken, error)

type RookTokenExternal

type RookTokenExternal struct {
	CephSecret   string `json:"ceph-secret,omitempty"`
	CephUsername string `json:"ceph-username,omitempty"`
	FSID         string `json:"fsid"`
	MonSecret    string `json:"mon-secret,omitempty"`
}

func UnmarshalRookSecretExternal

func UnmarshalRookSecretExternal(rookSecret *corev1.Secret) (*RookTokenExternal, error)

type S3Token

type S3Token struct {
	AccessKeyID          string `json:"AWS_ACCESS_KEY_ID"`
	SecretAccessKey      string `json:"AWS_SECRET_ACCESS_KEY"`
	S3Bucket             string `json:"s3Bucket"`
	S3CompatibleEndpoint string `json:"s3CompatibleEndpoint"`
	S3ProfileName        string `json:"s3ProfileName"`
	S3Region             string `json:"s3Region"`
}

func UnmarshalS3Secret

func UnmarshalS3Secret(s3Secret *corev1.Secret) (*S3Token, error)

type SecretLabelType

type SecretLabelType string

func GetInternalLabel

func GetInternalLabel(secret *corev1.Secret) SecretLabelType

Jump to

Keyboard shortcuts

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