k8s

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2025 License: GPL-3.0 Imports: 32 Imported by: 0

Documentation

Overview

Package k8s provides a k8s client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConnectToServer

func ConnectToServer(socket string) (*grpc.ClientConn, error)

func CreateListener

func CreateListener(addr string) (net.Listener, error)

CreateListener creates a listener on the specified endpoint. based from k8s.io/kubernetes/pkg/kubelet/util Nicked from https://github.com/k8snetworkplumbingwg/multus-cni/blob/v4.2.0/pkg/kubeletclient/kubeletclient_test.go

Types

type Client

type Client struct {
	Logger            *slog.Logger
	Hostname          string
	Config            *rest.Config
	Clientset         kubernetes.Interface
	PodResourceClient podresourcesapi.PodResourcesListerClient
	PodInformer       coreinformers.PodInformer
	// contains filtered or unexported fields
}

func New

func New(kubeconfigPath string, kubeletSocket string, logger *slog.Logger) (*Client, error)

New returns an instance of Client struct.

func (*Client) Close

func (c *Client) Close() error

Close stops clients and release resources.

func (*Client) ConfigMap

func (c *Client) ConfigMap(ctx context.Context, ns string, name string) (map[string]string, error)

ConfigMap returns contents of a configMap.

func (*Client) Exec

func (c *Client) Exec(ctx context.Context, ns string, pod string, container string, cmd []string) ([]byte, []byte, error)

Exec executes a given command in the pod and returns output.

func (*Client) ListPods

func (c *Client) ListPods(ctx context.Context, ns string, opts metav1.ListOptions) ([]Pod, error)

ListPods returns lists all current pods in the cluster.

func (*Client) ListPodsWithDevs

func (c *Client) ListPodsWithDevs(ctx context.Context) ([]Pod, error)

ListPodsWithDevs returns a slice of pods with devices associated with each pod.

func (*Client) ListUsers

func (c *Client) ListUsers(ctx context.Context, ns string) (map[string][]string, error)

ListUsers returns a slice of map of namespaces to users fetched from rolebindings.

func (*Client) NewPodInformer

func (c *Client) NewPodInformer(resyncPeriod time.Duration) error

NewInformer creates new pod informer using current client.

func (*Client) Pods

func (c *Client) Pods() []*v1.Pod

Pods returns a slice of pods provided by shared informer.

func (*Client) StartInformer

func (c *Client) StartInformer() error

StartInformer starts shared informers and waits for the shared informer cache to synchronize.

type Container

type Container struct {
	Name    string
	UID     string
	Devices []Device
}

Container is a representation of K8s container resource.

type Device

type Device struct {
	Name string
	IDs  []string
}

Device is a representation of a allocatable device for k8s containers.

type FakeResourceServer

func FakeKubeletServer

func FakeKubeletServer(socketDir string, listResp *podresourcesapi.ListPodResourcesResponse, getAllocatableResourcesResp *podresourcesapi.AllocatableResourcesResponse) (*FakeResourceServer, error)

FakeKubeletServer returns a mock API resource server.

type Pod

type Pod struct {
	Namespace  string
	Name       string
	UID        string
	CreatedAt  time.Time
	StartedAt  time.Time
	DeletedAt  time.Time
	Status     string
	QoS        string
	Containers []Container
}

Pod is a representation of K8s pod resource.

Jump to

Keyboard shortcuts

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