utils

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2022 License: Apache-2.0 Imports: 37 Imported by: 2

Documentation

Index

Constants

View Source
const (
	CgroupKubePods  = "/kubepods"
	CgroupPodPrefix = "pod"
)
View Source
const (
	ExtResourcePrefixFormat = "gocrane.io/%s"
)

Variables

This section is empty.

Functions

func AlmostEqual added in v0.2.0

func AlmostEqual(a, b float64) bool

func Bool2Int32 added in v0.3.0

func Bool2Int32(b bool) int32

func CalculatePodRequests

func CalculatePodRequests(pods []v1.Pod, resource v1.ResourceName) (int64, error)

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

func ContainMaps(a map[string]string, b map[string]string) bool

ContainMaps to judge the maps b is contained by maps a

func ContainsString

func ContainsString(slice []string, str string) bool

func EvictPodWithGracePeriod

func EvictPodWithGracePeriod(client clientset.Interface, pod *v1.Pod, gracePeriodSeconds *int32) error

EvictPodWithGracePeriod evict pod with grace period

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 GetContainerIdFromKey added in v0.2.0

func GetContainerIdFromKey(key string) string

func GetContainerIdFromPod added in v0.3.0

func GetContainerIdFromPod(pod *v1.Pod, containerName string) string

func GetContainerStatus added in v0.3.0

func GetContainerStatus(pod *v1.Pod, container v1.Container) v1.ContainerState

func GetEHPAFromScaleTarget added in v0.3.0

func GetEHPAFromScaleTarget(context context.Context, kubeClient client.Client, namespace string, objRef corev1.ObjectReference) (*autoscalingapi.EffectiveHorizontalPodAutoscaler, error)

func GetExtCpuRes added in v0.3.0

func GetExtCpuRes(container v1.Container) (resource.Quantity, bool)

GetExtCpuRes get container's gocrane.io/cpu usage

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 GetInt32withDefault(i *int32, value int32) int32

func GetInt64withDefault

func GetInt64withDefault(i *int64, value int64) int64

func GetNodeRef

func GetNodeRef(nodeName string) *v1.ObjectReference

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

func GetPodContainerByName(pod *v1.Pod, containerName string) (v1.Container, error)

GetPodContainerByName get container info by container name

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 GetPodTemplate(context context.Context, namespace string, name string, kind string, apiVersion string, kubeClient client.Client) (*v1.PodTemplateSpec, error)

func GetPodsFromScale

func GetPodsFromScale(kubeClient client.Client, scale *autoscalingapiv1.Scale) ([]v1.Pod, error)

func GetResourceByPodTemplate added in v0.3.0

func GetResourceByPodTemplate(podTemplate *corev1.PodTemplateSpec, containerName string) *corev1.ResourceRequirements

func GetUint32withDefault

func GetUint32withDefault(i *uint32, value uint32) uint32

func GetUint64FromMaps

func GetUint64FromMaps(key string, maps map[string]uint64) uint64

func GetUint64withDefault

func GetUint64withDefault(i *uint64, value uint64) uint64

func Int32P added in v0.3.0

func Int32P(value int32) *int32

func IsCPUResourceEqual added in v0.3.0

func IsCPUResourceEqual(oldResource, desiredResource corev1.ResourceList) bool

func IsEqual added in v0.3.0

func IsEqual(oldResource, desiredResource *corev1.ResourceRequirements) bool

func IsMemoryResourceEqual added in v0.3.0

func IsMemoryResourceEqual(oldResource, desiredResource corev1.ResourceList) bool

func IsPodAvailable

func IsPodAvailable(pod *v1.Pod, minReadySeconds int32, now metav1.Time) bool

IsPodAvailable returns true if a pod is available; false otherwise. copied from k8s.io/kubernetes/pkg/api/v1/pod.go

func IsPodReady

func IsPodReady(pod *v1.Pod) bool

IsPodReady returns true if a pod is ready; false otherwise. copied from k8s.io/kubernetes/pkg/api/v1/pod.go

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 LabelSelectorMatched(maps map[string]string, selector *metav1.LabelSelector) (bool, error)

func ParseDuration

func ParseDuration(s string) (time.Duration, error)

ParseDuration ParseDuration

func ParseFloat

func ParseFloat(str string, defaultValue float64) (float64, error)

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 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 RemoveNodeTaints(client clientset.Interface, nodeLister corelisters.NodeLister, nodeName string, taint v1.Taint, retry *uint64) (*v1.Node, error)

func StringPtr added in v0.3.0

func StringPtr(str string) *string

func Uint32P added in v0.3.0

func Uint32P(value uint32) *uint32

func Uint64P added in v0.3.0

func Uint64P(value uint64) *uint64

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

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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