k8s

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 27, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Package k8s provides helper functions for interacting with Kubernetes clusters and related resources.

Package k8s contains helpers for interacting with Kubernetes clusters and related resources.

Index

Constants

View Source
const GPUProperty corev1.ResourceName = "nvidia.com/gpu"

GPUProperty is the Kubernetes resource name for GPU.

View Source
const NodeCondGpuUnhealthy corev1.NodeConditionType = "GpuUnhealthy"

NodeCondGpuUnhealthy is the condition type for unhealthy GPU nodes.

Variables

View Source
var DefaultGPUSelectors = []string{
	"app=dummy",
	"component=predictor",
	"ome.oracle.com/trainingjob",
}

DefaultGPUSelectors is the default set of label selectors used to sum GPU allocations.

Functions

func DrainNode added in v0.1.3

func DrainNode(ctx context.Context, kubeconfig, contextName, nodeName string) error

DrainNode uses kubectl's drain.Helper to cordon and drain a node.

func LoadDedicatedAIClusters

func LoadDedicatedAIClusters(ctx context.Context, lister DedicatedAIClusterLister) (map[string][]models.DedicatedAICluster, error)

LoadDedicatedAIClusters loads DedicatedAICluster information using the provided DedicatedAIClusterLister.

func LoadGpuNodes

func LoadGpuNodes(ctx context.Context, lister GpuNodeLister) (map[string][]models.GpuNode, error)

LoadGpuNodes loads GPU node information using the provided GpuNodeLister.

func TenantIDFromLabels

func TenantIDFromLabels(labels map[string]any) string

TenantIDFromLabels extracts the tenant ID from a map of labels. Returns "UNKNOWN_TENANCY" if the label is missing or not a string.

func ToggleCordon added in v0.1.3

func ToggleCordon(ctx context.Context, kubeconfig, contextName, nodeName string) error

ToggleCordon uses kubectl's drain.Helper to cordon or uncordon a node. Returns true if node is cordoned after the call, false if uncordoned.

Types

type DedicatedAIClusterLister

type DedicatedAIClusterLister interface {
	ListDedicatedAIClusters(ctx context.Context) ([]models.DedicatedAICluster, error)
}

DedicatedAIClusterLister is an interface for listing DedicatedAIClusters.

type GpuNodeLister

type GpuNodeLister interface {
	ListGpuNodes(ctx context.Context) ([]models.GpuNode, error)
}

GpuNodeLister is an interface for listing GPU nodes.

type Helper

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

Helper provides helpers for interacting with Kubernetes clusters. It manages client configuration, context switching, and provides methods for listing GPU nodes and AI clusters.

func NewHelper

func NewHelper(configFile string, context string) (*Helper, error)

NewHelper creates a new Helper using the given kubeconfig file and context.

func (*Helper) ChangeContext

func (k *Helper) ChangeContext(context string) error

ChangeContext switches the current context of the K8sHelper to the specified context.

func (*Helper) ListDedicatedAIClusters

func (k *Helper) ListDedicatedAIClusters(ctx context.Context) ([]models.DedicatedAICluster, error)

ListDedicatedAIClusters returns all DedicatedAICluster resources from both v1alpha1 and v1beta1 CRDs.

func (*Helper) ListGpuNodes

func (k *Helper) ListGpuNodes(ctx context.Context) ([]models.GpuNode, error)

ListGpuNodes is the production version, using all selectors.

func (*Helper) ListGpuNodesWithSelectors

func (k *Helper) ListGpuNodesWithSelectors(ctx context.Context, selectors ...string) ([]models.GpuNode, error)

ListGpuNodesWithSelectors returns a list of GpuNode objects from the current Kubernetes context. If no selectors are provided, DefaultGPUSelectors is used.

Jump to

Keyboard shortcuts

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