client

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MPL-2.0 Imports: 15 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) ListResourcesByLabel added in v0.9.0

func (c *DynamicKubernetesClient) ListResourcesByLabel(gvr schema.GroupVersionResource, namespace, labelSelector string) (*unstructured.UnstructuredList, error)

ListResourcesByLabel lists resources of the given kind narrowed to a label selector; an empty namespace lists across all namespaces. It lets callers ask the API server to return only the objects they care about (e.g. this context's CLI-placed secrets) rather than listing everything and filtering.

func (*DynamicKubernetesClient) PatchResource

PatchResource patches a resource. The caller-supplied ctx is honoured so parent cancellation (e.g. Ctrl+C propagated through cmd.Context()) and short caller-defined deadlines (e.g. Notify's 10s notifyTimeout) actually preempt in-flight requests. A requestTimeout is layered on top as an upper bound so callers that pass context.Background() still get the pre-existing 30s cap.

func (*DynamicKubernetesClient) ResourceFor added in v0.9.0

ResourceFor resolves a GroupVersionKind to its GroupVersionResource using the API server's discovery data, so callers holding only an ownerReference (apiVersion + kind) can address the owning object with the dynamic client. Resolution is cached by the deferred discovery mapper.

type KubernetesClient

type KubernetesClient interface {
	GetResource(gvr schema.GroupVersionResource, namespace, name string) (*unstructured.Unstructured, error)
	ListResources(gvr schema.GroupVersionResource, namespace string) (*unstructured.UnstructuredList, error)
	ListResourcesByLabel(gvr schema.GroupVersionResource, namespace, labelSelector 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
	ResourceFor(gvk schema.GroupVersionKind) (schema.GroupVersionResource, error)
	PatchResource(ctx context.Context, 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)
	ListResourcesByLabelFunc func(gvr schema.GroupVersionResource, namespace, labelSelector 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
	ResourceForFunc          func(gvk schema.GroupVersionKind) (schema.GroupVersionResource, error)
	PatchResourceFunc        func(ctx context.Context, 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) ListResourcesByLabel added in v0.9.0

func (m *MockKubernetesClient) ListResourcesByLabel(gvr schema.GroupVersionResource, namespace, labelSelector string) (*unstructured.UnstructuredList, error)

ListResourcesByLabel implements KubernetesClient interface

func (*MockKubernetesClient) PatchResource

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

PatchResource implements KubernetesClient interface

func (*MockKubernetesClient) ResourceFor added in v0.9.0

ResourceFor implements KubernetesClient interface

Jump to

Keyboard shortcuts

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