util

package
v3.2.5 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2024 License: Apache-2.0 Imports: 45 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddToWorkqueue added in v3.2.0

func AddToWorkqueue(workqueue workqueue.Interface, req *generalpb.ResourceId) (*emptypb.Empty, error)

func AppendDynamicScenariosByCategories added in v3.2.0

func AppendDynamicScenariosByCategories(
	ctx context.Context,
	scenariosList []string,
	categories []string,
	listScenariosFunc func(ctx context.Context, in *generalpb.ListOptions) (*scenariopb.ListScenariosResponse, error),
) []string

func ContainsFinalizer added in v3.2.0

func ContainsFinalizer(finalizers []string, finalizer string) bool

ContainsFinalizer checks an Object that the provided finalizer is present.

func ConvertIntMap added in v3.2.0

func ConvertIntMap[T, U IntegerType](input map[string]T) map[string]U

A function that converts an integer type T to an integer type U

func ConvertMapStruct added in v3.2.0

func ConvertMapStruct[K comparable, V any, T any](input map[string]T, getMapFunc func(T) map[K]V) map[string]map[K]V

A helper function that converts nested maps containing a struct with a map field into raw nested maps. E. g., it can convert map[string]*generalpb.StringMap to map[string]map[string]string. To make this work generic, we additionally need to pass a function which retrieves the raw map from our struct value. E. g., GetRawStringMap retrieves the raw map[string]string from *generalpb.StringMap.

func ConvertToStringMapSlice added in v3.2.0

func ConvertToStringMapSlice(stringMapSlice []*generalpb.StringMap) []map[string]string

A function that converts []*generalpb.StringMap to []map[string]string

func ConvertToStringMapStructMap added in v3.2.0

func ConvertToStringMapStructMap(in map[string]map[string]string) map[string]*generalpb.StringMap

A function that converts map[string]map[string]string to map[string]*generalpb.StringMap

func CountMachinesPerTemplateAndEnvironment

func CountMachinesPerTemplateAndEnvironment(ctx context.Context, vmClient vmpb.VMSvcClient, template string, enviroment string) (int, error)

func CountMachinesPerTemplateAndEnvironmentAndScheduledEvent

func CountMachinesPerTemplateAndEnvironmentAndScheduledEvent(ctx context.Context, vmClient vmpb.VMSvcClient, template string, enviroment string, se string) (int, error)

func DeleteHfCollection added in v3.2.0

func DeleteHfCollection(
	ctx context.Context,
	listOptions *generalpb.ListOptions,
	clientDelete HfClientDelete,
	resourceName string,
) (*emptypb.Empty, error)

func DeleteHfResource added in v3.2.0

func DeleteHfResource(
	ctx context.Context,
	req *generalpb.ResourceId,
	clientDelete HfClientDelete,
	resourceName string,
) (*emptypb.Empty, error)

func EnsureVMNotReady

func EnsureVMNotReady(hfClientset hfClientset.Interface, vmLister v1.VirtualMachineLister, vmName string, ctx context.Context) error

func FilterByCourse added in v3.2.0

func FilterByCourse(se *scheduledeventpb.ScheduledEvent, course string) bool

Specific filter function for courses

func FilterByScenario added in v3.2.0

func FilterByScenario[T ScenarioProvider](obj T, scenario string) bool

Specific filter function for scenarios

func FilterScheduledEvents added in v3.2.0

func FilterScheduledEvents(
	objId string,
	seList *scheduledeventpb.ListScheduledEventsResponse,
	filterFunc EventFilterfunc,
) []*scheduledeventpb.ScheduledEvent

Filter a ScheduledEventList to find SEs that are a) active and b) using the course/scenario specified

func FilterSessions added in v3.2.0

func FilterSessions(
	objId string,
	sessList *sessionpb.ListSessionsResponse,
	filterFunc SessionFilterfunc,
) []*sessionpb.Session

