util

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: Apache-2.0 Imports: 41 Imported by: 18

Documentation

Index

Constants

View Source
const (
	CNRFieldNameNodeResourceProperties = "NodeResourceProperties"
	CNRFieldNameTopologyZone           = "TopologyZone"
	CNRFieldNameResources              = "Resources"
	CNRFieldNameTopologyPolicy         = "TopologyPolicy"
	CNRFieldNameNodeMetricStatus       = "NodeMetricStatus"
	CNRFieldNameAnnotations            = "Annotations"
)

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 AggregateMetrics added in v0.4.1

func AggregateMetrics(metrics []resource.Quantity, aggregator apiworkload.Aggregator) (*resource.Quantity, error)

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 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 GetExtendedIndicator added in v0.4.1

func GetExtendedIndicator(indicators interface{}) (string, runtime.Object, error)

GetExtendedIndicator get extended indicator name and object

func GetExtendedIndicatorSpec added in v0.4.1

func GetExtendedIndicatorSpec(baselinePercent *int32, indicators interface{}) (*apiworkload.ServiceExtendedIndicatorSpec, error)

GetExtendedIndicatorSpec get extended indicator spec by baseline percent and indicators. The indicators must be a pointer to a struct that has a suffix "Indicators" in its name and the indicators must be an implement of runtime.Object and use AddKnownTypes add to scheme with the same group and version as the spd

func GetLastFetchTime added in v0.4.2

func GetLastFetchTime(spd *apiworkload.ServiceProfileDescriptor) time.Time

func GetPodListForSPD

func GetPodListForSPD(spd *apiworkload.ServiceProfileDescriptor, podIndexer cache.Indexer, podLabelIndexKeyList []string,
	workloadListerMap map[schema.GroupVersionResource]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(podMeta metav1.ObjectMeta) (string, error)

GetPodSPDName gets spd name from pod annotation

func GetSPDExtendedBaselineSentinel added in v0.4.1

func GetSPDExtendedBaselineSentinel(spd *v1alpha1.ServiceProfileDescriptor) (map[string]SPDBaselinePodMeta, error)

GetSPDExtendedBaselineSentinel get the extended baseline sentinel pod of this spd

func GetSPDForPod

func GetSPDForPod(pod *core.Pod, spdIndexer cache.Indexer, workloadListerMap map[schema.GroupVersionKind]cache.GenericLister,
	spdLister workloadlister.ServiceProfileDescriptorLister, checkSPDMatchWithPod bool,
) (*apiworkload.ServiceProfileDescriptor, error)

GetSPDForPod is used to get spd that should manage the given pod, 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 GetZoneID added in v0.4.1

func GetZoneID(node ZoneNode) (int, error)

GetZoneID extracts the integer ID from a ZoneNode's Meta.Name field. It returns an error if the conversion from string to int fails.

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 InsertSPDExtendedIndicatorSpec added in v0.4.1

func InsertSPDExtendedIndicatorSpec(spec *apiworkload.ServiceProfileDescriptorSpec,
	serviceExtendedIndicatorSpec *apiworkload.ServiceExtendedIndicatorSpec,
)

func InsertSPDSystemIndicatorSpec added in v0.2.0

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

func IsBaselinePod added in v0.4.0

func IsBaselinePod(podMeta metav1.ObjectMeta, baselinePercent *int32, baselineSentinel *SPDBaselinePodMeta) (bool, error)

IsBaselinePod check whether a pod is baseline pod

func IsExtendedBaselinePod added in v0.4.1

func IsExtendedBaselinePod(podMeta metav1.ObjectMeta, baselinePercent *int32, podMetaMap map[string]SPDBaselinePodMeta, name string) (bool, error)

IsExtendedBaselinePod check whether a pod is baseline pod by extended indicator

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 MergeSiblings added in v0.4.1

func MergeSiblings(dst, src []apis.Sibling) []apis.Sibling

MergeSiblings merges two siblings, returns the merged result. If the attributes of the same sibling exists in both dst and src, the one in dst will be kept.

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 RemoveUnusedTargetConfig added in v0.4.2

func RemoveUnusedTargetConfig(configList []configapi.TargetConfig, needToDelete func(config configapi.TargetConfig) bool) []configapi.TargetConfig

RemoveUnusedTargetConfig delete those unused configurations from CNC status

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 SetLastFetchTime added in v0.4.2

func SetLastFetchTime(spd *apiworkload.ServiceProfileDescriptor, t time.Time)

func SetSPDBaselineSentinel added in v0.4.0

func SetSPDBaselineSentinel(spd *v1alpha1.ServiceProfileDescriptor, podMeta *SPDBaselinePodMeta)

SetSPDBaselineSentinel set the baseline percentile of this spd, if percentile is nil means delete it

func SetSPDExtendedBaselineSentinel added in v0.4.1

func SetSPDExtendedBaselineSentinel(spd *v1alpha1.ServiceProfileDescriptor, podMetaMap map[string]SPDBaselinePodMeta)

SetSPDExtendedBaselineSentinel set the extended baseline sentinel of this spd, if percentile is nil means delete it

func SetSPDHash added in v0.2.0

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

SetSPDHash set spd hash to spd annotation

func SetWorkloadEnableFunc added in v0.4.0

func SetWorkloadEnableFunc(f WorkloadSPDEnabledFunc)

SetWorkloadEnableFunc provides a way to set the

func VPATargetReferenceIndex

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

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

func ValidateSharedCoresWithNumaBindingPod added in v0.4.1

func ValidateSharedCoresWithNumaBindingPod(qosConf *generic.QoSConfiguration, pod *v1.Pod, zoneRequests map[ZoneNode]*v1.ResourceList) (bool, error)

ValidateSharedCoresWithNumaBindingPod is to check whether zone requests of shared_cores with numa_binding pod is valid

func WorkloadSPDEnabled added in v0.4.0

func WorkloadSPDEnabled(workload metav1.Object) bool

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 SPDBaselinePodMeta added in v0.4.0

type SPDBaselinePodMeta struct {
	TimeStamp metav1.Time `json:"timeStamp"`
	PodName   string      `json:"podName"`
}

func GetSPDBaselinePodMeta added in v0.4.1

func GetSPDBaselinePodMeta(podMeta metav1.ObjectMeta) SPDBaselinePodMeta

GetSPDBaselinePodMeta get the baseline coefficient of this pod

func GetSPDBaselineSentinel added in v0.4.0

func GetSPDBaselineSentinel(spd *v1alpha1.ServiceProfileDescriptor) (*SPDBaselinePodMeta, error)

GetSPDBaselineSentinel get the baseline sentinel pod of this spd

func (SPDBaselinePodMeta) Cmp added in v0.4.0

func (SPDBaselinePodMeta) String added in v0.4.0

func (c SPDBaselinePodMeta) String() string

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,
	siblingsMap map[ZoneNode]ZoneSiblings,
) []*nodev1alpha1.TopologyZone

GenerateTopologyZoneStatus generates topology zone status by allocations, resources and attributes

type WorkloadSPDEnabledFunc added in v0.4.0

type WorkloadSPDEnabledFunc func(metav1.Object) bool

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

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 ZoneSiblings added in v0.4.1

type ZoneSiblings []nodev1alpha1.Sibling

ZoneSiblings is list of siblings

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