pvcusage

package module
v0.0.0-...-2717e6f Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2023 License: BSD-3-Clause Imports: 9 Imported by: 0

README

k8s-pvc-usage

Barebones PVC usage metrics exposed with Prometheus.

This project is designed to be executed as a single-pod deployment within a Kubernetes cluster.

Assumptions

  • A service account token is available at /var/run/secrets/kubernetes.io/serviceaccount/token. The directory can be overridden using the KUBERNETES_SECRETS_PATH environment variable.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client provides simplified access to the k8s API.

func New

func New(addr, token string) *Client

New creates a new k8s API client.

func (*Client) Req

func (c *Client) Req(ctx context.Context, parts ...string) *request.Client

Req prepares a request against the k8s API.

func (*Client) With

func (c *Client) With(opts ...Option)

With enables modification of the k8s API client configuration.

type Node

type Node struct {
	Metadata struct {
		Name string `json:"name"`
	} `json:"metadata"`
}

Node represents an individual k8s node.

func GetNodes

func GetNodes(api *Client) []Node

func GetNodesCtx

func GetNodesCtx(ctx context.Context, api *Client) []Node

type NodeList

type NodeList struct {
	Items []Node `json:"items"`
}

NodeList represents the list of nodes in the k8s cluster.

type NodePodsList

type NodePodsList struct {
	Pods []Pod `json:"pods"`
}

NodePodsList represents the list of pods scheduled on a k8s node.

type Option

type Option func(*Client)

Option allows modification of the k8s API client.

func CA

func CA(path string) Option

CA attempts to load a trusted Certificate Authority into the API client.

func Timeout

func Timeout(dur time.Duration) Option

Timeout customizes the maximum amount of time to wait for a response from the k8s API.

type Pod

type Pod struct {
	Volumes []Volume `json:"volume"`
}

Pod represents a k8s Pod workload.

type PvcRef

type PvcRef struct {
	Name      string `json:"name"`
	Namespace string `json:"namespace"`
}

PvcRef represents a relationship between a Volume and a PVC.

type PvcStats

type PvcStats struct {
	Name           string  `json:"name"`
	Namespace      string  `json:"namespace"`
	AvailableBytes float64 `json:"availableBytes"`
	CapacityBytes  float64 `json:"capacityBytes"`
	UsedBytes      float64 `json:"usedBytes"`
}

func GetNodePvcUsage

func GetNodePvcUsage(api *Client, node Node) []PvcStats

func GetNodePvcUsageCtx

func GetNodePvcUsageCtx(ctx context.Context, api *Client, node Node) (stats []PvcStats)

func GetPvcUsage

func GetPvcUsage(api *Client) []PvcStats

func GetPvcUsageCtx

func GetPvcUsageCtx(ctx context.Context, api *Client) (stats []PvcStats)

func (PvcStats) Avail

func (pvc PvcStats) Avail() float64

func (PvcStats) Usage

func (pvc PvcStats) Usage() float64

type Volume

type Volume struct {
	Time           *time.Time `json:"time"`
	AvailableBytes float64    `json:"availableBytes"`
	CapacityBytes  float64    `json:"capacityBytes"`
	UsedBytes      float64    `json:"usedBytes"`
	InodesFree     float64    `json:"inodesFree"`
	Inodes         float64    `json:"inodes"`
	InodesUsed     float64    `json:"inodesUsed"`
	Name           string     `json:"name"`
	PvcRef         *PvcRef    `json:"pvcRef"`
}

Volume represents information about a volume attached to a Pod.

Directories

Path Synopsis
cmd
k8s-pvc-usage command

Jump to

Keyboard shortcuts

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