simutil

package
v0.0.0-...-7916917 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorEncapsulatingPanic = errors.New("panic has occurred")

ErrorEncapsulatingPanic is a sentinel error indicating that there has been a panic which has been captured as an error and returned as value.

Functions

func AdjustPods

func AdjustPods(pods []corev1.Pod) []corev1.Pod

func ApplyDsPodsToNodes

func ApplyDsPodsToNodes(ctx context.Context, v scalesim.VirtualClusterAccess, dsPods []corev1.Pod) error

func AsJson

func AsJson(nodePodAssignments []scalesim.NodePodAssignment) (string, error)

func ComparePriceDescending

func ComparePriceDescending(n1, n2 corev1.Node) int

func ComputeNodeWaste

func ComputeNodeWaste(node *corev1.Node, pods []corev1.Pod) resource.Quantity

func CreateNodeInWorkerGroup

func CreateNodeInWorkerGroup(ctx context.Context, a scalesim.VirtualClusterAccess, wg *v1beta1.Worker) (*corev1.Node, error)

CreateNodeInWorkerGroup creates a sample node if the passed workerGroup objects max has not been met

func CreateNodeInWorkerGroupForZone

func CreateNodeInWorkerGroupForZone(ctx context.Context, a scalesim.VirtualClusterAccess, zone, region string, wg *v1beta1.Worker) (bool, error)

func CreateNodesTillPoolMax

func CreateNodesTillPoolMax(ctx context.Context, a scalesim.VirtualClusterAccess, wg *v1beta1.Worker) (int, error)

CreateNodesTillPoolMax creates sample nodes in the given worker pool till the worker pool max is reached.

func CreateNodesTillZonexPoolMax

func CreateNodesTillZonexPoolMax(ctx context.Context, a scalesim.VirtualClusterAccess, region string, wg *v1beta1.Worker) error

CreateNodesTillZonexPoolMax creates sample nodes in the given worker pool till the worker pool max is reached.

func DeleteAssignedPods

func DeleteAssignedPods(unscheduledPods []corev1.Pod, allAssignedPods []corev1.Pod) []corev1.Pod

func DeleteNodeAndPods

func DeleteNodeAndPods(ctx context.Context, w http.ResponseWriter, access scalesim.VirtualClusterAccess, node *corev1.Node, pods []corev1.Pod) error

func DeleteNodeAndResetPods

func DeleteNodeAndResetPods(ctx context.Context, a scalesim.VirtualClusterAccess, nodeName string, podListForRun []corev1.Pod) ([]corev1.Pod, time.Time, error)

func EmptyOr

func EmptyOr(val string, defaultVal string) string

func GenerateRandomString

func GenerateRandomString(length int) (string, error)

func GetAllAssignedPods

func GetAllAssignedPods(ctx context.Context, a scalesim.VirtualClusterAccess) ([]corev1.Pod, error)

func GetFailedSchedulingEvents

func GetFailedSchedulingEvents(ctx context.Context, a scalesim.VirtualClusterAccess, since time.Time) ([]corev1.Event, error)

GetFailedSchedulingEvents get all FailedSchedulingEvents whose referenced pod does not have a node assigned FIXME: This should take a since time.Time which is the scenario start time.

func GetMatchingPods

func GetMatchingPods(allPods []corev1.Pod, filterPods []corev1.Pod) []corev1.Pod

func GetPodSchedulingEvents

func GetPodSchedulingEvents(ctx context.Context, vca scalesim.VirtualClusterAccess, podNames []string, since time.Time) ([]corev1.Event, error)

func GetPodsAssignedToNode

func GetPodsAssignedToNode(ctx context.Context, a scalesim.VirtualClusterAccess, nodeName string) ([]corev1.Pod, error)

func GetPodsOnNode

func GetPodsOnNode(ctx context.Context, virtualAccess scalesim.VirtualClusterAccess, nodeName string) ([]corev1.Pod, error)

func GetUnscheduledPodCount

func GetUnscheduledPodCount(ctx context.Context, access scalesim.VirtualClusterAccess) (int, error)

func IsExistingNode

func IsExistingNode(n *corev1.Node) bool

func LogError

func LogError(w http.ResponseWriter, scenarioName string, err error)

func PodNames

func PodNames(pods []corev1.Pod) []string

func RunConcurrently

func RunConcurrently(ctx context.Context, tasks []Task, bound int) []error

RunConcurrently runs tasks concurrently with number of goroutines bounded by bound. If there is a panic executing a single Task then it will capture the panic and capture it as an error which will then subsequently be returned from this function. It will not propagate the panic causing the app to exit.

func WaitAndGetUnscheduledPodCount

func WaitAndGetUnscheduledPodCount(ctx context.Context, access scalesim.VirtualClusterAccess, waitSec int) (int, error)

func WaitForAndRecordPodSchedulingEvents

func WaitForAndRecordPodSchedulingEvents(ctx context.Context, vca scalesim.VirtualClusterAccess, w http.ResponseWriter, since time.Time, pods []corev1.Pod, timeout time.Duration) (scheduledPodNames sets.Set[string], unscheduledPodNames sets.Set[string], err error)

func WaitTillNoUnscheduledPodsOrTimeout

func WaitTillNoUnscheduledPodsOrTimeout(ctx context.Context, access scalesim.VirtualClusterAccess, timeout time.Duration, since time.Time) (int, error)

Types

type PodBuilder

type PodBuilder struct {
	// contains filtered or unexported fields
}

func NewPodBuilder

func NewPodBuilder() *PodBuilder

func (*PodBuilder) AddLabels

func (p *PodBuilder) AddLabels(labels map[string]string) *PodBuilder

func (*PodBuilder) Build

func (p *PodBuilder) Build() (*corev1.Pod, error)

func (*PodBuilder) GenerateName

func (p *PodBuilder) GenerateName(generateName string) *PodBuilder

func (*PodBuilder) Name

func (p *PodBuilder) Name(name string) *PodBuilder

func (*PodBuilder) Namespace

func (p *PodBuilder) Namespace(namespace string) *PodBuilder

func (*PodBuilder) NodeName

func (p *PodBuilder) NodeName(nodeName string) *PodBuilder

func (*PodBuilder) RequestCPU

func (p *PodBuilder) RequestCPU(quantity string) *PodBuilder

func (*PodBuilder) RequestMemory

func (p *PodBuilder) RequestMemory(quantity string) *PodBuilder

func (*PodBuilder) SchedulerName

func (p *PodBuilder) SchedulerName(schedulerName string) *PodBuilder

func (*PodBuilder) TopologySpreadConstraint

func (p *PodBuilder) TopologySpreadConstraint(topologyKey *string, maxSkew *int, labels map[string]string) *PodBuilder

type RunGroup

type RunGroup struct {
	// contains filtered or unexported fields
}

RunGroup is a runner for concurrently spawning multiple asynchronous tasks. If any task errors or panics then these are captured as errors.

func NewRunGroup

func NewRunGroup(numTasks, bound int) *RunGroup

NewRunGroup creates a new RunGroup.

func (*RunGroup) Close

func (g *RunGroup) Close()

Close closes the RunGroup

func (*RunGroup) WaitAndCollectErrors

func (g *RunGroup) WaitAndCollectErrors() []error

WaitAndCollectErrors waits for all tasks to finish, collects and returns any errors.

type Task

type Task struct {
	// Name is the name of the task
	Name string
	// Fn is the function which accepts a context and returns an error if there is one.
	// Implementations of Fn should handle context cancellation properly.
	Fn func(ctx context.Context) error
}

Task is a holder for a named function.

Jump to

Keyboard shortcuts

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