client

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2025 License: MPL-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DynamicKubernetesClient

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

DynamicKubernetesClient implements KubernetesClient using dynamic client

func NewDynamicKubernetesClient

func NewDynamicKubernetesClient() *DynamicKubernetesClient

NewDynamicKubernetesClient creates a new DynamicKubernetesClient

func (*DynamicKubernetesClient) ApplyResource

ApplyResource applies a resource using server-side apply

func (*DynamicKubernetesClient) CheckHealth

func (c *DynamicKubernetesClient) CheckHealth(ctx context.Context, endpoint string) error

CheckHealth verifies Kubernetes API connectivity by listing nodes using the dynamic client. If an endpoint is specified, it overrides the default kubeconfig for this check. Returns an error if the client cannot be initialized or the API is unreachable.

func (*DynamicKubernetesClient) DeleteResource

func (c *DynamicKubernetesClient) DeleteResource(gvr schema.GroupVersionResource, namespace, name string, opts metav1.DeleteOptions) error

DeleteResource deletes a resource

func (*DynamicKubernetesClient) GetNodeReadyStatus

func (c *DynamicKubernetesClient) GetNodeReadyStatus(ctx context.Context, nodeNames []string) (map[string]bool, error)

GetNodeReadyStatus returns a map of node names to their Ready condition status. It checks the Ready condition for each specified node using the dynamic client. If nodeNames is empty, all nodes are checked. Nodes not found are omitted from the result. Returns a map of node names to Ready status (true if Ready, false if NotReady), or an error if listing fails.

func (*DynamicKubernetesClient) GetResource

func (c *DynamicKubernetesClient) GetResource(gvr schema.GroupVersionResource, namespace, name string) (*unstructured.Unstructured, error)

GetResource gets a resource by name and namespace

func (*DynamicKubernetesClient) ListResources

ListResources lists resources in a namespace

func (*DynamicKubernetesClient) PatchResource

func (c *DynamicKubernetesClient) PatchResource(gvr schema.GroupVersionResource, namespace, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions) (*unstructured.Unstructured, error)

PatchResource patches a resource

type KubernetesClient

type KubernetesClient interface {
	GetResource(gvr schema.GroupVersionResource, namespace, name string) (*unstructured.Unstructured, error)
	ListResources(gvr schema.GroupVersionResource, namespace string) (*unstructured.UnstructuredList, error)
	ApplyResource(gvr schema.GroupVersionResource, obj *unstructured.Unstructured, opts metav1.ApplyOptions) (*unstructured.Unstructured, error)
	DeleteResource(gvr schema.GroupVersionResource, namespace, name string, opts metav1.DeleteOptions) error
	PatchResource(gvr schema.GroupVersionResource, namespace, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions) (*unstructured.Unstructured, error)
	CheckHealth(ctx context.Context, endpoint string) error
	GetNodeReadyStatus(ctx context.Context, nodeNames []string) (map[string]bool, error)
}

KubernetesClient defines methods for Kubernetes resource operations

type MockKubernetesClient

type MockKubernetesClient struct {
	GetResourceFunc        func(gvr schema.GroupVersionResource, namespace, name string) (*unstructured.Unstructured, error)
	ListResourcesFunc      func(gvr schema.GroupVersionResource, namespace string) (*unstructured.UnstructuredList, error)
	ApplyResourceFunc      func(gvr schema.GroupVersionResource, obj *unstructured.Unstructured, opts metav1.ApplyOptions) (*unstructured.Unstructured, error)
	DeleteResourceFunc     func(gvr schema.GroupVersionResource, namespace, name string, opts metav1.DeleteOptions) error
	PatchResourceFunc      func(gvr schema.GroupVersionResource, namespace, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions) (*unstructured.Unstructured, error)
	CheckHealthFunc        func(ctx context.Context, endpoint string) error
	GetNodeReadyStatusFunc func(ctx context.Context, nodeNames []string) (map[string]bool, error)
}

MockKubernetesClient is a mock implementation of KubernetesClient interface for testing

func NewMockKubernetesClient

func NewMockKubernetesClient() *MockKubernetesClient

NewMockKubernetesClient creates a new MockKubernetesClient

func (*MockKubernetesClient) ApplyResource

ApplyResource implements KubernetesClient interface

func (*MockKubernetesClient) CheckHealth

func (m *MockKubernetesClient) CheckHealth(ctx context.Context, endpoint string) error

CheckHealth implements KubernetesClient interface

func (*MockKubernetesClient) DeleteResource

func (m *MockKubernetesClient) DeleteResource(gvr schema.GroupVersionResource, namespace, name string, opts metav1.DeleteOptions) error

DeleteResource implements KubernetesClient interface

func (*MockKubernetesClient) GetNodeReadyStatus

func (m *MockKubernetesClient) GetNodeReadyStatus(ctx context.Context, nodeNames []string) (map[string]bool, error)

GetNodeReadyStatus implements KubernetesClient interface

func (*MockKubernetesClient) GetResource

func (m *MockKubernetesClient) GetResource(gvr schema.GroupVersionResource, namespace, name string) (*unstructured.Unstructured, error)

GetResource implements KubernetesClient interface

func (*MockKubernetesClient) ListResources

ListResources implements KubernetesClient interface

func (*MockKubernetesClient) PatchResource

func (m *MockKubernetesClient) PatchResource(gvr schema.GroupVersionResource, namespace, name string, pt types.PatchType, data []byte, opts metav1.PatchOptions) (*unstructured.Unstructured, error)

PatchResource implements KubernetesClient interface

Jump to

Keyboard shortcuts

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