utils

package
v0.0.0-...-f2569be Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2023 License: Apache-2.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResourceMilliCpu = "MilliCpuLeft"
	ResourceMemory   = "Memory"
	ResourceGpu      = "Gpu"
	ResourceMilliGpu = "MilliGpu"
)
View Source
const (
	//ColorReset  = "\033[0m"
	ColorReset = ""
	//ColorRed    = "\033[31m"
	ColorRed = ""
	//ColorGreen  = "\033[32m"
	ColorGreen = ""
	//ColorYellow = "\033[33m"
	ColorYellow = ""
	//ColorCyan   = "\033[36m"
	ColorCyan = ""

	// open-local storage class names
	OpenLocalSCNameLVM           = "open-local-lvm"
	OpenLocalSCNameDeviceHDD     = "open-local-device-hdd"
	OpenLocalSCNameDeviceSSD     = "open-local-device-ssd"
	OpenLocalSCNameMountPointHDD = "open-local-mountpoint-hdd"
	OpenLocalSCNameMountPointSSD = "open-local-mountpoint-ssd"

	// yoda storage class names
	YodaSCNameLVM           = "yoda-lvm-default"
	YodaSCNameDeviceHDD     = "yoda-device-hdd"
	YodaSCNameDeviceSSD     = "yoda-device-ssd"
	YodaSCNameMountPointHDD = "yoda-mountpoint-hdd"
	YodaSCNameMountPointSSD = "yoda-mountpoint-ssd"
)
View Source
const (
	Q1LackBoth  = "q1_lack_both"
	Q2LackGpu   = "q2_lack_gpu"
	Q3Satisfied = "q3_satisfied"
	Q4LackCpu   = "q4_lack_cpu"
	XLSatisfied = "xl_satisfied"
	XRLackCPU   = "xr_lack_cpu"
	NoAccess    = "no_access"
)

Variables

View Source
var FragRatioDataMap = map[string]int{
	Q1LackBoth:  0,
	Q2LackGpu:   1,
	Q3Satisfied: 2,
	Q4LackCpu:   3,
	XLSatisfied: 4,
	XRLackCPU:   5,
	NoAccess:    6,
}
View Source
var GpuNumTypeList = []string{"PureCpu", "ShareGpu", "OneGpu", "TwoGpu", "FourGpu", "EightGpu", "Others"}

Functions

func AddWorkloadInfoToPod

func AddWorkloadInfoToPod(pod *corev1.Pod, kind string, name string, namespace string) *corev1.Pod

AddWorkloadInfoToPod add annotation in pod for simulating later

func AdjustNodesOrder

func AdjustNodesOrder(nodes []string) []string

func AdjustWorkloads

func AdjustWorkloads(workloads map[string][]string)

func CalculateL2NormDiff

func CalculateL2NormDiff(vec1, vec2 []float64) (l2norm float64)

func CalculateL2NormRatio

func CalculateL2NormRatio(vec1, vec2 []float64) (l2norm float64)

func CalculateVectorCosineSimilarity

func CalculateVectorCosineSimilarity(vec1, vec2 []float64) float64

CalculateVectorCosineSimilarity returns value in range [0, 1] or -1 (error)

func CalculateVectorDotProduct

func CalculateVectorDotProduct(vec1, vec2 []float64) (innerProduct float64)

func CanNodeHostPodOnGpuMemory

func CanNodeHostPodOnGpuMemory(nodeRes simontype.NodeResource, podRes simontype.PodResource) bool

func CreateKubeClient

func CreateKubeClient(kubeconfig string) (*clientset.Clientset, error)

func DecodeYamlContent

func DecodeYamlContent(yamlRes []byte) ([]runtime.Object, error)

DecodeYamlContent captures the yml or yaml file, and decodes it

func ExportNodeStatusToCsv

func ExportNodeStatusToCsv(nodeStatus []simontype.NodeStatus, filePath string) error

func GeneratePodKey

func GeneratePodKey(pod *corev1.Pod) string

func GeneratePodKeyByName

func GeneratePodKeyByName(namespace, name string) string

func GenerateSchedulingMatchGroups

