utils

package
v4.6.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package utils to provide utils for storageBackend

Package utils to provide utils for storageBackend

Package utils to provide k8s resource utils

Package utils to provide utils for storageBackend

Index

Constants

View Source
const (
	// ConfigMapFinalizer used when configmap as a resource to create StorageBackendContent
	ConfigMapFinalizer = "storagebackend.xuanwu.huawei.io/configmap-protection"
	// SecretFinalizer used when secret as a resource to create StorageBackendContent
	SecretFinalizer = "storagebackend.xuanwu.huawei.io/secret-protection"
	// ClaimBoundFinalizer used when storageBackendClaim bound to a storageBackendContent
	ClaimBoundFinalizer = "storagebackend.xuanwu.huawei.io/storagebackendclaim-bound-protection"
	// ContentBoundFinalizer used when storageBackendContent bound to a storageBackendClaim
	ContentBoundFinalizer = "storagebackend.xuanwu.huawei.io/storagebackendcontent-bound-protection"
)
View Source
const (
	// BackendStatus backend status topic
	BackendStatus = "BACKEND_STATUS"
)

Variables

This section is empty.

Functions

func CombineMap

func CombineMap[K comparable, V any](dst map[K]V, src map[K]V) map[K]V

CombineMap combines two maps and returns a new map, if there's a key conflict, subject to the destination map.

func ConvertMapString2MapInterface

func ConvertMapString2MapInterface(param map[string]string) map[string]interface{}

ConvertMapString2MapInterface used to convert map[string]string to map[string]interface

func ConvertToMapValueX

func ConvertToMapValueX[T bool | string | int64 | map[string]interface{}](ctx context.Context,
	m map[string]interface{}) map[string]T

ConvertToMapValueX convert map value to x

func ConvertToStringSlice

func ConvertToStringSlice(inputs []interface{}) []string

ConvertToStringSlice convert interface slice to string slice

func CreateContent

CreateContent used to create content by xuanwu client

func DeleteContent

func DeleteContent(ctx context.Context, client clientSet.Interface, contentName string) error

DeleteContent used to delete content by xuanwu client

func Errorf

func Errorf(ctx context.Context, format string, a ...interface{}) error

Errorf used to create and print formatted error messages.

func Errorln

func Errorln(ctx context.Context, msg string) error

Errorln used to create and print error messages.

func GenDynamicContentName

func GenDynamicContentName(storageBackend *xuanwuv1.StorageBackendClaim) string

GenDynamicContentName return the uniq name of StorageBackendContent

func GenObjectMetaKey

func GenObjectMetaKey(obj interface{}) (string, error)

GenObjectMetaKey return the meta namespace key

func GetBackendConfigmapByClaimName

func GetBackendConfigmapByClaimName(ctx context.Context, claimNameMeta string) (*coreV1.ConfigMap, error)

func GetBackendSecret

func GetBackendSecret(ctx context.Context, secretMeta string) (*coreV1.Secret, error)

func GetCertMeta

func GetCertMeta(ctx context.Context, claimNameMeta string) (bool, string, error)

GetCertMeta get cert meta from backend claim

func GetCertPool

func GetCertPool(ctx context.Context, useCert bool, secretMeta string) (bool, *x509.CertPool, error)

GetCertPool get cert pool

func GetCertSecretFromBackendID

func GetCertSecretFromBackendID(ctx context.Context, backendID string) (bool, string, error)

GetCertSecretFromBackendID get cert secret meta from backend

func GetClaim

GetClaim used to get claim by xuanwu client

func GetClaimByMeta

func GetClaimByMeta(ctx context.Context, claimNameMeta string) (*xuanwuv1.StorageBackendClaim, error)

func GetConfigMap

func GetConfigMap(configmapMeta string) (*coreV1.ConfigMap, error)

GetConfigMap is to get configmap using storage backend claim

func GetConfigMeta

func GetConfigMeta(ctx context.Context, claimNameMeta string) (string, string, error)

func GetContent

func GetContent(ctx context.Context, client clientSet.Interface, contentName string) (
	*xuanwuv1.StorageBackendContent, error)

GetContent used to get content by xuanwu client

func GetContentByClaimMeta

func GetContentByClaimMeta(ctx context.Context, claimNameMeta string) (*xuanwuv1.StorageBackendContent, error)

func GetK8SAndCrdClient

func GetK8SAndCrdClient(ctx context.Context) (*kubernetes.Clientset, *clientSet.Clientset, error)

GetK8SAndCrdClient return k8sClient, crdClient

func GetNameSpaceFromEnv

func GetNameSpaceFromEnv(namespaceEnv, defaultNamespace string) string

GetNameSpaceFromEnv get the namespace from the env

func GetPasswordFromBackendID

func GetPasswordFromBackendID(ctx context.Context, backendID string) (string, error)

func GetSBCTCapabilitiesByClaim

func GetSBCTCapabilitiesByClaim(ctx context.Context, backendID string) (map[string]bool, error)

GetSBCTCapabilitiesByClaim get backend capabilities

func GetSBCTOnlineStatusByClaim

func GetSBCTOnlineStatusByClaim(ctx context.Context, backendID string) (bool, error)

func GetSBCTOnlineStatusByContent

func GetSBCTOnlineStatusByContent(ctx context.Context, content *xuanwuv1.StorageBackendContent) (bool, error)

GetSBCTOnlineStatusByContent get backend capabilities by SBCT

