k8sutils

package
v4.12.0 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package k8sutils provides Kubernetes utilities

Package k8sutils provides Kubernetes utilities

Package k8sutils provides Kubernetes utilities

Package k8sutils provides Kubernetes utilities

Package k8sutils provides Kubernetes utilities

Package k8sutils provides Kubernetes utilities

Package k8sutils provides Kubernetes utilities

Index

Constants

View Source
const (
	// TopologyPrefix supported by CSI plugin
	TopologyPrefix = "topology.kubernetes.io"
	// ProtocolTopologyPrefix supported by CSI plugin
	ProtocolTopologyPrefix = TopologyPrefix + "/protocol."
)

Variables

This section is empty.

Functions

func BuildConfig added in v4.12.0

func BuildConfig(kubeConfig string, opts ...ConfigOption) (*rest.Config, error)

BuildConfig builds a REST config from kubeConfig and applies the given options.

func NewBackendUtils added in v4.12.0

func NewBackendUtils(kubeConfig string, opts ...ConfigOption) (versioned.Interface, error)

NewBackendUtils creates a new backend clientset with the given kubeConfig and options.

func WithHandler

func WithHandler[T runtime.Object](handler cache.ResourceEventHandlerFuncs) func(*ResourceAccessor[T]) error

WithHandler sets event handler for the resource.

func WithIndexers

func WithIndexers[T runtime.Object](indexers cache.Indexers) func(*ResourceAccessor[T]) error

WithIndexers sets indexers for the resource.

func WithTransformer

func WithTransformer[T runtime.Object](transform cache.TransformFunc) func(*ResourceAccessor[T]) error

WithTransformer sets transformer for the resource.

Types

type ConfigOption added in v4.12.0

type ConfigOption func(*rest.Config)

ConfigOption defines the functional option type for client configuration.

func Burst added in v4.12.0

func Burst(burst int) ConfigOption

Burst sets the Burst limit for the REST config.

func QPS added in v4.12.0

func QPS(qps float32) ConfigOption

QPS sets the QPS limit for the REST config.

type ConfigmapOps

type ConfigmapOps interface {
	// CreateConfigmap creates the given configmap
	CreateConfigmap(context.Context, *coreV1.ConfigMap) (*coreV1.ConfigMap, error)
	// GetConfigmap gets the configmap object given its name and namespace
	GetConfigmap(context.Context, string, string) (*coreV1.ConfigMap, error)
	// UpdateConfigmap update the configmap object given its name and namespace
	UpdateConfigmap(context.Context, *coreV1.ConfigMap) (*coreV1.ConfigMap, error)
	// DeleteConfigmap delete the configmap object given its name and namespace
	DeleteConfigmap(context.Context, *coreV1.ConfigMap) error
}

ConfigmapOps defines interfaces required by configmap

type Interface

type Interface interface {
	// GetNodeTopology returns configured kubernetes node's topological labels
	GetNodeTopology(ctx context.Context, nodeName string) (map[string]string, error)

	// GetVolume returns volumes on the node at K8S side
	GetVolume(ctx context.Context, nodeName string, driverName string) (map[string]struct{}, error)

	// GetPVByName get all pv info
	GetPVByName(ctx context.Context, name string) (*corev1.PersistentVolume, error)

	// ListPods get pods by namespace
	ListPods(ctx context.Context, namespace string) (*corev1.PodList, error)

	// GetPod get pod by name and namespace
	GetPod(ctx context.Context, namespace, podName string) (*corev1.Pod, error)

	// GetVolumeAttributes returns volume attributes of PV
	GetVolumeAttributes(ctx context.Context, pvName string) (map[string]string, error)

	// GetVolumeAttrsByVolumeId returns volume attributes of PV from volume id
	GetVolumeAttrsByVolumeId(volumeId string) ([]map[string]string, error)

	// GetDTreeParentNameByVolumeId returns dDTreeParentname field of PV by volume id
	GetDTreeParentNameByVolumeId(volumeId string) (string, error)

	// GetKvCacheStoreIdByVolumeId returns kvCacheStoreId field of PV by volume id
	GetKvCacheStoreIdByVolumeId(volumeId string) (string, error)

	// UpdateVAsWithHostMap updates VAs with the given host map
	UpdateVAsWithHostMap(ctx context.Context, volumeId string, hostMap map[string]map[string]interface{}) error

	// GetMappingHostsByVolumeId returns mapping hosts in VAs by volume id
	GetMappingHostsByVolumeId(volumeId string) ([]string, error)

	// GetVAsByPVName returns VAs by pv name
	GetVAsByPVName(pvName string) ([]*storagev1.VolumeAttachment, error)

	// Activate the k8s helpers when start the service
	Activate()
	// Deactivate the k8s helpers when stop the service
	Deactivate()

	ConfigmapOps
	// contains filtered or unexported methods
}

