kubeclient

package
v0.0.0-...-366d0f7 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2025 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Overview

Package kubeclient a series of k8s function

Package kubeclient a series of k8s function

Package kubeclient a series of k8s function

Package kubeclient a series of k8s function

Package kubeclient a series of k8s function

Index

Constants

View Source
const (
	// HostIPEnv represents the env for HOST_IP
	HostIPEnv = "HOST_IP"
	// KubeletPortEnv represents the env for KUBELET_PORT
	KubeletPortEnv = "KUBELET_PORT"
	// DefaultKubeletPort represents the default listening port for the kubelet service
	DefaultKubeletPort = "10250"
	// MaxPortIntValue represents the max value of port
	MaxPortIntValue = 65535
)

Variables

This section is empty.

Functions

func GetNodeNameFromEnv

func GetNodeNameFromEnv() (string, error)

GetNodeNameFromEnv get current node name from env

func UpdatePodList

func UpdatePodList(newObj interface{}, operator EventType)

UpdatePodList update pod list by informer

Types

type ClientK8s

type ClientK8s struct {
	Clientset      kubernetes.Interface
	NodeName       string
	DeviceInfoName string
	IsApiErr       bool
	PodInformer    cache.SharedIndexInformer
	Queue          workqueue.RateLimitingInterface
	KltClient      *http.Client
}

ClientK8s include ClientK8sSet & nodeName & configmap name & kubelet http Client

func NewClientK8s

func NewClientK8s() (*ClientK8s, error)

NewClientK8s create k8s client

func (*ClientK8s) AddAnnotation

func (ki *ClientK8s) AddAnnotation(key, value string) error

AddAnnotation add annotation

func (*ClientK8s) AnnotationReset

func (ki *ClientK8s) AnnotationReset() error

AnnotationReset reset annotation and device info

func (*ClientK8s) ClearResetInfo

func (ki *ClientK8s) ClearResetInfo(taskName, namespace string) error

ClearResetInfo clear reset info

func (*ClientK8s) CreateConfigMap

func (ki *ClientK8s) CreateConfigMap(cm *v1.ConfigMap) (*v1.ConfigMap, error)

CreateConfigMap create device info, which is cm

func (*ClientK8s) CreateEvent

func (ki *ClientK8s) CreateEvent(evt *v1.Event) (*v1.Event, error)

CreateEvent create event resource

func (*ClientK8s) FlushPodCacheNextQuerying

func (ki *ClientK8s) FlushPodCacheNextQuerying()

FlushPodCacheNextQuerying next time querying pod, flush cache

func (*ClientK8s) GetActivePodList

func (ki *ClientK8s) GetActivePodList() ([]v1.Pod, error)

GetActivePodList is to get active pod list

func (*ClientK8s) GetActivePodListCache

func (ki *ClientK8s) GetActivePodListCache() []v1.Pod

GetActivePodListCache is to get active pod list with cache

func (*ClientK8s) GetAllPodList

func (ki *ClientK8s) GetAllPodList() (*v1.PodList, error)

GetAllPodList get pod list by field selector

func (*ClientK8s) GetAllPodListCache

func (ki *ClientK8s) GetAllPodListCache() []v1.Pod

GetAllPodListCache get pod list by field selector with cache,

func (*ClientK8s) GetConfigMap

func (ki *ClientK8s) GetConfigMap(cmName, cmNameSpace string) (*v1.ConfigMap, error)

GetConfigMap get config map by name and namespace

func (*ClientK8s) GetDeviceInfoCMCache

func (ki *ClientK8s) GetDeviceInfoCMCache() *common.NodeDeviceInfoCache

GetDeviceInfoCMCache get device info configMap with cache

func (*ClientK8s) GetManuallySeparateNPUIDFromDeviceInfo

func (ki *ClientK8s) GetManuallySeparateNPUIDFromDeviceInfo(deviceInfoCMName, deviceInfoCMNamespace string) []int32

GetManuallySeparateNPUIDFromDeviceInfo returns the ManuallySeparateNPU from device info

func (*ClientK8s) GetNode

func (ki *ClientK8s) GetNode() (*v1.Node, error)

GetNode get node

func (*ClientK8s) GetNodeServerID

func (ki *ClientK8s) GetNodeServerID() (string, error)

GetNodeServerID Get Node Server ID

func (*ClientK8s) GetNodeServerIDCache

func (ki *ClientK8s) GetNodeServerIDCache() (string, error)

GetNodeServerIDCache Get Node Server ID with cache

func (*ClientK8s) GetPod

func (ki *ClientK8s) GetPod(pod *v1.Pod) (*v1.Pod, error)

GetPod get pod by namespace and name

func (*ClientK8s) GetPodsUsedNPUByKlt

func (ki *ClientK8s) GetPodsUsedNPUByKlt() sets.String

GetPodsUsedNPUByKlt returns NPUs used by Pods

func (*ClientK8s) GetPodsUsedNpuByCommon