func GenerateSchedulingMatchGroups(nodeRes simontype.NodeResource, podRes simontype.PodResource,
	gpuDimExtMethod simontype.GpuDimExtMethod, normMethod simontype.NormMethod) (matchGroups []simontype.SchedulingMatchGroup)

func GetAllPodsPtrFromNodeStatus

func GetAllPodsPtrFromNodeStatus(nodeStatus []simontype.NodeStatus) []*corev1.Pod

func GetAllocatablePodList

func GetAllocatablePodList(clientset externalclientset.Interface) []corev1.Pod

func GetGpuFragMilliByNodeResAndPodRes

func GetGpuFragMilliByNodeResAndPodRes(nodeRes simontype.NodeResource, podRes simontype.PodResource) int64

func GetGpuMilliLeftTotal

func GetGpuMilliLeftTotal(nodeRes simontype.NodeResource) (gpuMilliLeftTotal int64)

func GetGpuNodeInfoFromAnnotation

func GetGpuNodeInfoFromAnnotation(node *corev1.Node) (*gpusharecache.GpuNodeInfoStr, error)

func GetMasterFromKubeConfig

func GetMasterFromKubeConfig(filename string) (string, error)

func GetNodeAllocMap

func GetNodeAllocMap(nodeStatus []simontype.NodeStatus) (map[string]AllocAmount, error)

func GetNodeAllocatable

func GetNodeAllocatable(node *corev1.Node) (resource.Quantity, resource.Quantity)

func GetNodeAllocatableCpuGpu

func GetNodeAllocatableCpuGpu(node *corev1.Node) []float64

func GetNodeCache

func GetNodeCache(node *corev1.Node) (*localcache.NodeCache, error)

func GetNodePodFrag

func GetNodePodFrag(nodeRes simontype.NodeResource, podRes simontype.PodResource) string

func GetNodeResourceAndPodResourceViaHandle

func GetNodeResourceAndPodResourceViaHandle(p *corev1.Pod, nodeName string, handle framework.Handle) (nodeResPtr *simontype.NodeResource, podResPtr *simontype.PodResource)

func GetNodeResourceMap

func GetNodeResourceMap(nodeStatus []simontype.NodeStatus) map[string]simontype.NodeResource

func GetNodeResourceViaHandleAndName

func GetNodeResourceViaHandleAndName(handle framework.Handle, nodeName string) (nodeRes *simontype.NodeResource)

func GetNodeResourceViaNodeInfo

func GetNodeResourceViaNodeInfo(nodeInfo *framework.NodeInfo) (nodeRes *simontype.NodeResource)

func GetNodeResourceViaPodList

func GetNodeResourceViaPodList(podList []*corev1.Pod, node *corev1.Node) (nodeRes *simontype.NodeResource)

func GetObjectHashCodeDigit

func GetObjectHashCodeDigit(isPod bool) int

func GetPodResource

func GetPodResource(pod *corev1.Pod) simontype.PodResource

func GetPodsPtrFromPods

func GetPodsPtrFromPods(pods []corev1.Pod) (podsPtr []*corev1.Pod)

func GetPodsTotalRequestsAndLimitsByNodeName

func GetPodsTotalRequestsAndLimitsByNodeName(pods []*corev1.Pod, nodeName string) (map[corev1.ResourceName]resource.Quantity, map[corev1.ResourceName]resource.Quantity)

func GetResourceSimilarity

func GetResourceSimilarity(nodeRes simontype.NodeResource, podRes simontype.PodResource) float64

func GetSHA256HashCode

func GetSHA256HashCode(message []byte, num int) string

func GetSkylinePods

func GetSkylinePods(allPods []*v1.Pod) (skylinePods simontype.SkylinePodList)

func GetTypicalPods

func GetTypicalPods(allPods []*v1.Pod, config v1alpha1.TypicalPodsConfig) simontype.TargetPodList

func GetYamlContentFromDirectory

func GetYamlContentFromDirectory(dir string) ([]string, error)

GetYamlContentFromDirectory returns the yaml content and ignores other content

func IsNodeAccessibleToPod

func IsNodeAccessibleToPod(nodeRes simontype.NodeResource, podRes simontype.PodResource) bool