func GetSecret

func GetSecret(meta string) (*coreV1.Secret, error)

GetSecret is to get secret using storage backend claim

func InitRecorder

func InitRecorder(client kubernetes.Interface, componentName string) record.EventRecorder

InitRecorder used to init event recorder

func IsBackendCapabilitySupport

func IsBackendCapabilitySupport(ctx context.Context, backendID string,
	capability constants.BackendCapability) (bool, error)

IsBackendCapabilitySupport valid backend capability

func IsClaimBoundContent

func IsClaimBoundContent(storageBackend *xuanwuv1.StorageBackendClaim) bool

IsClaimBoundContent indicates whether StorageBackendClaim bound to StorageBackendContent

func IsClaimReady

func IsClaimReady(storageBackend *xuanwuv1.StorageBackendClaim) bool

IsClaimReady returns StorageBackendClaim ready or not

func IsContentReady

func IsContentReady(ctx context.Context, content *xuanwuv1.StorageBackendContent) bool

IsContentReady returns StorageBackendContent ready or not

func IsSBCTExist

func IsSBCTExist(ctx context.Context, backendID string) bool

func IsSBCTOnline

func IsSBCTOnline(ctx context.Context, backendID string) bool

func ListClaim

func ListClaim(ctx context.Context, client clientSet.Interface, namespace string) (*xuanwuv1.StorageBackendClaimList, error)

ListClaim used to list claims by xuanwu client

func ListContent

ListContent used to list contents by xuanwu client

func MakeMetaWithNamespace

func MakeMetaWithNamespace(ns, name string) string

MakeMetaWithNamespace used to make a backendID

func NeedAddClaimBoundFinalizers

func NeedAddClaimBoundFinalizers(storageBackend *xuanwuv1.StorageBackendClaim) bool

NeedAddClaimBoundFinalizers returns whether to add a Finalizer to claim

func NeedAddContentBoundFinalizers

func NeedAddContentBoundFinalizers(content *xuanwuv1.StorageBackendContent) bool

NeedAddContentBoundFinalizers returns whether to add a Finalizer to content

func NeedChangeContent

func NeedChangeContent(storageBackend *xuanwuv1.StorageBackendClaim) bool

NeedChangeContent returns need update content or not

func NeedRemoveClaimBoundFinalizers

func NeedRemoveClaimBoundFinalizers(storageBackend *xuanwuv1.StorageBackendClaim) bool

NeedRemoveClaimBoundFinalizers returns whether to add a Finalizer

func NeedRemoveContentBoundFinalizers

func NeedRemoveContentBoundFinalizers(content *xuanwuv1.StorageBackendContent) bool

NeedRemoveContentBoundFinalizers returns whether to add a Finalizer

func Publish

func Publish(ctx context.Context, key string, args ...interface{})

Publish event to subscriber

func RunWithLeaderElection

func RunWithLeaderElection(ctx context.Context, leaderElection LeaderElectionConf, k8sClient *kubernetes.Clientset,
	recorder record.EventRecorder, runFunc func(ctx context.Context, ch chan os.Signal), ch chan os.Signal)

RunWithLeaderElection run with leader election

func SetSBCTOnlineStatus

func SetSBCTOnlineStatus(ctx context.Context, content *xuanwuv1.StorageBackendContent, status bool) error

func SetStorageBackendContentOnlineStatus

func SetStorageBackendContentOnlineStatus(ctx context.Context, backendID string, online bool) error

func SplitMetaNamespaceKey

func SplitMetaNamespaceKey(obj string) (namespace, name string, err error)

SplitMetaNamespaceKey returns the namespace and name

func StorageBackendClaimKey

func StorageBackendClaimKey(storageBackend *xuanwuv1.StorageBackendClaim) string

StorageBackendClaimKey return the uniq name of claim

func StoreObjectUpdate

func StoreObjectUpdate(ctx context.Context, store cache.Store, obj interface{}, className string) (bool, error)

StoreObjectUpdate updates given cache with a new object version from Informer

func Subscribe

func Subscribe(topic string, fn interface{})

Subscribe subscribe topic

func UpdateClaim

func UpdateClaim(ctx context.Context, client clientSet.Interface, storageBackend *xuanwuv1.StorageBackendClaim) (
	*xuanwuv1.StorageBackendClaim, error)

UpdateClaim used to update claim by xuanwu client

func UpdateClaimStatus

func UpdateClaimStatus(ctx context.Context, client clientSet.Interface, storageBackend *xuanwuv1.StorageBackendClaim) (
	*xuanwuv1.StorageBackendClaim, error)

UpdateClaimStatus used to update claim status by xuanwu client

func UpdateConfigMap

func UpdateConfigMap(configmap *coreV1.ConfigMap) (*coreV1.ConfigMap, error)

UpdateConfigMap is to update configmap using storage backend claim

func UpdateContent

UpdateContent used to update content by xuanwu client

func UpdateContentStatus

UpdateContentStatus used to update content status by xuanwu client

func WaitExitSignal

func WaitExitSignal(ctx context.Context, components string)

WaitExitSignal is used to wait exits signal, components e.g. webhook, controller

Types

type LeaderElectionConf

type LeaderElectionConf struct {
	LeaderName    string
	LeaseDuration time.Duration
	RenewDeadline time.Duration
	RetryPeriod   time.Duration
}

LeaderElectionConf include the configuration of leader election

Jump to

Keyboard shortcuts

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