util

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: Apache-2.0 Imports: 36 Imported by: 18

Documentation

Index

Constants

View Source
const (
	CNRFieldNameNodeResourceProperties = "NodeResourceProperties"
	CNRFieldNameTopologyZone           = "TopologyZone"
	CNRFieldNameResources              = "Resources"
	CNRFieldNameTopologyPolicy         = "TopologyPolicy"
)

those fields are used by in-tree reporter plugins to refer specific field names of CNR.

View Source
const (
	CNRKind = "CustomNodeResource"
)

Variables

View Source
var (
	CNRGroupVersionKind = metav1.GroupVersionKind{
		Group:   nodev1alpha1.SchemeGroupVersion.Group,
		Kind:    CNRKind,
		Version: nodev1alpha1.SchemeGroupVersion.Version,
	}
)

Functions

func AddOrUpdateCNRTaint

func AddOrUpdateCNRTaint(cnr *apis.CustomNodeResource, taint *apis.Taint) (*apis.CustomNodeResource, bool, error)

AddOrUpdateCNRTaint tries to add a taint to annotations list. Returns a new copy of updated CNR and true if something was updated false otherwise.

func CNRTaintExists

func CNRTaintExists(taints []*apis.Taint, taintToFind *apis.Taint) bool

CNRTaintExists checks if the given taint exists in list of taints. Returns true if exists false otherwise.

func CalculateSPDHash added in v0.2.0

func CalculateSPDHash(spd *apiworkload.ServiceProfileDescriptor) (string, error)

CalculateSPDHash calculate current spd hash by its spec and status

func CheckCNRConditionMatched

func CheckCNRConditionMatched(curCondition *nodev1alpha1.CNRCondition, status corev1.ConditionStatus, reason, message string) bool

CheckCNRConditionMatched checks if current CNR condition matches the update condition

func CheckPodSpecUpdated added in v0.2.0

func CheckPodSpecUpdated(pod *core.Pod) bool

CheckPodSpecUpdated checks pod spec whether is updated to expected resize resource in annotation

func CheckSPDMatchWithPod

func CheckSPDMatchWithPod(pod *core.Pod, spd *apiworkload.ServiceProfileDescriptor, workloadListerMap map[schema.GroupVersionKind]cache.GenericLister) bool

CheckSPDMatchWithPod checks whether the given pod and spd matches with each other

func CheckVPAStatusLegal

func CheckVPAStatusLegal(vpa *apis.KatalystVerticalPodAutoscaler, pods []*core.Pod) (bool, string, error)

CheckVPAStatusLegal checks following things and return a msg 1. recommended resource mustn't change pod qos class 2. recommended resource mustn't scale up in VPA 1.0 todo: remove this in VPA 2.0 3. recommended resource mustn't be negative if vpa status is illegal, we'll refuse update its status

func CheckWorkloadEnableVPA

func CheckWorkloadEnableVPA(runtimeObject runtime.Object) bool

CheckWorkloadEnableVPA is used to check whether the object enables VPA functionality

func CheckWorkloadSPDEnabled

func CheckWorkloadSPDEnabled(workload metav1.Object) bool

CheckWorkloadSPDEnabled checks if the given workload is enabled with service profiling.

func ConvertNumaEvictionRankingMetricsToStringList added in v0.3.0

func ConvertNumaEvictionRankingMetricsToStringList(metrics []v1alpha1.NumaEvictionRankingMetric) []string

func ConvertStringListToNumaEvictionRankingMetrics added in v0.3.0

func ConvertStringListToNumaEvictionRankingMetrics(metrics []string) []v1alpha1.NumaEvictionRankingMetric

func ConvertStringListToSystemEvictionRankingMetrics added in v0.3.0

func ConvertStringListToSystemEvictionRankingMetrics(metrics []string) []v1alpha1.SystemEvictionRankingMetric

func ConvertSystemEvictionRankingMetricsToStringList added in v0.3.0

func ConvertSystemEvictionRankingMetricsToStringList(metrics []v1alpha1.SystemEvictionRankingMetric) []string

func ConvertVPAContainerResourceToRecommendedContainerResources

func ConvertVPAContainerResourceToRecommendedContainerResources(resource apis.ContainerResources) apis.RecommendedContainerResources

ConvertVPAContainerResourceToRecommendedContainerResources converts apis.ContainerResources to apis.RecommendedContainerResources

func ConvertVPAContainerResourceToResourceRequirements

func ConvertVPAContainerResourceToResourceRequirements(containerResource apis.ContainerResources) core.ResourceRequirements

ConvertVPAContainerResourceToResourceRequirements converts target value in apis.ContainerResources to core.ResourceRequirements

func DeleteCNRTaint

func DeleteCNRTaint(taints []*apis.Taint, taintToDelete *apis.Taint) ([]*apis.Taint, bool)