func GenKeyPair

func GenKeyPair() (string, string, error)

func GenerateResourceName

func GenerateResourceName(prefix string, input string, hashlength int) string

func GenericHfGetter added in v3.2.0

func GenericHfGetter[T metav1.Object, G HfClientGet[T], C GenericCacheRetriever[T]](
	ctx context.Context,
	req *generalpb.GetRequest,
	getter G,
	cacheGetter C,
	resourceName string,
	hasSynced bool,
) (T, error)

func GenericUnmarshal added in v3.2.0

func GenericUnmarshal[T any](rawObj string, propName string) (T, error)

func GetDurationWithDays added in v3.2.0

func GetDurationWithDays(s string) (string, error)

This Method converts a given duration into a valid duration for time.ParseDuration. time.ParseDuration does not accept "d" for days

func GetHTTPErrorCode

func GetHTTPErrorCode(httpStatus int) string

func GetLock

func GetLock(lockName string, cfg *rest.Config) (resourcelock.Interface, error)

func GetOwnerReferences added in v3.2.0

func GetOwnerReferences[T metav1.Object, G HfClientGet[T], C GenericCacheRetriever[T]](
	ctx context.Context,
	req *generalpb.GetRequest,
	getter G,
	cacheGetter C,
	resourceName string,
	hasSynced bool,
) (*generalpb.OwnerReferences, error)

func GetProtoMarshaller

func GetProtoMarshaller() protojson.MarshalOptions

func GetRawStringMap added in v3.2.0

func GetRawStringMap(val *generalpb.StringMap) map[string]string

func GetRawVMTemplateCountMap added in v3.2.0

func GetRawVMTemplateCountMap(val *scheduledeventpb.VMTemplateCountMap) map[string]uint32

func GetReleaseNamespace

func GetReleaseNamespace() string

func IsSessionOfCourse added in v3.2.0

func IsSessionOfCourse(sess *sessionpb.Session, course string) bool

Returns true if session is assigned to the provided course

func IsSessionOfScenario added in v3.2.0

func IsSessionOfScenario(sess *sessionpb.Session, scenario string) bool

Returns true if session is assigned to the provided scenario

func ListByCache added in v3.2.0

func ListByCache[T any, L GenericLister[T]](listOptions *generalpb.ListOptions, lister L, resourcename string, hasSynced bool) ([]T, error)

func ListByHfClient added in v3.2.0

func ListByHfClient[T any, L HfClientList[T]](ctx context.Context, listOptions *generalpb.ListOptions, lister L, resourcename string) (T, error)

func MaxUint32 added in v3.2.0

func MaxUint32(x, y uint32) uint32

func RandStringRunes

func RandStringRunes(n int) string

func RemoveFinalizer added in v3.2.0

func RemoveFinalizer(finalizers []string, finalizer string) []string

RemoveFinalizer accepts a slice of finalizers and removes the provided finalizer if present.

func ResourceVersionAtLeast

func ResourceVersionAtLeast(curr, min string) bool

borrowed from longhorn

func ReturnHTTPContent

func ReturnHTTPContent(w http.ResponseWriter, r *http.Request, httpStatus int, messageType string, content []byte)

func ReturnHTTPMessage

func ReturnHTTPMessage(w http.ResponseWriter, r *http.Request, httpStatus int, messageType string, message string)

func ReturnHTTPRaw

func ReturnHTTPRaw(w http.ResponseWriter, r *http.Request, content string)

func StringPtr

func StringPtr(s string) *string

func UniqueStringSlice

func UniqueStringSlice(stringSlice []string) []string

func Verify added in v3.2.0

func Verify[T metav1.Object, C GenericCacheRetriever[T]](getter C, object T, timeout time.Duration) error

func VerifyDeletion added in v3.2.0

func VerifyDeletion(ctx context.Context, clientWatch HfClientWatch, resourceId string) error

func VerifySession

