Documentation ¶
Index ¶
- Constants
- Variables
- func AlmostEqual(a, b float64) bool
- func Bool2Int32(b bool) int32
- func Bool2Uint(b bool) uint
- func BuildZoneName(nodeID int) string
- func CalculatePodRequests(pods []v1.Pod, resource v1.ResourceName) (int64, error)
- func CalculatePodTemplateRequests(podTemplate *v1.PodTemplateSpec, resource v1.ResourceName) (int64, error)
- func CmpFloat(p1, p2 float64) int32
- func ContainMaps(a map[string]string, b map[string]string) bool
- func ContainsString(slice []string, str string) bool
- func EvictPodWithGracePeriod(client clientset.Interface, pod *v1.Pod, gracePeriodSeconds *int32) error
- func ExpandSlice(slice string) (string, error)
- func GetAddressAndDialer(endpoint string) (string, func(ctx context.Context, addr string) (net.Conn, error), error)
- func GetAvailablePods(pods []v1.Pod) []v1.Pod
- func GetCgroupPath(p *v1.Pod, cgroupDriver string) string
- func GetContainerCpuUsageExpression(namespace string, workloadName string, kind string, containerName string) string
- func GetContainerExtCpuResFromPod(pod *v1.Pod, containerName string) (resource.Quantity, bool)
- func GetContainerExtMemResFromPod(pod *v1.Pod, containerName string) (resource.Quantity, bool)
- func GetContainerFromPod(pod *v1.Pod, containerName string) *v1.Container
- func GetContainerIdFromKey(key string) string
- func GetContainerIdFromPod(pod *v1.Pod, containerName string) string
- func GetContainerMemUsageExpression(namespace string, workloadName string, kind string, containerName string) string
- func GetContainerNameFromPod(pod *v1.Pod, containerId string) string
- func GetContainerStatus(pod *v1.Pod, container v1.Container) v1.ContainerState
- func GetCronMetricName() string
- func GetCustomerExpression(metricName string, labels string) string
- func GetDaemonSetPods(kubeClient client.Client, namespace string, name string) ([]corev1.Pod, error)
- func GetEHPAFromScaleTarget(context context.Context, kubeClient client.Client, namespace string, ...) (*autoscalingapi.EffectiveHorizontalPodAutoscaler, error)
- func GetEVPAFromScaleTarget(context context.Context, kubeClient client.Client, namespace string, ...) (*autoscalingapi.EffectiveVerticalPodAutoscaler, error)
- func GetElasticResourceLimit(pod *v1.Pod, resName v1.ResourceName) (amount int64)
- func GetExpressionQueryAnnotation(metricIdentifier string, annotations map[string]string) string
- func GetExpressionQueryDefault(metric autoscalingv2.MetricSpec, namespace string, name string, kind string) string
- func GetExtCpuRes(container v1.Container) (resource.Quantity, bool)
- func GetExtMemRes(container v1.Container) (resource.Quantity, bool)
- func GetGroupVersionResource(discoveryClient discovery.DiscoveryInterface, apiVersion string, kind string) (*schema.GroupVersionResource, error)
- func GetHPAFromScaleTarget(context context.Context, kubeClient client.Client, namespace string, ...) (*autoscalingv2.HorizontalPodAutoscaler, error)
- func GetInt32withDefault(i *int32, value int32) int32
- func GetInt64withDefault(i *int64, value int64) int64
- func GetKubeletConfig(ctx context.Context, c kubeclient.Interface, hostname string) (*kubeletconfiginternal.KubeletConfiguration, error)
- func GetMetricIdentifier(metric autoscalingv2.MetricSpec, name string) string
- func GetNodeCpuUsageExpression(nodeName string) string
- func GetNodeMemUsageExpression(nodeName string) string
- func GetNodePods(kubeClient client.Client, nodeName string) ([]corev1.Pod, error)
- func GetNodeRef(nodeName string) *v1.ObjectReference
- func GetPodCgroupNameSuffix(podUID types.UID) string
- func GetPodCondition(status *v1.PodStatus, conditionType v1.PodConditionType) (int, *v1.PodCondition)
- func GetPodContainerByName(pod *v1.Pod, containerName string) (v1.Container, error)
- func GetPodCpuUsageExpression(namespace string, name string) string
- func GetPodMemUsageExpression(namespace string, name string) string
- func GetPodNameReg(resourceName string, resourceType string) string
- func GetPodReadyCondition(status v1.PodStatus) *v1.PodCondition
- func GetPodTemplate(context context.Context, namespace string, name string, kind string, ...) (*v1.PodTemplateSpec, error)
- func GetPodsFromScale(kubeClient client.Client, scale *autoscalingapiv1.Scale) ([]v1.Pod, error)
- func GetPredictionMetricName(sourceType autoscalingv2.MetricSourceType) (metricName string)
- func GetReadyPredictionMetric(metric string, resourceIdentifier string, ...) (*predictionapi.MetricTimeSeries, error)
- func GetRecommendationRuleOwnerReference(recommend *analysisv1alpha1.Recommendation) *metav1.OwnerReference
- func GetReservedCPUs(cpus string) (cpuset.CPUSet, error)
- func GetResourceByPodTemplate(podTemplate *corev1.PodTemplateSpec, containerName string) (*corev1.ResourceRequirements, bool)
- func GetRunNumber(recommendation *analysisv1alpha1.Recommendation) (int32, error)
- func GetScale(ctx context.Context, restMapper meta.RESTMapper, ...) (*autoscalingapiv1.Scale, *meta.RESTMapping, error)
- func GetScaleFromObjectReference(ctx context.Context, restMapper meta.RESTMapper, ...) (*autoscalingapiv1.Scale, *meta.RESTMapping, error)
- func GetUint32withDefault(i *uint32, value uint32) uint32
- func GetUint64FromMaps(key string, maps map[string]uint64) uint64
- func GetUint64withDefault(i *uint64, value uint64) uint64
- func GetWorkloadCpuUsageExpression(namespace string, name string, kind string) string
- func GetWorkloadMemUsageExpression(namespace string, name string, kind string) string
- func Int32P(value int32) *int32
- func IsCPUResourceEqual(oldResource, desiredResource corev1.ResourceList) bool
- func IsEHPACronEnabled(ehpa *autoscalingapi.EffectiveHorizontalPodAutoscaler) bool
- func IsEHPAHasPredictionMetric(ehpa *autoscalingapi.EffectiveHorizontalPodAutoscaler) bool
- func IsEHPAPredictionEnabled(ehpa *autoscalingapi.EffectiveHorizontalPodAutoscaler) bool
- func IsEqual(oldResource, desiredResource *corev1.ResourceRequirements) bool
- func IsExpressionQueryAnnotationEnabled(metricIdentifier string, annotations map[string]string) bool
- func IsHPAControlledByEHPA(hpa *autoscalingv2.HorizontalPodAutoscaler) bool
- func IsMemoryResourceEqual(oldResource, desiredResource corev1.ResourceList) bool
- func IsNodeAwareOfTopology(attr map[string]string) *bool
- func IsPodAvailable(pod *v1.Pod, minReadySeconds int32, now metav1.Time) bool
- func IsPodReady(pod *v1.Pod) bool
- func IsPodTerminated(pod *corev1.Pod) bool
- func IsRecommendationControlledByRule(recommend *analysisv1alpha1.Recommendation) bool
- func IsResourceEqual(oldResource, desiredResource corev1.ResourceList) bool
- func KindForResource(resource string, restMapper meta.RESTMapper) (string, error)
- func LabelSelectorMatched(maps map[string]string, selector *metav1.LabelSelector) (bool, error)
- func MapSortToArray(m map[string]string) []string
- func ParseDuration(s string) (time.Duration, error)
- func ParseFloat(str string, defaultValue float64) (float64, error)
- func ParsePercentage(input string) (float64, error)
- func ParseTimestamp(ts string) (time.Time, error)
- func PodExcludeReservedCPUs(pod *corev1.Pod) bool
- func QueryPredictedTimeSeriesOnce(predictor prediction.Interface, caller string, pConfig *config.Config, ...) ([]*common.TimeSeries, error)
- func QueryPredictedValues(predictor prediction.Interface, caller string, pConfig *config.Config, ...) ([]*common.TimeSeries, error)
- func QueryPredictedValuesOnce(recommendation *v1alpha1.Recommendation, predictor prediction.Interface, ...) ([]*common.TimeSeries, error)
- func RemoveNodeTaints(client clientset.Interface, nodeLister corelisters.NodeLister, nodeName string, ...) (*v1.Node, error)
- func RemoveString(slice []string, str string) []string
- func SetRunNumber(recommendation *analysisv1alpha1.Recommendation, runNumber int32)
- func StringPtr(str string) *string
- func Uint32P(value uint32) *uint32
- func Uint64P(value uint64) *uint64
- func UpdateNodeConditionsStatues(client clientset.Interface, nodeLister corelisters.NodeLister, nodeName string, ...) (*v1.Node, error)
- func UpdateNodeTaints(client clientset.Interface, nodeLister corelisters.NodeLister, nodeName string, ...) (*v1.Node, error)
- type CgroupName
- type SortMap
- type SortMaps
Constants ¶
const ( // WorkloadCpuUsageExprTemplate is used to query workload cpu usage by promql, param is namespace,workload-name,duration str WorkloadCpuUsageExprTemplate = `sum(irate(container_cpu_usage_seconds_total{namespace="%s",pod=~"%s",container!=""}[%s]))` // WorkloadMemUsageExprTemplate is used to query workload mem usage by promql, param is namespace, workload-name WorkloadMemUsageExprTemplate = `sum(container_memory_working_set_bytes{namespace="%s",pod=~"%s",container!=""})` // following is node exporter metric for node cpu/memory usage // NodeCpuUsageExprTemplate is used to query node cpu usage by promql, param is node name which prometheus scrape, duration str NodeCpuUsageExprTemplate = `` /* 166-byte string literal not displayed */ // NodeMemUsageExprTemplate is used to query node cpu memory by promql, param is node name, node name which prometheus scrape NodeMemUsageExprTemplate = `sum(node_memory_MemTotal_bytes{instance=~"(%s)(:\\d+)?"} - node_memory_MemAvailable_bytes{instance=~"(%s)(:\\d+)?"})` // PodCpuUsageExprTemplate is used to query pod cpu usage by promql, param is namespace,pod, duration str PodCpuUsageExprTemplate = `sum(irate(container_cpu_usage_seconds_total{container!="POD",namespace="%s",pod="%s"}[%s]))` // PodMemUsageExprTemplate is used to query pod cpu usage by promql, param is namespace,pod PodMemUsageExprTemplate = `sum(container_memory_working_set_bytes{container!="POD",namespace="%s",pod="%s"})` // ContainerCpuUsageExprTemplate is used to query container cpu usage by promql, param is namespace,pod,container duration str ContainerCpuUsageExprTemplate = `irate(container_cpu_usage_seconds_total{container!="POD",namespace="%s",pod=~"%s",container="%s"}[%s])` // ContainerMemUsageExprTemplate is used to query container cpu usage by promql, param is namespace,pod,container ContainerMemUsageExprTemplate = `container_memory_working_set_bytes{container!="POD",namespace="%s",pod=~"%s",container="%s"}` CustomerExprTemplate = `sum(%s{%s})` )
todo: later we change these templates to configurable like prometheus-adapter
const ( PostRegMatchesPodDeployment = `[a-z0-9]+-[a-z0-9]{5}$` PostRegMatchesPodReplicaset = `[a-z0-9]+$` PostRegMatchesPodStatefulset = `[0-9]+$` )
const ( CgroupKubePods = "kubepods" CgroupPodPrefix = "pod" )
const (
ExtResourcePrefixFormat = "gocrane.io/%s"
)
Variables ¶
var RootCgroupName = CgroupName([]string{})
Functions ¶
func AlmostEqual ¶ added in v0.2.0
func Bool2Int32 ¶ added in v0.3.0
func BuildZoneName ¶ added in v0.8.0
BuildZoneName returns the canonical name of a NUMA zone from its ID.
func CalculatePodRequests ¶
CalculatePodRequests sum request total from pods
func CalculatePodTemplateRequests ¶ added in v0.3.0
func CalculatePodTemplateRequests(podTemplate *v1.PodTemplateSpec, resource v1.ResourceName) (int64, error)
CalculatePodTemplateRequests sum request total from podTemplate
func ContainMaps ¶ added in v0.2.0
ContainMaps to judge the maps b is contained by maps a
func ContainsString ¶
func EvictPodWithGracePeriod ¶
func EvictPodWithGracePeriod(client clientset.Interface, pod *v1.Pod, gracePeriodSeconds *int32) error
EvictPodWithGracePeriod evict pod with grace period
func ExpandSlice ¶ added in v0.8.0
func GetAddressAndDialer ¶
func GetAddressAndDialer(endpoint string) (string, func(ctx context.Context, addr string) (net.Conn, error), error)
GetAddressAndDialer returns the address parsed from the given endpoint and a context dialer.
func GetAvailablePods ¶ added in v0.5.0
GetAvailablePods return a set with pod names that paas IsPodAvailable check
func GetContainerCpuUsageExpression ¶ added in v0.8.0
func GetContainerExtCpuResFromPod ¶ added in v0.5.0
GetContainerExtCpuResFromPod get container's gocrane.io/cpu usage
func GetContainerExtMemResFromPod ¶ added in v0.8.0
GetContainerExtMemResFromPod get container's gocrane.io/memory usage
func GetContainerFromPod ¶ added in v0.5.0
func GetContainerIdFromKey ¶ added in v0.2.0
func GetContainerIdFromPod ¶ added in v0.3.0
func GetContainerMemUsageExpression ¶ added in v0.8.0
func GetContainerNameFromPod ¶ added in v0.5.0
func GetContainerStatus ¶ added in v0.3.0
func GetCronMetricName ¶ added in v0.8.0
func GetCronMetricName() string
GetCronMetricName return metric name used by cron
func GetCustomerExpression ¶ added in v0.8.0
func GetDaemonSetPods ¶ added in v0.7.0
func GetEHPAFromScaleTarget ¶ added in v0.3.0
func GetEHPAFromScaleTarget(context context.Context, kubeClient client.Client, namespace string, objRef corev1.ObjectReference) (*autoscalingapi.EffectiveHorizontalPodAutoscaler, error)
func GetEVPAFromScaleTarget ¶ added in v0.4.0
func GetEVPAFromScaleTarget(context context.Context, kubeClient client.Client, namespace string, objRef corev1.ObjectReference) (*autoscalingapi.EffectiveVerticalPodAutoscaler, error)
func GetElasticResourceLimit ¶ added in v0.8.0
func GetElasticResourceLimit(pod *v1.Pod, resName v1.ResourceName) (amount int64)
GetElasticResourceLimit sum all containers resources limit for gocrane.io/resource As extended resource is not over committable resource, so request = limit
func GetExpressionQueryAnnotation ¶ added in v0.8.0
GetExpressionQueryAnnotation return metric query from annotation by metricName
func GetExpressionQueryDefault ¶ added in v0.8.0
func GetExpressionQueryDefault(metric autoscalingv2.MetricSpec, namespace string, name string, kind string) string
GetExpressionQuery return metric query
func GetExtCpuRes ¶ added in v0.3.0
GetExtCpuRes get container's gocrane.io/cpu usage
func GetExtMemRes ¶ added in v0.8.0
GetExtMemRes get container's gocrane.io/memory usage
func GetGroupVersionResource ¶ added in v0.9.0
func GetGroupVersionResource(discoveryClient discovery.DiscoveryInterface, apiVersion string, kind string) (*schema.GroupVersionResource, error)
func GetHPAFromScaleTarget ¶ added in v0.3.0
func GetHPAFromScaleTarget(context context.Context, kubeClient client.Client, namespace string, objRef corev1.ObjectReference) (*autoscalingv2.HorizontalPodAutoscaler, error)
func GetInt32withDefault ¶
func GetInt64withDefault ¶
func GetKubeletConfig ¶ added in v0.8.0
func GetKubeletConfig(ctx context.Context, c kubeclient.Interface, hostname string) (*kubeletconfiginternal.KubeletConfiguration, error)
func GetMetricIdentifier ¶ added in v0.8.0
func GetMetricIdentifier(metric autoscalingv2.MetricSpec, name string) string
GetGeneralPredictionMetricName return metric name used by prediction
func GetNodeCpuUsageExpression ¶ added in v0.8.0
func GetNodeMemUsageExpression ¶ added in v0.8.0
func GetNodePods ¶ added in v0.8.0
func GetNodeRef ¶
func GetNodeRef(nodeName string) *v1.ObjectReference
func GetPodCgroupNameSuffix ¶ added in v0.8.0
func GetPodCondition ¶
func GetPodCondition(status *v1.PodStatus, conditionType v1.PodConditionType) (int, *v1.PodCondition)
GetPodCondition 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. copied from k8s.io/kubernetes/pkg/api/v1/pod.go
func GetPodContainerByName ¶ added in v0.2.0
GetPodContainerByName get container info by container name
func GetPodCpuUsageExpression ¶ added in v0.8.0
func GetPodMemUsageExpression ¶ added in v0.8.0
func GetPodNameReg ¶ added in v0.9.0
func GetPodReadyCondition ¶
func GetPodReadyCondition(status v1.PodStatus) *v1.PodCondition
GetPodReadyCondition extracts the pod ready condition from the given status and returns that. Returns nil if the condition is not present. copied from k8s.io/kubernetes/pkg/api/v1/pod.go
func GetPodTemplate ¶ added in v0.3.0
func GetPodsFromScale ¶
func GetPredictionMetricName ¶ added in v0.5.0
func GetPredictionMetricName(sourceType autoscalingv2.MetricSourceType) (metricName string)
GetPredictionMetricName return metric name used by prediction
func GetReadyPredictionMetric ¶ added in v0.6.0
func GetReadyPredictionMetric(metric string, resourceIdentifier string, prediction *predictionapi.TimeSeriesPrediction) (*predictionapi.MetricTimeSeries, error)
func GetRecommendationRuleOwnerReference ¶ added in v0.10.0
func GetRecommendationRuleOwnerReference(recommend *analysisv1alpha1.Recommendation) *metav1.OwnerReference
func GetReservedCPUs ¶ added in v0.10.0
GetReservedCPUs ...
func GetResourceByPodTemplate ¶ added in v0.3.0
func GetResourceByPodTemplate(podTemplate *corev1.PodTemplateSpec, containerName string) (*corev1.ResourceRequirements, bool)
func GetRunNumber ¶ added in v0.10.0
func GetRunNumber(recommendation *analysisv1alpha1.Recommendation) (int32, error)
func GetScale ¶
func GetScale(ctx context.Context, restMapper meta.RESTMapper, scaleClient scale.ScalesGetter, namespace string, ref autoscalingv2.CrossVersionObjectReference) (*autoscalingapiv1.Scale, *meta.RESTMapping, error)
func GetScaleFromObjectReference ¶ added in v0.10.0
func GetScaleFromObjectReference(ctx context.Context, restMapper meta.RESTMapper, scaleClient scale.ScalesGetter, ref v1.ObjectReference) (*autoscalingapiv1.Scale, *meta.RESTMapping, error)
func GetUint32withDefault ¶
func GetUint64withDefault ¶
func GetWorkloadCpuUsageExpression ¶ added in v0.8.0
func GetWorkloadMemUsageExpression ¶ added in v0.8.0
func IsCPUResourceEqual ¶ added in v0.3.0
func IsCPUResourceEqual(oldResource, desiredResource corev1.ResourceList) bool
func IsEHPACronEnabled ¶ added in v0.4.0
func IsEHPACronEnabled(ehpa *autoscalingapi.EffectiveHorizontalPodAutoscaler) bool
func IsEHPAHasPredictionMetric ¶ added in v0.5.0
func IsEHPAHasPredictionMetric(ehpa *autoscalingapi.EffectiveHorizontalPodAutoscaler) bool
func IsEHPAPredictionEnabled ¶ added in v0.4.0
func IsEHPAPredictionEnabled(ehpa *autoscalingapi.EffectiveHorizontalPodAutoscaler) bool
func IsEqual ¶ added in v0.3.0
func IsEqual(oldResource, desiredResource *corev1.ResourceRequirements) bool
func IsExpressionQueryAnnotationEnabled ¶ added in v0.9.0
func IsHPAControlledByEHPA ¶ added in v0.8.0
func IsHPAControlledByEHPA(hpa *autoscalingv2.HorizontalPodAutoscaler) bool
func IsMemoryResourceEqual ¶ added in v0.3.0
func IsMemoryResourceEqual(oldResource, desiredResource corev1.ResourceList) bool
func IsNodeAwareOfTopology ¶ added in v0.8.0
IsNodeAwareOfTopology returns default topology awareness policy.
func IsPodAvailable ¶
IsPodAvailable returns true if a pod is available; false otherwise. copied from k8s.io/kubernetes/pkg/api/v1/pod.go
func IsPodReady ¶
IsPodReady returns true if a pod is ready; false otherwise. copied from k8s.io/kubernetes/pkg/api/v1/pod.go and modified
func IsPodTerminated ¶ added in v0.8.0
func IsRecommendationControlledByRule ¶ added in v0.10.0
func IsRecommendationControlledByRule(recommend *analysisv1alpha1.Recommendation) bool
func IsResourceEqual ¶ added in v0.3.0
func IsResourceEqual(oldResource, desiredResource corev1.ResourceList) bool
func KindForResource ¶ added in v0.2.0
func KindForResource(resource string, restMapper meta.RESTMapper) (string, error)
func LabelSelectorMatched ¶
func MapSortToArray ¶ added in v0.9.0
func ParseDuration ¶
ParseDuration parse a string to time.Duration
func ParsePercentage ¶ added in v0.5.0
parsePercentage parse the percent string value
func ParseTimestamp ¶ added in v0.7.0
ParseTimestamp parse a string to time.Time
func PodExcludeReservedCPUs ¶ added in v0.10.0
PodExcludeReservedCPUs ...
func QueryPredictedTimeSeriesOnce ¶ added in v0.3.0
func QueryPredictedTimeSeriesOnce(predictor prediction.Interface, caller string, pConfig *config.Config, namer metricnaming.MetricNamer, startTime time.Time, endTime time.Time) ([]*common.TimeSeries, error)
func QueryPredictedValues ¶ added in v0.4.0
func QueryPredictedValues(predictor prediction.Interface, caller string, pConfig *config.Config, namer metricnaming.MetricNamer) ([]*common.TimeSeries, error)
func QueryPredictedValuesOnce ¶ added in v0.3.0
func QueryPredictedValuesOnce(recommendation *v1alpha1.Recommendation, predictor prediction.Interface, caller string, pConfig *config.Config, namer metricnaming.MetricNamer) ([]*common.TimeSeries, error)
func RemoveNodeTaints ¶ added in v0.2.0
func RemoveString ¶ added in v0.4.0
func SetRunNumber ¶ added in v0.10.0
func SetRunNumber(recommendation *analysisv1alpha1.Recommendation, runNumber int32)
func UpdateNodeConditionsStatues ¶ added in v0.2.0
func UpdateNodeConditionsStatues(client clientset.Interface, nodeLister corelisters.NodeLister, nodeName string, condition v1.NodeCondition, retry *uint64) (*v1.Node, error)
UpdateNodeConditionsStatues be used to update node condition with check whether it needs to update
func UpdateNodeTaints ¶ added in v0.2.0
func UpdateNodeTaints(client clientset.Interface, nodeLister corelisters.NodeLister, nodeName string, taint v1.Taint, retry *uint64) (*v1.Node, error)
UpdateNodeTaints be used to update node taints with check whether it needs to update
Types ¶
type CgroupName ¶ added in v0.8.0
type CgroupName []string
func GetCgroupName ¶ added in v0.8.0
func GetCgroupName(p *v1.Pod) CgroupName
func NewCgroupName ¶ added in v0.8.0
func NewCgroupName(base CgroupName, components ...string) CgroupName
func (CgroupName) ToCgroupfs ¶ added in v0.8.0
func (cgroupName CgroupName) ToCgroupfs() string
func (CgroupName) ToSystemd ¶ added in v0.8.0
func (cgroupName CgroupName) ToSystemd() string