func (ki *ClientK8s) GetPodsUsedNpuByCommon() sets.String

GetPodsUsedNpuByCommon get npu by status

func (*ClientK8s) GetServerUsageLabelCache

func (ki *ClientK8s) GetServerUsageLabelCache() (string, error)

GetServerUsageLabelCache get node label:server-usage, and cache it in memory, if label updated, restart is required if server-usage label is set return the value of label if server-usage label is not set return 'unknown'

func (*ClientK8s) InitPodInformer

func (ki *ClientK8s) InitPodInformer()

InitPodInformer init pod informer

func (*ClientK8s) PatchNodeState

func (ki *ClientK8s) PatchNodeState(curNode, newNode *v1.Node) (*v1.Node, []byte, error)

PatchNodeState patch node state

func (*ClientK8s) PatchPod

func (ki *ClientK8s) PatchPod(pod *v1.Pod, data []byte) (*v1.Pod, error)

PatchPod patch pod information

func (*ClientK8s) PodInformerInspector

func (ki *ClientK8s) PodInformerInspector(ctx context.Context)

PodInformerInspector check pod in cache

func (*ClientK8s) ResetDeviceInfo

func (ki *ClientK8s) ResetDeviceInfo()

ResetDeviceInfo reset device info

func (*ClientK8s) ResourceEventHandler

func (ki *ClientK8s) ResourceEventHandler(res ResourceType, filter func(obj interface{}) bool) cache.
	ResourceEventHandler

ResourceEventHandler handle the configmap resource event

func (*ClientK8s) SetNodeDeviceInfoCache

func (ki *ClientK8s) SetNodeDeviceInfoCache(deviceInfoCache *common.NodeDeviceInfoCache)

SetNodeDeviceInfoCache set device info cache

func (*ClientK8s) TryUpdatePodAnnotation

func (ki *ClientK8s) TryUpdatePodAnnotation(pod *v1.Pod, annotation map[string]string) error

TryUpdatePodAnnotation is to try updating pod annotation

func (*ClientK8s) TryUpdatePodCacheAnnotation

func (ki *ClientK8s) TryUpdatePodCacheAnnotation(pod *v1.Pod, annotation map[string]string) error

TryUpdatePodCacheAnnotation is to try updating pod annotation in both api server and cache

func (*ClientK8s) UpdateConfigMap

func (ki *ClientK8s) UpdateConfigMap(cm *v1.ConfigMap) (*v1.ConfigMap, error)

UpdateConfigMap update device info, which is cm

func (*ClientK8s) UpdatePod

func (ki *ClientK8s) UpdatePod(pod *v1.Pod) (*v1.Pod, error)

UpdatePod update pod by namespace and name

func (*ClientK8s) WriteDeviceInfoDataIntoCM

func (ki *ClientK8s) WriteDeviceInfoDataIntoCM(deviceInfo map[string]string,
	manuallySeparateNPU string, switchInfo common.SwitchFaultInfo, superPodID,
	serverIndex int32) (*common.NodeDeviceInfoCache, error)

WriteDeviceInfoDataIntoCM write deviceinfo into config map

func (*ClientK8s) WriteDeviceInfoDataIntoCMCache

func (ki *ClientK8s) WriteDeviceInfoDataIntoCMCache(deviceInfo map[string]string, manuallySeparateNPU string,
	switchInfo common.SwitchFaultInfo, superPodID, serverIndex int32) error

WriteDeviceInfoDataIntoCMCache write deviceinfo into config map with cache

func (*ClientK8s) WriteFaultInfoDataIntoCM

func (ki *ClientK8s) WriteFaultInfoDataIntoCM(taskName string, namespace string,
	faultInfo *common.TaskFaultInfo) (*v1.ConfigMap, error)

WriteFaultInfoDataIntoCM write fault info into config map

func (*ClientK8s) WriteResetInfoDataIntoCM

func (ki *ClientK8s) WriteResetInfoDataIntoCM(taskName string, namespace string,
	taskInfo *common.TaskResetInfo, needAddRetry bool) (*v1.ConfigMap, error)

WriteResetInfoDataIntoCM write reset info into config map

type Event

type Event struct {
	// ResourceType is the type of the resource that is being watched
	Resource ResourceType
	// Key is namespace/name
	Key string
	// Type is the type of the event
	Type EventType
}

Event is the event that will be sent to the watcher

type EventType

type EventType string

EventType string type of event

const (
	// EventTypeAdd is used when a new resource is created
	EventTypeAdd EventType = "add"
	// EventTypeUpdate is used when an existing resource is modified
	EventTypeUpdate EventType = "update"
	// EventTypeDelete is used when an existing resource is deleted
	EventTypeDelete EventType = "delete"
)

type ResourceType

type ResourceType string

ResourceType string type of resource

const (
	// PodResource is used when the event is related to a pod
	PodResource ResourceType = "pod"
	// CMResource is used when the event is related to a configmap
	CMResource ResourceType = "configmap"
)

Jump to

Keyboard shortcuts

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