DeleteCNRTaint removes all the taints that have the same key and effect to given taintToDelete.

func GenerateNumaSocketZone added in v0.2.0

func GenerateNumaSocketZone(nodes []info.Node) map[ZoneNode]ZoneNode

GenerateNumaSocketZone parse numa info to get the map of numa zone node to socket zone node

func GenerateVPAPodResizePolicyAnnotations

func GenerateVPAPodResizePolicyAnnotations(pod *core.Pod, containerPolicies map[string]apis.ContainerResourcePolicy) (map[string]string, error)

GenerateVPAPodResizePolicyAnnotations returns mapping from containerName to policy

func GenerateVPAPodResizeResourceAnnotations

func GenerateVPAPodResizeResourceAnnotations(pod *core.Pod, podResources map[consts.PodContainerName]apis.ContainerResources,
	containerResources map[consts.ContainerName]apis.ContainerResources) (map[string]core.ResourceRequirements, error)

GenerateVPAPodResizeResourceAnnotations returns mapping from containerName to resourceRequirements by merging the given podResources and containerResources; and podResources is always superior to containerResources

func GenerateVPAPolicyMap

GenerateVPAPolicyMap returns vpa resource policy at container-level

func GenerateVPAResourceMap

GenerateVPAResourceMap returns the map of pod resources and container resources; the returned pod resources map use GeneratePodContainerName as key, and apis.ContainerResources as value the returned container resources map use GenerateContainerName as key, and apis.ContainerResources as value

func GetCNRCondition

func GetCNRCondition(status *apis.CustomNodeResourceStatus, conditionType apis.CNRConditionType) (int, *apis.CNRCondition)

GetCNRCondition extracts the provided condition from the given status and returns that. Returns nil and -1 if the condition is not present, and the index of the located condition.

func GetPodListForSPD

func GetPodListForSPD(spd *apiworkload.ServiceProfileDescriptor, podIndexer cache.Indexer, podLabelIndexKeyList []string,
	workloadLister cache.GenericLister, podLister corelisters.PodLister) ([]*core.Pod, error)

GetPodListForSPD is used to get pods that should be managed by the given spd, we'll always get through workload

func GetPodListForVPA

func GetPodListForVPA(vpa *apis.KatalystVerticalPodAutoscaler, podIndexer cache.Indexer, podLabelIndexKeyList []string,
	workloadLister cache.GenericLister, podLister corelisters.PodLister) ([]*core.Pod, error)

GetPodListForVPA is used to get pods that should be managed by the given vpa, we'll always get through workload

func GetPodSPDName added in v0.2.0

func GetPodSPDName(pod *core.Pod) (string, error)

GetPodSPDName gets spd name from pod annotation

func GetSPDForPod

GetSPDForPod is used to get spd that should manage the given vpa, we'll try to find by annotation for pod, and then go through workload if not exist, and we will find it recursively since we don't know in which level the owner will be.

func GetSPDForVPA

GetSPDForVPA is used to get spd that matches with the workload belongs to the given vpa the preference is indexer --> GetSPDForWorkload

func GetSPDForWorkload

GetSPDForWorkload is used to get spd that should manage the given workload the preference is annotation ---> indexer --> lister

func GetSPDHash added in v0.2.0

GetSPDHash get spd hash from spd annotation

func GetServiceBusinessIndicatorTarget added in v0.2.0

func GetServiceBusinessIndicatorTarget(spd *workloadapis.ServiceProfileDescriptor) (map[string]IndicatorTarget, error)

GetServiceBusinessIndicatorTarget get service business indicator target from spd if there are duplicate upper bound or lower bound, return error

func GetServiceBusinessIndicatorValue added in v0.2.0

func GetServiceBusinessIndicatorValue(spd *workloadapis.ServiceProfileDescriptor) (map[string]float64, error)

GetServiceBusinessIndicatorValue returns the current value of business indicators The returned map is a map from indicator name to its current value, and if duplicate indicators are found, the first one is used

func GetServiceSystemIndicatorTarget added in v0.3.0

func GetServiceSystemIndicatorTarget(spd *workloadapis.ServiceProfileDescriptor) (map[string]IndicatorTarget, error)

GetServiceSystemIndicatorTarget get service system indicator target from spd if there are duplicate upper bound or lower bound, return error

func GetVPAForPod

GetVPAForPod is used to get vpa that should manage the given vpa, we'll always get through workload, and we will find it recursively since we don't know in which level the owner will be.

func GetVPAForVPARec

GetVPAForVPARec is used to get vpa that should manage the given vpaRec

func GetVPAForWorkload

GetVPAForWorkload is used to get vpa that should manage the given workload

func GetVPARecForVPA

GetVPARecForVPA is used to get vpaRec that should be managed the given vpa

