utils

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2024 License: Apache-2.0 Imports: 36 Imported by: 0

Documentation

Overview

Package utils provide utilities like buildinfo

Index

Constants

View Source
const (
	BackupLocationServiceAnnotation = "kahu.io/provider-service"
	NamespaceAnnotation             = "kahu.io/provider-namespace"
	InsecureAnnotation              = "kahu.io/provider-insecure-grpc-connection"
	NamespaceEnv                    = "NAMESPACE"
)
View Source
const (
	Pod                = "Pod"
	Service            = "Service"
	Deployment         = "Deployment"
	Replicaset         = "ReplicaSet"
	StatefulSet        = "StatefulSet"
	DaemonSet          = "DaemonSet"
	Configmap          = "ConfigMap"
	Secret             = "Secret"
	PVC                = "PersistentVolumeClaim"
	PV                 = "PersistentVolume"
	Endpoint           = "Endpoint"
	SC                 = "StorageClass"
	Backup             = "Backup"
	VBC                = "VolumeBackupContent"
	KahuSnapshot       = "VolumeSnapshot"
	BackupLocation     = "BackupLocation"
	Node               = "Node"
	Event              = "Event"
	VolumeSnapshot     = "VolumeSnapshot"
	ClusterRole        = "ClusterRole"
	ClusterRoleBinding = "ClusterRoleBinding"
	Role               = "Role"
	RoleBinding        = "RoleBinding"
	ServiceAccount     = "ServiceAccount"
	EndpointSlice      = "EndpointSlice"

	AnnBackupLocationParam = "kahu.io/backup-location-parameter"
)
View Source
const (
	EventOwnerNotDeleted        = "OwnerNotDeleted"
	EventCancelVolRestoreFailed = "CancelVolRestoreFailed"
)

Variables

View Source
var (
	GVKPersistentVolumeClaim = schema.GroupVersionKind{Group: corev1.SchemeGroupVersion.Group,
		Version: corev1.SchemeGroupVersion.Version, Kind: "PersistentVolumeClaim"}
	GVKRestore = schema.GroupVersionKind{Group: kahuapi.SchemeGroupVersion.Group,
		Version: kahuapi.SchemeGroupVersion.Version, Kind: "Restore"}
	GVKBackup = schema.GroupVersionKind{Group: kahuapi.SchemeGroupVersion.Group,
		Version: kahuapi.SchemeGroupVersion.Version, Kind: "Backup"}

	DeletionHandlingMetaNamespaceKeyFunc = cache.DeletionHandlingMetaNamespaceKeyFunc
)
View Source
var SupportedCsiDrivers = []string{""}

Functions

func AddGRPCRequestID added in v0.1.1

func AddGRPCRequestID(ctx context.Context,
	method string,
	req, reply interface{},
	cc *grpc.ClientConn,
	invoker grpc.UnaryInvoker,
	opts ...grpc.CallOption) error

func CheckBackupSupport added in v0.1.1

func CheckBackupSupport(pv corev1.PersistentVolume) error

CheckBackupSupport checks if PV is t be considered for backup or not

func CheckServerUnavailable added in v0.1.1

func CheckServerUnavailable(err error) bool

func Contains added in v0.1.1

func Contains(s []string, str string) bool

func ContainsAnnotation added in v0.1.1

func ContainsAnnotation(meta metav1.Object, annotation string) bool

ContainsAnnotation checks for Annotation existence.

func ContainsFinalizer added in v0.1.1

func ContainsFinalizer(meta metav1.Object, finalizer string) bool

ContainsFinalizer checks for finalizer existence.

func FileToResource added in v0.1.1

func FileToResource(filePath string) *pb.Resource

func FindMatchedStrings added in v0.1.1

func FindMatchedStrings(kind string, allList []string, includeList, excludeList []kahuapi.ResourceSpec) []string

func GetAnnotation added in v0.1.1

func GetAnnotation(meta metav1.Object, annotation string) (string, bool)

GetAnnotation checks and return for annotation value.

func GetBackupIdentifier added in v0.1.1

func GetBackupIdentifier(backup *kahuapi.Backup,
	backupLocation *kahuapi.BackupLocation,
	backupProvider *kahuapi.Provider) (*pb.BackupIdentifier, error)

func GetBackupLocation added in v0.1.1

func GetBackupLocation(
	logger log.FieldLogger,
	locationName string,
	backupLocationLister kahulister.BackupLocationLister) (*kahuapi.BackupLocation, error)

func GetBackupParameters added in v0.1.1

func GetBackupParameters(
	logger log.FieldLogger,
	backupName,
	backupLocationName string,
	backupLocationLister kahulister.BackupLocationLister,
	backupProviderLister kahulister.ProviderLister) (map[string]string, error)

func GetConfig

func GetConfig(kubeConfig string) (config *restclient.Config, err error)

func GetDynamicClient added in v0.1.1

func GetDynamicClient(config *restclient.Config) (dynamic.Interface, error)

func GetGRPCConnection added in v0.1.1

func GetGRPCConnection(endpoint string, dialOptions ...grpc.DialOption) (*grpc.ClientConn, error)