func IsNodeAccessibleToPodByType

func IsNodeAccessibleToPodByType(nodeGpuType string, podGpuType string) bool

func MakeValidNodeByNode

func MakeValidNodeByNode(node *corev1.Node, nodename string) (*corev1.Node, error)

func MakeValidPod

func MakeValidPod(oldPod *corev1.Pod) (*corev1.Pod, error)

MakeValidPod make pod valid, so we can handle it

func MakeValidPodByCronJob

func MakeValidPodByCronJob(cronjob *batchv1beta1.CronJob) ([]*corev1.Pod, error)

func MakeValidPodByJob

func MakeValidPodByJob(job *batchv1.Job) ([]*corev1.Pod, error)

func MakeValidPodByPod

func MakeValidPodByPod(pod *corev1.Pod) (*corev1.Pod, error)

func MakeValidPodsByDaemonset

func MakeValidPodsByDaemonset(ds *appsv1.DaemonSet, nodes []*corev1.Node) ([]*corev1.Pod, error)

func MakeValidPodsByDeployment

func MakeValidPodsByDeployment(deploy *appsv1.Deployment) ([]*corev1.Pod, error)

func MakeValidPodsByReplicaSet

func MakeValidPodsByReplicaSet(rs *appsv1.ReplicaSet) ([]*corev1.Pod, error)

func MakeValidPodsByReplicationController

func MakeValidPodsByReplicationController(rc *corev1.ReplicationController) ([]*corev1.Pod, error)

func MakeValidPodsByStatefulSet

func MakeValidPodsByStatefulSet(ss *appsv1.StatefulSet) ([]*corev1.Pod, error)

func MeetResourceRequests

func MeetResourceRequests(node *corev1.Node, pod *corev1.Pod, daemonSets []*appsv1.DaemonSet) (bool, error)

func MultiplyMilliQuant

func MultiplyMilliQuant(quant resource.Quantity, factor float64) resource.Quantity

MultiplyMilliQuant scales quantity by factor

func MultiplyQuant

func MultiplyQuant(quant resource.Quantity, factor float64) resource.Quantity

MultiplyQuant scales quantity by factor

func NewDaemonPod

func NewDaemonPod(ds *appsv1.DaemonSet, nodeName string) (*corev1.Pod, error)

func NodeGpuFragBasedOnSkyline

func NodeGpuFragBasedOnSkyline(nodeRes simontype.NodeResource, skylinePods simontype.SkylinePodList) int64

func NodeGpuFragBellman

func NodeGpuFragBellman(nodeRes simontype.NodeResource, typicalPods simontype.TargetPodList, dp *sync.Map, cumProb float64) float64

func NodeGpuShareFragAmountScore

func NodeGpuShareFragAmountScore(nodeRes simontype.NodeResource, typicalPods simontype.TargetPodList) float64

func NodeShouldRunPod

func NodeShouldRunPod(node *corev1.Node, pod *corev1.Pod) bool

NodeShouldRunPod determines whether a node should run a pod according to scheduling rules

func NormalizeVector

func NormalizeVector(vec []float64, normVec []float64) []float64

func ParseFilePath

func ParseFilePath(path string) (filePaths []string, err error)

ParseFilePath converts recursively directory path to a slice of file paths

func PodListRatioSum

func PodListRatioSum(tpl simontype.TargetPodList) (cumRatio float64)

func ReadJsonFile

func ReadJsonFile(path string) []byte

func ReadYamlFile

func ReadYamlFile(path string) []byte

func RemovePodFromPodSliceByPod

func RemovePodFromPodSliceByPod(pods []*corev1.Pod, pod *corev1.Pod) []*corev1.Pod

func ReportFailedPods

func ReportFailedPods(fp []simontype.UnscheduledPod)

func SetDaemonSetPodNodeNameByNodeAffinity

func SetDaemonSetPodNodeNameByNodeAffinity(affinity *corev1.Affinity, nodename string) *corev1.Affinity

func SetObjectMetaFromObject

func SetObjectMetaFromObject(owner metav1.Object, genPod bool) metav1.ObjectMeta

func SetStorageAnnotationOnPods