Interface is a kubernetes utility interface required by CSI plugin to interact with Kubernetes

func NewK8SUtils

func NewK8SUtils(kubeConfig string, opts ...Option) (Interface, error)

type KubeClient

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

KubeClient provides a wrapper for kubernetes client interface.

func (*KubeClient) Activate

func (k *KubeClient) Activate()

Activate activate k8s helpers

func (*KubeClient) CreateConfigmap

func (k *KubeClient) CreateConfigmap(ctx context.Context, configmap *coreV1.ConfigMap) (*coreV1.ConfigMap, error)

CreateConfigmap creates the given configmap

func (*KubeClient) CreateSecret

func (k *KubeClient) CreateSecret(ctx context.Context, secret *corev1.Secret) (*corev1.Secret, error)

CreateSecret create secret

func (*KubeClient) Deactivate

func (k *KubeClient) Deactivate()

Deactivate deactivate k8s helpers

func (*KubeClient) DeleteConfigmap

func (k *KubeClient) DeleteConfigmap(ctx context.Context, configmap *coreV1.ConfigMap) error

DeleteConfigmap delete configmap

func (*KubeClient) DeleteSecret

func (k *KubeClient) DeleteSecret(ctx context.Context, secretName, namespace string) error

DeleteSecret delete secret

func (*KubeClient) GetConfigmap

func (k *KubeClient) GetConfigmap(ctx context.Context, name, namespace string) (*coreV1.ConfigMap, error)

GetConfigmap gets the configmap object given its name and namespace

func (*KubeClient) GetDTreeParentNameByVolumeId added in v4.7.0

func (k *KubeClient) GetDTreeParentNameByVolumeId(volumeId string) (string, error)

GetDTreeParentNameByVolumeId returns dDTreeParentname field of PV by volume id

func (*KubeClient) GetKvCacheStoreIdByVolumeId added in v4.11.0

func (k *KubeClient) GetKvCacheStoreIdByVolumeId(volumeId string) (string, error)

GetKvCacheStoreIdByVolumeId returns kvCacheStoreId field of PV by volume id

func (*KubeClient) GetMappingHostsByVolumeId added in v4.12.0

func (k *KubeClient) GetMappingHostsByVolumeId(volumeId string) ([]string, error)

GetMappingHostsByVolumeId returns mapping hosts in VAs by volume id

func (*KubeClient) GetNodeTopology

func (k *KubeClient) GetNodeTopology(ctx context.Context, nodeName string) (map[string]string, error)

GetNodeTopology gets topology belonging to this node by node name

func (*KubeClient) GetPVByName

func (k *KubeClient) GetPVByName(ctx context.Context, name string) (*corev1.PersistentVolume, error)

GetPVByName gets the pv by pv name

func (*KubeClient) GetPod

func (k *KubeClient) GetPod(ctx context.Context, namespace, podName string) (*corev1.Pod, error)

GetPod gets a pod by pod name from this namespace

func (*KubeClient) GetSecret

func (k *KubeClient) GetSecret(ctx context.Context, secretName, namespace string) (*corev1.Secret, error)

GetSecret get secret