func GetK8sClient added in v0.1.1

func GetK8sClient(config *restclient.Config) (*kubernetes.Clientset, error)

func GetMetaserviceBackupClient added in v0.1.1

func GetMetaserviceBackupClient(address string, port uint) metaservice.MetaService_BackupClient

func GetMetaserviceClient added in v0.1.1

func GetMetaserviceClient(grpcConnection *grpc.ClientConn) metaservice.MetaServiceClient

func GetMetaserviceDeleteClient added in v0.1.1

func GetMetaserviceDeleteClient(address string, port uint) metaservice.MetaServiceClient

func GetProvider added in v0.1.1

func GetProvider(
	logger log.FieldLogger,
	providerName string,
	providerLister kahulister.ProviderLister) (*kahuapi.Provider, error)

func GetResultantItems added in v0.1.1

func GetResultantItems(allList, includeList, excludeList []string) []string

func GetSubItemStrings added in v0.1.1

func GetSubItemStrings(allList []string, input string, isRegex bool) []string

func GetgrpcConn added in v0.1.1

func GetgrpcConn(address string, port uint) (*grpc.ClientConn, error)

func NamespaceAndName

func NamespaceAndName(objMeta metav1.Object) string

func Probe added in v0.1.1

func Probe(conn grpc.ClientConnInterface, timeout time.Duration) error

func RemoveAnnotation added in v0.1.1

func RemoveAnnotation(meta metav1.Object, annotation string)

RemoveAnnotation removes annotation if it exists.

func RemoveFinalizer added in v0.1.1

func RemoveFinalizer(meta metav1.Object, finalizer string)

RemoveFinalizer removes a finalizer if it exists.

func RemoveItem added in v0.1.1

func RemoveItem(s []string, r string) []string

func ResourceToFile

func ResourceToFile(backupHandle string, resource *pb.Resource) string

func SetAnnotation added in v0.1.1

func SetAnnotation(meta metav1.Object, annotation, value string)

SetAnnotation append Annotation if not exists.

func SetFinalizer added in v0.1.1

func SetFinalizer(meta metav1.Object, finalizer string)

SetFinalizer append finalizer if not exists.

func SetupSignalHandler added in v0.1.1

func SetupSignalHandler(cancel context.CancelFunc)

func StoreClean added in v0.1.1

func StoreClean(store Store, obj interface{}, className string) error

StoreClean delete given cache with the object version from Informer callback (i.e. with events from etcd) or with an object modified by the controller itself. Returns error if face any issue during delete

func StoreRevisionUpdate added in v0.1.1

func StoreRevisionUpdate(store Store, obj interface{}, className string) (bool, error)

StoreRevisionUpdate updates given cache with a new object version from Informer callback (i.e. with events from etcd) or with an object modified by the controller itself. Returns "true", if the cache was updated, false if the object is an old version and should be ignored.

func ValidateIncludesExcludes

func ValidateIncludesExcludes(includesList, excludesList []string) []error

func ValidateNamespace added in v0.1.1

func ValidateNamespace(includesList, excludesList []string) []error

func VolumeProvider added in v1.0.0

func VolumeProvider(pv *corev1.PersistentVolume) string

Types

type BuildInfo added in v0.1.1

type BuildInfo struct {
	GitVersion   string `json:"gitVersion"`
	GitCommit    string `json:"gitCommit"`
	GitTreeState string `json:"gitTreeState"`
	BuildDate    string `json:"buildDate"`
	GoVersion    string `json:"goVersion"`
	Compiler     string `json:"compiler"`
	Platform     string `json:"platform"`
}

BuildInfo contains build information

func GetBuildInfo added in v0.1.1

func GetBuildInfo() BuildInfo

GetBuildInfo returns the overall code build info

func (BuildInfo) Print added in v0.1.1

func (info BuildInfo) Print()

type KeyFunc added in v0.1.1

type KeyFunc func(obj interface{}) (string, error)

KeyFunc knows how to make a key from an object. Implementations should be deterministic.

type Store added in v0.1.1

type Store interface {

	// Add adds the given object to the accumulator associated with the given object's key
	Add(obj interface{}, value interface{}) error

	// Update updates the given object in the accumulator associated with the given object's key
	Update(obj interface{}, value interface{}) error

	// Delete deletes the given object from the accumulator associated with the given object's key
	Delete(obj interface{}) error

	// Get returns the accumulator associated with the given object's key
	Get(obj interface{}) (item interface{}, exists bool, err error)

	// List returns a list of all the currently non-empty accumulators
	List() []interface{}

	// ListKeys returns a list of all the keys currently associated with non-empty accumulators
	ListKeys() []string
}

func NewStore added in v0.1.1

func NewStore(keyFunc KeyFunc) Store

type StoreError added in v0.1.1

type StoreError struct {
	Obj interface{}
	Err error
}

StoreError will be returned any time a Store gives an error; it includes the object at fault.

func (StoreError) Error added in v0.1.1

func (k StoreError) Error() string

Error gives a human-readable description of the error.

Directories

Path Synopsis
Package options defines log options
Package options defines log options

Jump to

Keyboard shortcuts

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