func GetWorkloadForSPD

func GetWorkloadForSPD(spd *apiworkload.ServiceProfileDescriptor, lister cache.GenericLister) (runtime.Object, error)

GetWorkloadForSPD is used to get workload that should be managed the given spd

func GetWorkloadForVPA

func GetWorkloadForVPA(vpa *apis.KatalystVerticalPodAutoscaler, workloadLister cache.GenericLister) (runtime.Object, error)

GetWorkloadForVPA is used to get workload that should be managed by the given vpa

func InsertSPDBusinessIndicatorSpec added in v0.2.0

func InsertSPDBusinessIndicatorSpec(spec *apiworkload.ServiceProfileDescriptorSpec,
	serviceBusinessIndicatorSpec *apiworkload.ServiceBusinessIndicatorSpec)

func InsertSPDBusinessIndicatorStatus added in v0.2.0

func InsertSPDBusinessIndicatorStatus(status *apiworkload.ServiceProfileDescriptorStatus,
	serviceBusinessIndicatorStatus *apiworkload.ServiceBusinessIndicatorStatus)

func InsertSPDSystemIndicatorSpec added in v0.2.0

func InsertSPDSystemIndicatorSpec(spec *apiworkload.ServiceProfileDescriptorSpec,
	serviceSystemIndicatorSpec *apiworkload.ServiceSystemIndicatorSpec)

func MatchCNRTaint

func MatchCNRTaint(taintToMatch, taint *apis.Taint) bool

MatchCNRTaint checks if the taint matches taintToMatch. Taints are unique by key:effect, if the two taints have same key:effect, regard as they match.

func MergeAllocations added in v0.2.0

func MergeAllocations(dst, src []*apis.Allocation) []*apis.Allocation

MergeAllocations merges two allocations, returns the merged result. If the same allocation exists in both dst and src, the one in dst will be kept.

func MergeAttributes added in v0.2.0

func MergeAttributes(dst, src []apis.Attribute) []apis.Attribute

MergeAttributes merges two attributes, returns the merged result. If the same attribute exists in both dst and src, the one in dst will be kept.

func MergeResources added in v0.2.0

func MergeResources(dst, src apis.Resources) apis.Resources

MergeResources merges two resources, returns the merged result.

func MergeTopologyZone added in v0.2.0

func MergeTopologyZone(dst, src []*apis.TopologyZone) []*apis.TopologyZone

MergeTopologyZone merges two topology zones recursively, returns the merged result. If the same zone exists in both dst and src, the one in dst will be kept.

func RemoveCNRTaint

func RemoveCNRTaint(cnr *apis.CustomNodeResource, taint *apis.Taint) (*apis.CustomNodeResource, bool, error)

RemoveCNRTaint tries to remove a taint cnr taints. Returns a new copy of updated CNR and true if something was updated false otherwise.

func SPDTargetReferenceIndex

func SPDTargetReferenceIndex(obj interface{}) ([]string, error)

SPDTargetReferenceIndex is used to construct informer index for target reference in SPD

func SetCNRCondition

func SetCNRCondition(cnr *apis.CustomNodeResource, conditionType apis.CNRConditionType, status corev1.ConditionStatus, reason, message string, now metav1.Time)

SetCNRCondition set specific cnr condition.

func SetSPDHash added in v0.2.0

func SetSPDHash(spd *apiworkload.ServiceProfileDescriptor, hash string)

SetSPDHash set spd hash to spd annotation

func VPATargetReferenceIndex

func VPATargetReferenceIndex(obj interface{}) ([]string, error)

VPATargetReferenceIndex is used to construct informer index for target reference in VPA

Types

type IndicatorTarget added in v0.2.0

type IndicatorTarget struct {
	UpperBound *float64
	LowerBound *float64
}

type KCCTargetResource

type KCCTargetResource struct {
	*unstructured.Unstructured
}

KCCTargetResource is used to provide util function to get detailed information about KCC Target fields.

func ToKCCTargetResource

func ToKCCTargetResource(obj *unstructured.Unstructured) KCCTargetResource

func (KCCTargetResource) CheckExpired

func (g KCCTargetResource) CheckExpired(now time.Time) bool

func (KCCTargetResource) CheckValid

func (g KCCTargetResource) CheckValid() bool

func (KCCTargetResource) DeepCopy

func (g KCCTargetResource) DeepCopy() KCCTargetResource

func (KCCTargetResource) GenerateConfigHash

func (g KCCTargetResource) GenerateConfigHash() (string, error)

func (KCCTargetResource) GetCollisionCount

func (g KCCTargetResource) GetCollisionCount() *int32

func (KCCTargetResource) GetGenericStatus

func (g KCCTargetResource) GetGenericStatus() v1alpha1.GenericConfigStatus

func (KCCTargetResource) GetHash

