kube

package
v0.0.0-...-d85bf88 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2022 License: AGPL-3.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExceedsCompare

func ExceedsCompare(a string) string

Compare

func FieldString

func FieldString(str string) float64

FieldString

func New

func New(cc *ClientConfig) (client kubernetes.Interface, metricsClient *metrics.Clientset, err error)

New returns a kubernetes client. It tries first with in-cluster config, if it fails it will try with out-of-cluster config.

func NewFromConfig

func NewFromConfig(cc *ClientConfig) (client kubernetes.Interface, metricsClient *metrics.Clientset, err error)

NewFromConfig returns a new out-of-cluster kubernetes client.

func NewGpuResource

func NewGpuResource(name v1.ResourceName, rl *v1.ResourceList) *resource.Quantity

NewGpuResource returns the list of NewGpuResource

func NewInCluster

func NewInCluster(cc *ClientConfig) (client kubernetes.Interface, metricsClient *metrics.Clientset, err error)

NewInCluster returns a new in-cluster kubernetes client.

func NodeCapacity

func NodeCapacity(node *v1.Node) v1.ResourceList

NodeCapacity

func PodRequestsAndLimits

func PodRequestsAndLimits(pod *v1.Pod) (reqs, limits v1.ResourceList, err error)

PodRequestsAndLimits returns a dictionary of all defined resources summed up for all containers of the pod. If pod overhead is non-nil, the pod overhead is added to the total container resource requests and to the total container limits which have a non-zero quantity.

Types

type CPUResource

type CPUResource struct {
	*resource.Quantity
}

func NewCPUResource

func NewCPUResource(value int64) *CPUResource

NewCPUResource

func (*CPUResource) String

func (r *CPUResource) String() string

String

func (*CPUResource) ToQuantity

func (r *CPUResource) ToQuantity() *resource.Quantity

ToQuantity

type CPUResources

type CPUResources struct {
	// CPUUsages is number of allocated milicores.
	CPUUsages *CPUResource

	// CPURequests is number of allocated milicores.
	CPURequests *CPUResource

	// CPURequestsFraction is a fraction of CPU, that is allocated.
	CPURequestsFraction float64 `json:"cpuRequestsFraction"`

	// CPULimits is defined CPU limit.
	CPULimits *CPUResource

	// CPULimitsFraction is a fraction of defined CPU limit, can be over 100%, i.e.
	// overcommitted.
	CPULimitsFraction float64 `json:"cpuLimitsFraction"`

	// CPUCapacity is specified node CPU capacity in milicores.
	CPUCapacity *CPUResource
}

CPUResources describes node allocated resources.

type ClientConfig

type ClientConfig struct {
	QPS        float32
	Burst      int
	KubeCtx    string
	KubeConfig string
}

type KubeClient

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

func NewKubeClient

func NewKubeClient(cc *ClientConfig) (*KubeClient, error)

func (*KubeClient) GetActivePodByNodename

func (k *KubeClient) GetActivePodByNodename(node corev1.Node) (*corev1.PodList, error)

GetActivePodByNodename

func (*KubeClient) GetDeploy

func (k *KubeClient) GetDeploy(selector labels.Selector) []appsv1.Deployment

func (*KubeClient) GetDeployByName

func (k *KubeClient) GetDeployByName(ns, name string) (*appsv1.Deployment, error)

func (*KubeClient) GetNodeMetricsFromMetricsAPI

func (k *KubeClient) GetNodeMetricsFromMetricsAPI(resourceName string, selector labels.Selector) (*metricsapi.NodeMetricsList, error)

GetNodeMetricsFromMetricsAPI

func (*KubeClient) GetNodeResources

func (k *KubeClient) GetNodeResources(sortBy string, selector labels.Selector) ([]NodeResources, error)

NodeResources

func (*KubeClient) GetNodes

func (k *KubeClient) GetNodes(resourceName string, selector labels.Selector) (map[string]corev1.Node, error)

GetNodes

func (*KubeClient) GetPodByPodname

func (k *KubeClient) GetPodByPodname(podName string, namespace string) (*corev1.Pod, error)

GetActivePodByPodname

func (*KubeClient) GetPodMetricsFromMetricsAPI

func (k *KubeClient) GetPodMetricsFromMetricsAPI(namespace string, labelSelector labels.Selector, fieldSelector fields.Selector) (*metricsapi.PodMetricsList, error)

GetPodMetricsFromMetricsAPI

func (*KubeClient) GetPodResources

func (k *KubeClient) GetPodResources(podmetrics []metricsapi.PodMetrics, namespace string, sortBy string) ([]PodsResources, error)

func (*KubeClient) Patch

func (k *KubeClient) Patch(ns, name string) error

func (*KubeClient) PatchReplicas

func (k *KubeClient) PatchReplicas(ns, name string, nostop bool) error

func (*KubeClient) PodMetricses

func (k *KubeClient) PodMetricses() (*metricsV1beta1api.PodMetricsList, error)

PodMetricses returns all pods' usage metrics

type MemoryResource

type MemoryResource struct {
	*resource.Quantity
}

func NewMemoryResource

func NewMemoryResource(value int64) *MemoryResource

NewMemoryResource