func SetStorageAnnotationOnPods(pods []*corev1.Pod, volumeClaimTemplates []corev1.PersistentVolumeClaim, stsName string) error

func SortTargetPodInDecreasingCount

func SortTargetPodInDecreasingCount(tgtPodResMap map[simontype.PodResource]float64) simontype.TargetPodList

func ValidateNode

func ValidateNode(node *corev1.Node) error

ValidateNode check if node is valid

func ValidatePod

func ValidatePod(pod *corev1.Pod) error

ValidatePod check if pod is valid

Types

type AllocAmount

type AllocAmount struct {
	NodeName    string
	Requested   map[string]int64
	Allocatable map[string]int64
}

func (AllocAmount) Add

func (a AllocAmount) Add(b AllocAmount) error

type FragAmount

type FragAmount struct {
	NodeName string
	Data     []float64
}

func GetFragAmountByNodeResAndFragRatio

func GetFragAmountByNodeResAndFragRatio(nodeRes simontype.NodeResource, fragRatio FragRatio) FragAmount

func NewFragAmount

func NewFragAmount(nodeName string, data []float64) FragAmount

func NodeGpuFragAmount

func NodeGpuFragAmount(nodeRes simontype.NodeResource, typicalPods simontype.TargetPodList) FragAmount

NodeGpuFragAmount is deprecated. Use NodeGpuShareFragAmount instead.

func NodeGpuShareFragAmount

func NodeGpuShareFragAmount(nodeRes simontype.NodeResource, typicalPods simontype.TargetPodList) FragAmount

func (FragAmount) AddByFragType

func (fa FragAmount) AddByFragType(fragType string, amount float64) error

func (FragAmount) AddFragAmount

func (fa FragAmount) AddFragAmount(faOther FragAmount) error

func (FragAmount) AddGamma

func (fa FragAmount) AddGamma(faOther FragAmount, gamma float64) error

func (FragAmount) FragAmountSumExceptQ3

func (fa FragAmount) FragAmountSumExceptQ3() (out float64)

func (FragAmount) FragAmountSumQ1Q2Q4

func (fa FragAmount) FragAmountSumQ1Q2Q4() (out float64)

func (FragAmount) Repr

func (fa FragAmount) Repr() (outStr string)

type FragRatio

type FragRatio struct {
	Data []float64
}

func NodeGpuFragRatio

func NodeGpuFragRatio(nodeRes simontype.NodeResource, typicalPods simontype.TargetPodList) FragRatio

func (FragRatio) AddRatio

func (fr FragRatio) AddRatio(fragType string, freq float64) error

func (FragRatio) FragRatioSumExceptQ3

func (fr FragRatio) FragRatioSumExceptQ3() (out float64)

func (FragRatio) Repr

func (fr FragRatio) Repr() (outStr string)

type NodeQueue

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

func NewNodeQueue

func NewNodeQueue(nodes []string) *NodeQueue

func (*NodeQueue) Len

func (queue *NodeQueue) Len() int

func (*NodeQueue) Less

func (queue *NodeQueue) Less(i, j int) bool

func (*NodeQueue) Swap

func (queue *NodeQueue) Swap(i, j int)

type NodeStorage

type NodeStorage struct {
	VGs     []localcache.SharedResource    `json:"vgs"`
	Devices []localcache.ExclusiveResource `json:"devices"`
}

func GetNodeStorage

func GetNodeStorage(node *corev1.Node) (*NodeStorage, error)

type ResourceSummary

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

func ReportNodeAllocationRate

func ReportNodeAllocationRate(aamap map[string]AllocAmount) (rs []ResourceSummary)

type Volume

type Volume struct {
	Size int64 `json:"size,string"`
	// Kind 可以是 LVM 或 HDD 或 SSD
	// HDD 和 SSD 均指代独占盘
	Kind             string `json:"kind"`
	StorageClassName string `json:"scName"`
}

type VolumeRequest

type VolumeRequest struct {
	Volumes []Volume `json:"volumes"`
}

func GetPodStorage

func GetPodStorage(pod *corev1.Pod) *VolumeRequest

Jump to

Keyboard shortcuts

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