Documentation
¶
Overview ¶
Package kubectl provides kubectl operations.
Index ¶
- Variables
- type Backend
- type Client
- func (c *Client) Apply(ctx context.Context, data []byte, namespace string) error
- func (c *Client) Delete(ctx context.Context, resourceType string, name string, namespace string) error
- func (c *Client) DeletePodsByLabel(ctx context.Context, namespace string, labelSelector string) (int, error)
- func (c *Client) Get(ctx context.Context, resourceType string, name string, namespace string) (string, error)
- func (c *Client) GetVersion(ctx context.Context) (resp *VersionResponse, err error)
- func (c *Client) Scale(ctx context.Context, resourceType string, name string, namespace string, ...) error
- func (c *Client) Wait(ctx context.Context, resourceType string, name string, namespace string, ...) error
- type ClientVersion
- type ServerVersion
- type VersionResponse
Constants ¶
This section is empty.
Variables ¶
var ErrGettingVersion = errors.New("getting kubernetes server version")
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend interface {
// Get retrieves a Kubernetes resource and returns its JSON representation.
// resourceType: e.g., "deployment", "statefulset", "pod"
// name: resource name
// namespace: Kubernetes namespace
Get(ctx context.Context, resourceType string, name string, namespace string) (string, error)
// DeletePodsByLabel deletes all pods matching a label selector in a namespace.
// Returns the number of pods deleted and any error encountered.
// If no pods match, returns (0, nil).
DeletePodsByLabel(ctx context.Context, namespace string, labelSelector string) (int, error)
// GetVersion returns the Kubernetes server version information.
GetVersion(ctx context.Context) (*VersionResponse, error)
// Scale sets the number of replicas for a deployment or statefulset.
// resourceType: "deployment" or "statefulset"
// name: resource name
// namespace: Kubernetes namespace
// replicas: desired number of replicas
Scale(ctx context.Context, resourceType string, name string, namespace string, replicas int) error
// Apply applies a Kubernetes resource from JSON input via stdin.
// jsonData: JSON representation of the resource
// namespace: Kubernetes namespace
Apply(ctx context.Context, jsonData []byte, namespace string) error
// Delete deletes a Kubernetes resource.
// resourceType: e.g., "deployment", "statefulset", "pod"
// name: resource name
// namespace: Kubernetes namespace
Delete(ctx context.Context, resourceType string, name string, namespace string) error
// Wait waits for a condition to be met on a Kubernetes resource.
// resourceType: e.g., "deployment", "statefulset"
// name: resource name
// namespace: Kubernetes namespace
// condition: condition to wait for (e.g., "available", "delete")
// timeout: maximum time to wait (e.g., "60s", "5m")
Wait(ctx context.Context, resourceType string, name string, namespace string, condition string, timeout string) error
}
Backend defines the interface for low-level kubectl operations.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client implements the Backend interface using the kubectl CLI.
func NewClient ¶
func NewClient(executor executor.CommandRunner) *Client
NewClient creates a new kubectl client.
func (*Client) Delete ¶
func (c *Client) Delete(ctx context.Context, resourceType string, name string, namespace string) error
Delete deletes a Kubernetes resource.
func (*Client) DeletePodsByLabel ¶
func (c *Client) DeletePodsByLabel(ctx context.Context, namespace string, labelSelector string) (int, error)
DeletePodsByLabel deletes all pods matching a label selector in a namespace.
func (*Client) Get ¶
func (c *Client) Get(ctx context.Context, resourceType string, name string, namespace string) (string, error)
Get retrieves a Kubernetes resource and returns its JSON representation.
func (*Client) GetVersion ¶
func (c *Client) GetVersion(ctx context.Context) (resp *VersionResponse, err error)
GetVersion returns the Kubernetes server version information.
type ClientVersion ¶
type ClientVersion struct {
Major string `json:"major"`
Minor string `json:"minor"`
GitVersion string `json:"gitVersion"`
GitCommit string `json:"gitCommit"`
GitTreeState string `json:"gitTreeState"`
BuildDate time.Time `json:"buildDate"`
GoVersion string `json:"goVersion"`
Compiler string `json:"compiler"`
Platform string `json:"platform"`
}
ClientVersion represents the kubectl client version information.
type ServerVersion ¶
type ServerVersion struct {
Major string `json:"major"`
Minor string `json:"minor"`
EmulationMajor string `json:"emulationMajor"`
EmulationMinor string `json:"emulationMinor"`
MinCompatibilityMajor string `json:"minCompatibilityMajor"`
MinCompatibilityMinor string `json:"minCompatibilityMinor"`
GitVersion string `json:"gitVersion"`
GitCommit string `json:"gitCommit"`
GitTreeState string `json:"gitTreeState"`
BuildDate time.Time `json:"buildDate"`
GoVersion string `json:"goVersion"`
Compiler string `json:"compiler"`
Platform string `json:"platform"`
}
ServerVersion represents the Kubernetes server version information.
type VersionResponse ¶
type VersionResponse struct {
ClientVersion ClientVersion `json:"clientVersion"`
KustomizeVersion string `json:"kustomizeVersion"`
ServerVersion ServerVersion `json:"serverVersion"`
}
VersionResponse represents the response from kubectl version command.