func (*MemoryResource) String

func (r *MemoryResource) String() string

func (*MemoryResource) ToQuantity

func (r *MemoryResource) ToQuantity() *resource.Quantity

ToQuantity

type MemoryResources

type MemoryResources struct {
	// MemoryUsages is a fraction of memory, that is allocated.
	MemoryUsages *MemoryResource

	// MemoryRequests is a fraction of memory, that is allocated.
	MemoryRequests *MemoryResource

	// MemoryRequestsFraction is a fraction of memory, that is allocated.
	MemoryRequestsFraction float64 `json:"memoryRequestsFraction"`

	// MemoryLimits is defined memory limit.
	MemoryLimits *MemoryResource

	// MemoryLimitsFraction is a fraction of defined memory limit, can be over 100%, i.e.
	// overcommitted.
	MemoryLimitsFraction float64 `json:"memoryLimitsFraction"`

	// MemoryCapacity is specified node memory capacity in bytes.
	MemoryCapacity *MemoryResource
}

MemoryResources describes node allocated resources.

type NodeAllocatedResources

type NodeAllocatedResources struct {
	CPUResources
	MemoryResources
	PodResources
}

NodeAllocatedResources describes node allocated resources.

type NodeResources

type NodeResources struct {
	NodeName            string `json:"nodeName" yaml:"nodeName"`
	NodeIP              string `json:"nodeIP" yaml:"nodeIP"`
	CPUUsages           string `json:"cpuUsages" yaml:"cpuUsages"`
	CPURequests         string `json:"cpuRequests" yaml:"cpuRequests"`
	CPULimits           string `json:"cpuLimits" yaml:"cpuLimits"`
	CPUCapacity         string `json:"cpuCapacity" yaml:"cpuCapacity"`
	CPURequestsFraction string `json:"cpuRequestsFraction" yaml:"cpuRequestsFraction"`
	CPULimitsFraction   string `json:"cpuLimitsFraction" yaml:"cpuLimitsFraction"`

	MemoryUsages           string `json:"memoryUsages" yaml:"memoryUsages"`
	MemoryRequests         string `json:"memoryRequests" yaml:"memoryRequests"`
	MemoryLimits           string `json:"memoryLimits" yaml:"memoryLimits"`
	MemoryCapacity         string `json:"memoryCapacity" yaml:"memoryCapacity"`
	MemoryRequestsFraction string `json:"memoryRequestsFraction" yaml:"memoryRequestsFraction"`
	MemoryLimitsFraction   string `json:"memoryLimitsFraction" yaml:"memoryLimitsFraction"`

	AllocatedPods int    `json:"allocatedPods" yaml:"allocatedPods"`
	PodCapacity   int64  `json:"podCapacity" yaml:"podCapacity"`
	PodFraction   string `json:"podFraction" yaml:"podFraction"`

	Age string `json:"age" yaml:"age"`
}

type PodAllocatedResources

type PodAllocatedResources struct {
	// CPUUsages is number of allocated milicores.
	CPUUsages *CPUResource

	// CPURequestsFraction is a fraction of CPU, that is allocated.
	CPUUsagesFraction float64 `json:"cpuUsagesFraction"`

	// CPURequests is number of allocated milicores.
	CPURequests *CPUResource

	// CPULimits is defined CPU limit.
	CPULimits *CPUResource

	// MemoryUsages is a fraction of memory, that is allocated.
	MemoryUsages *MemoryResource

	// MemoryRequestsFraction is a fraction of memory, that is allocated.
	MemoryUsagesFraction float64 `json:"memoryUsagesFraction"`

	// MemoryRequests is a fraction of memory, that is allocated.
	MemoryRequests *MemoryResource

	// MemoryLimits is defined memory limit.
	MemoryLimits *MemoryResource
}

PodAllocatedResources describes node allocated resources.

type PodResources

type PodResources struct {
	// AllocatedPods in number of currently allocated pods on the node.
	AllocatedPods int `json:"allocatedPods"`

	// PodCapacity is maximum number of pods, that can be allocated on the node.
	PodCapacity int64 `json:"podCapacity"`

	// PodFraction is a fraction of pods, that can be allocated on given node.
	PodFraction float64 `json:"podFraction"`
}

PodResources describes node allocated resources.

type PodsResources

type PodsResources struct {
	Name                 string `json:"name" yaml:"name"`
	Namespace            string `json:"namespace" yaml:"namespace"`
	CPUUsages            string `json:"cpuUsages" yaml:"cpuUsages"`
	CPURequests          string `json:"cpuRequests" yaml:"cpuRequests"`
	CPULimits            string `json:"cpuLimits" yaml:"cpuLimits"`
	CPUUsagesFraction    string `json:"cpuUsagesFraction" yaml:"cpuUsagesFraction"`
	MemoryUsages         string `json:"memoryUsages" yaml:"memoryUsages"`
	MemoryRequests       string `json:"memoryRequests" yaml:"memoryRequests"`
	MemoryLimits         string `json:"memoryLimits" yaml:"memoryLimits"`
	MemoryUsagesFraction string `json:"memoryUsagesFraction" yaml:"memoryUsagesFraction"`
}

Jump to

Keyboard shortcuts

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