func (g KCCTargetResource) GetHash() string

func (KCCTargetResource) GetLabelSelector

func (g KCCTargetResource) GetLabelSelector() string

func (KCCTargetResource) GetLastDuration

func (g KCCTargetResource) GetLastDuration() *time.Duration

func (KCCTargetResource) GetNodeNames

func (g KCCTargetResource) GetNodeNames() []string

func (KCCTargetResource) GetObservedGeneration

func (g KCCTargetResource) GetObservedGeneration() int64

func (KCCTargetResource) GetPriority added in v0.3.0

func (g KCCTargetResource) GetPriority() int32

func (KCCTargetResource) GetRevisionHistoryLimit

func (g KCCTargetResource) GetRevisionHistoryLimit() int64

func (KCCTargetResource) IsUpdated

func (g KCCTargetResource) IsUpdated() bool

func (KCCTargetResource) SetCollisionCount

func (g KCCTargetResource) SetCollisionCount(count *int32)

func (KCCTargetResource) SetGenericStatus

func (g KCCTargetResource) SetGenericStatus(status v1alpha1.GenericConfigStatus)

func (KCCTargetResource) SetHash

func (g KCCTargetResource) SetHash(hash string)

func (KCCTargetResource) SetObservedGeneration

func (g KCCTargetResource) SetObservedGeneration(generation int64)

func (KCCTargetResource) Unmarshal

func (g KCCTargetResource) Unmarshal(conf interface{}) error

type TopologyZoneGenerator added in v0.2.0

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

TopologyZoneGenerator is a struct that generates a tree diagram of zone, it uses AddNode to add new zone node into this tree according to its parent, and gets a list of TopologyZone by calling GenerateTopologyZoneStatus with the zone information map. TopologyZoneGenerator will be used by reporter plugin

func NewNumaSocketTopologyZoneGenerator added in v0.2.0

func NewNumaSocketTopologyZoneGenerator(numaSocketZoneNodeMap map[ZoneNode]ZoneNode) (*TopologyZoneGenerator, error)

NewNumaSocketTopologyZoneGenerator constructs topology generator by the numa zone node to socket zone node map

func NewZoneTopologyGenerator added in v0.2.0

func NewZoneTopologyGenerator() *TopologyZoneGenerator

NewZoneTopologyGenerator creates a new TopologyZoneGenerator

func (*TopologyZoneGenerator) AddNode added in v0.2.0

func (z *TopologyZoneGenerator) AddNode(parent *ZoneNode, current ZoneNode) error

AddNode adds a node to the zone tree,

  • if parent is nil, it will be added to the root topology
  • if parent is not nil, it will be added to the sub topology of the parent, the parent must already add into this generator before

func (*TopologyZoneGenerator) GenerateTopologyZoneStatus added in v0.2.0

func (z *TopologyZoneGenerator) GenerateTopologyZoneStatus(
	allocationsMap map[ZoneNode]ZoneAllocations,
	resourcesMap map[ZoneNode]nodev1alpha1.Resources,
	attributesMap map[ZoneNode]ZoneAttributes,
) []*nodev1alpha1.TopologyZone

GenerateTopologyZoneStatus generates topology zone status by allocations, resources and attributes

type ZoneAllocations added in v0.2.0

type ZoneAllocations []*nodev1alpha1.Allocation

ZoneAllocations is list of allocations

type ZoneAttributes added in v0.2.0

type ZoneAttributes []nodev1alpha1.Attribute

ZoneAttributes is list of attributes

type ZoneMeta added in v0.2.0

type ZoneMeta struct {
	Type nodev1alpha1.TopologyType
	Name string
}

ZoneMeta is a struct that contains the type and name of a zone.

type ZoneNode added in v0.2.0

type ZoneNode struct {
	Meta ZoneMeta
}

ZoneNode is a struct that contains the meta and an ID of a zone.

func GenerateDeviceZoneNode added in v0.3.3

func GenerateDeviceZoneNode(deviceId, zoneType string) ZoneNode

GenerateDeviceZoneNode generates device zone node through device id, which must be unique

func GenerateNumaZoneNode added in v0.2.0

func GenerateNumaZoneNode(numaID int) ZoneNode

GenerateNumaZoneNode generates numa zone node by numa id, which must be unique

func GenerateSocketZoneNode added in v0.2.0

func GenerateSocketZoneNode(socketID int) ZoneNode

GenerateSocketZoneNode generates socket zone node by socket id, which must be unique

type ZoneTopology added in v0.2.0

type ZoneTopology struct {
	Children map[ZoneNode]*ZoneTopology
}

ZoneTopology is a tree diagram of a zone

func NewZoneTopology added in v0.2.0

func NewZoneTopology() *ZoneTopology

Jump to

Keyboard shortcuts

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