k8s

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Overview

Package k8s provides Kubernetes client functionality for the k8s-controller application. It handles kubeconfig loading, client creation, and connection testing with structured logging.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadKubeconfig

func LoadKubeconfig(config ClientConfig, logger zerolog.Logger) (*rest.Config, error)

LoadKubeconfig loads the Kubernetes configuration from various sources. It follows the standard precedence: in-cluster config > kubeconfig file > default locations. Returns a *rest.Config that can be used to create a Kubernetes client.

Types

type Client

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

Client wraps the Kubernetes clientset with additional functionality. It provides structured logging and connection management for k8s operations.

func CreateClient

func CreateClient(config ClientConfig, logger zerolog.Logger) (*Client, error)

CreateClient creates a new Kubernetes client with the provided configuration. It returns a Client instance that wraps the clientset with additional functionality.

func (*Client) Close

func (c *Client) Close() error

Close performs cleanup operations for the client. Currently, there's no cleanup needed for the Kubernetes client, but this method is provided for future extensibility.

func (*Client) GetClientset

func (c *Client) GetClientset() kubernetes.Interface

GetClientset returns the underlying Kubernetes clientset. This allows access to all Kubernetes API operations.

func (*Client) GetConfig

func (c *Client) GetConfig() *rest.Config

GetConfig returns the underlying REST config. This can be useful for creating other types of clients.

func (*Client) ListDeployments added in v0.6.0

func (c *Client) ListDeployments(ctx context.Context, opts ListDeploymentsOptions) ([]DeploymentInfo, error)

ListDeployments retrieves deployments from the Kubernetes cluster based on the provided options. It returns a slice of DeploymentInfo structs containing essential deployment information.

func (*Client) TestConnection

func (c *Client) TestConnection(ctx context.Context) error

TestConnection verifies that the client can connect to the Kubernetes API server. It performs a simple API call to list namespaces with a timeout.

type ClientConfig

type ClientConfig struct {
	// KubeconfigPath specifies the path to the kubeconfig file.
	// If empty, the default locations will be checked.
	KubeconfigPath string

	// Context specifies which context to use from the kubeconfig.
	// If empty, the current context will be used.
	Context string
}

ClientConfig holds configuration options for creating a Kubernetes client.

type DeploymentInfo added in v0.6.0

type DeploymentInfo struct {
	Name      string `json:"name"`
	Namespace string `json:"namespace"`
	Replicas  struct {
		Desired   int32 `json:"desired"`
		Available int32 `json:"available"`
		Ready     int32 `json:"ready"`
		Updated   int32 `json:"updated"`
	} `json:"replicas"`
	Age       time.Duration `json:"age"`
	Images    []string      `json:"images"`
	CreatedAt time.Time     `json:"created_at"`
}

DeploymentInfo represents essential information about a Kubernetes deployment. This struct contains only the fields needed for listing operations.

type ListDeploymentsOptions added in v0.6.0

type ListDeploymentsOptions struct {
	// Namespace specifies the namespace to list deployments from.
	// If empty, deployments from all namespaces will be listed.
	Namespace string

	// LabelSelector allows filtering deployments by labels.
	// Uses the standard Kubernetes label selector syntax.
	LabelSelector string

	// FieldSelector allows filtering deployments by fields.
	// Uses the standard Kubernetes field selector syntax.
	FieldSelector string
}

ListDeploymentsOptions holds options for listing deployments.

Jump to

Keyboard shortcuts

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