func (*KubeClient) GetVA added in v4.12.0

GetVA gets the VA object given its name

func (*KubeClient) GetVAsByPVName added in v4.12.0

func (k *KubeClient) GetVAsByPVName(pvName string) ([]*storagev1.VolumeAttachment, error)

GetVAsByPVName returns VA resources by pv name

func (*KubeClient) GetVolume

func (k *KubeClient) GetVolume(ctx context.Context, nodeName string, driverName string) (map[string]struct{}, error)

GetVolume gets all volumes belonging to this node from K8S side

func (*KubeClient) GetVolumeAttributes

func (k *KubeClient) GetVolumeAttributes(ctx context.Context, pvName string) (map[string]string, error)

GetVolumeAttributes returns volume attributes of PV

func (*KubeClient) GetVolumeAttrsByVolumeId added in v4.10.0

func (k *KubeClient) GetVolumeAttrsByVolumeId(volumeId string) ([]map[string]string, error)

GetVolumeAttrsByVolumeId returns volume attributes of PV by volume id

func (*KubeClient) GetVolumeConfiguration

func (k *KubeClient) GetVolumeConfiguration(ctx context.Context, pvName string) (map[string]string, error)

GetVolumeConfiguration return pvc's annotations

func (*KubeClient) ListPods

func (k *KubeClient) ListPods(ctx context.Context, namespace string) (*corev1.PodList, error)

ListPods lists all pods from this namespace

func (*KubeClient) SetClient added in v4.11.0

func (k *KubeClient) SetClient(client kubernetes.Interface)

SetClient set k8s client

func (*KubeClient) UpdateConfigmap

func (k *KubeClient) UpdateConfigmap(ctx context.Context, configmap *coreV1.ConfigMap) (*coreV1.ConfigMap, error)

UpdateConfigmap update configmap

func (*KubeClient) UpdateSecret

func (k *KubeClient) UpdateSecret(ctx context.Context, secret *corev1.Secret) (*corev1.Secret, error)

UpdateSecret update secret

func (*KubeClient) UpdateVA added in v4.12.0

UpdateVA update the VA

func (*KubeClient) UpdateVAStatus added in v4.12.0

UpdateVAStatus update the VA status

func (*KubeClient) UpdateVAsWithHostMap added in v4.12.0

func (k *KubeClient) UpdateVAsWithHostMap(ctx context.Context, volumeId string,
	hostMap map[string]map[string]interface{}) error

UpdateVAsWithHostMap updates VAs with the given host map

type NotFoundError added in v4.12.0

type NotFoundError struct{}

NotFoundError represents an error when there is no resource found in caches

func (NotFoundError) Error added in v4.12.0

func (e NotFoundError) Error() string

Error returns the error message for NotFoundError

type Option added in v4.12.0

type Option func(*k8sUtilsConfig)

func WithBurst added in v4.12.0

func WithBurst(burst int) Option

func WithEnableVolumeModify added in v4.12.0

func WithEnableVolumeModify(enable bool) Option

func WithQPS added in v4.12.0

func WithQPS(qps float32) Option

func WithVolumeLabels added in v4.12.0

func WithVolumeLabels(labels map[string]string) Option

func WithVolumeNamePrefix added in v4.12.0

func WithVolumeNamePrefix(prefix string) Option

type ResourceAccessor

type ResourceAccessor[T runtime.Object] struct {
	// contains filtered or unexported fields
}

ResourceAccessor provides the methods to get kubernetes resource.

func NewResourceAccessor

func NewResourceAccessor[T runtime.Object](informer cache.SharedIndexInformer,
	options ...func(*ResourceAccessor[T]) error) (*ResourceAccessor[T], error)

NewResourceAccessor returns a ResourceAccessor instance.

func (*ResourceAccessor[T]) GetByIndex

func (rw *ResourceAccessor[T]) GetByIndex(indexName, indexValue string) ([]T, error)

GetByIndex gets resource by index. To use this method, you must add the indexer first.

Jump to

Keyboard shortcuts

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