func VerifySession(sLister v1.SessionLister, s *hfv1.Session) error

func VerifyTaskContent added in v3.2.0

func VerifyTaskContent(vm_tasks []hfv1.VirtualMachineTasks, request proto.Message) error

func VerifyVM

func VerifyVM(vmLister v1.VirtualMachineLister, vm *hfv1.VirtualMachine) error

func VerifyVMClaim

func VerifyVMClaim(vmClaimLister v1.VirtualMachineClaimLister, vmc *hfv1.VirtualMachineClaim) error

func VerifyVMDeleted

func VerifyVMDeleted(vmLister v1.VirtualMachineLister, vm *hfv1.VirtualMachine) error

func VerifyVMSet

func VerifyVMSet(vmSetLister v1.VirtualMachineSetLister, vms *hfv1.VirtualMachineSet) error

func VirtualMachinesUsedDuringPeriod

func VirtualMachinesUsedDuringPeriod(eventClient scheduledeventpb.ScheduledEventSvcClient, environment string, startString string, endString string, ctx context.Context) (map[time.Time]map[string]uint32, map[string]uint32, error)

Calculates available virtualMachineTemplates for a given period (startString, endString) and environment Returns a map with timestamps and corresponding availability of virtualmachines. Also returns the maximum available count of virtualmachinetemplates over the whole duration.

Types

type ByTime

type ByTime []time.Time

These functions are used to sort arrays of time.Time

func (ByTime) Len

func (t ByTime) Len() int

func (ByTime) Less

func (t ByTime) Less(i, j int) bool

func (ByTime) Swap

func (t ByTime) Swap(i, j int)

type EventFilterfunc added in v3.2.0

type EventFilterfunc func(se *scheduledeventpb.ScheduledEvent, objId string) bool

Implemented by FilterByScenario and FilterByCourse

type GenericCacheRetriever added in v3.2.0

type GenericCacheRetriever[T metav1.Object] interface {
	Get(id string) (T, error)
}

type GenericLister added in v3.2.0

type GenericLister[T any] interface {
	List(labels.Selector) ([]*T, error)
}

type HTTPContent

type HTTPContent struct {
	Type    string `json:"type"`
	Status  string `json:"status"`
	Content []byte `json:"content"`
}

type HTTPMessage

type HTTPMessage struct {
	Type    string `json:"type"`
	Status  string `json:"status"`
	Message string `json:"message"`
}

type HfClientDelete added in v3.2.0

type HfClientDelete interface {
	Delete(ctx context.Context, id string, opts metav1.DeleteOptions) error
	DeleteCollection(ctx context.Context, deleteOptions metav1.DeleteOptions, listOptions metav1.ListOptions) error
}

type HfClientGet added in v3.2.0

type HfClientGet[T metav1.Object] interface {
	Get(ctx context.Context, id string, opts metav1.GetOptions) (T, error)
}

type HfClientList added in v3.2.0

type HfClientList[T any] interface {
	List(ctx context.Context, opts metav1.ListOptions) (T, error)
}

type HfClientWatch added in v3.2.0

type HfClientWatch interface {
	Watch(ctx context.Context, opts metav1.ListOptions) (watch.Interface, error)
}

type IntegerType added in v3.2.0

type IntegerType interface {
	uint32 | int
}

type Range

type Range struct {
	Start     time.Time
	End       time.Time
	VMMapping map[string]uint32
}

Range with reserved virtual machine amounts for given time range

type ScenarioProvider added in v3.2.0

type ScenarioProvider interface {
	GetScenarios() []string
}

ScenarioProvider is an interface for any object that can provide scenarios. E. g. ScheduledEvents or Courses.

type SessionFilterfunc added in v3.2.0

type SessionFilterfunc func(se *sessionpb.Session, objId string) bool

Implemented by IsSessionOfScenario and IsSessionOfCourse

Jump to

Keyboard shortcuts

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