eksctl

package
v6.16.0 Latest Latest
Warning

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

Go to latest
Published: Apr 17, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package eksctl wraps the `eksctl` CLI binary as a KSail client.

eksctl's programmatic Go library exposes Upgrade/Delete/nodegroup operations via `github.com/weaveworks/eksctl/pkg/actions/...` but does not expose a programmatic Create API — cluster creation is tightly coupled to Cobra and cmdutils inside `pkg/ctl/create/cluster.go`. KSail therefore adopts a hybrid integration:

  • Shell out to the `eksctl` CLI binary for all write operations in this client package.
  • Embed the Go library directly in the EKS provisioner for operations that the library exposes cleanly (Upgrade, Delete, nodegroup scale).

This package provides the binary side of the hybrid. The upstream CLI is released from https://github.com/eksctl-io/eksctl (module path is still github.com/weaveworks/eksctl for historical reasons).

The client is fully testable via an injectable Runner interface so unit tests do not need the eksctl binary on PATH.

Index

Constants

View Source
const DefaultBinary = "eksctl"

DefaultBinary is the default binary name used to locate eksctl on PATH.

Variables

View Source
var ErrBinaryNotFound = errors.New(
	"eksctl binary not found on PATH; install from https://eksctl.io/installation/",
)

ErrBinaryNotFound is returned when the `eksctl` binary cannot be located on PATH and the caller did not inject a custom binary path or Runner. Cluster creation on the EKS distribution is delegated to the eksctl CLI; see https://eksctl.io/installation/ for installation instructions.

View Source
var ErrClusterNotFound = errors.New("eks cluster not found")

ErrClusterNotFound is returned when an `eksctl get cluster` lookup for a named cluster returns an empty result set.

View Source
var ErrEmptyClusterName = errors.New("cluster name must not be empty")

ErrEmptyClusterName is returned when an operation requires a cluster name but an empty string was supplied.

View Source
var ErrEmptyConfigPath = errors.New("config path must not be empty")

ErrEmptyConfigPath is returned when a config-file-based operation is invoked without a config path.

View Source
var ErrEmptyNodegroupName = errors.New("nodegroup name must not be empty")

ErrEmptyNodegroupName is returned when a nodegroup operation requires a nodegroup name but an empty string was supplied.

View Source
var ErrExecFailed = errors.New("eksctl command failed")

ErrExecFailed wraps a non-zero exit from the eksctl binary.

Functions

This section is empty.

Types

type Client

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

Client is the eksctl CLI wrapper.

func NewClient

func NewClient(opts ...Option) *Client

NewClient returns a Client using the eksctl binary on PATH and the default ExecRunner. Use the Options to override either.

func (*Client) Binary

func (c *Client) Binary() string

Binary returns the binary name this client will invoke.

func (*Client) CheckAvailable

func (c *Client) CheckAvailable() error

CheckAvailable verifies the eksctl binary can be found and is executable. When a custom binary path was supplied via WithBinary, the check uses exec.LookPath on that exact value (which also resolves relative paths).

This method is intentionally side-effect free: it does not call `eksctl version` because doing so on every `ksail cluster create` would add hundreds of milliseconds of latency.

func (*Client) CreateCluster

func (c *Client) CreateCluster(ctx context.Context, configPath, region string) error

CreateCluster invokes `eksctl create cluster -f <configPath>`. Pass "" for region unless overriding what the config file specifies.

func (*Client) DeleteCluster

func (c *Client) DeleteCluster(
	ctx context.Context,
	name, region, configPath string,
	wait bool,
) error

DeleteCluster invokes `eksctl delete cluster --name <name> [--region <region>]`. When configPath is non-empty, `--config-file` is used instead and takes precedence (matching eksctl's own flag precedence).

func (*Client) Exec

func (c *Client) Exec(ctx context.Context, args ...string) ([]byte, []byte, error)

Exec runs the eksctl binary with the given arguments. It is the low-level escape hatch used by all higher-level methods on this client and can be used directly when a helper has not been written yet.

func (*Client) ExecWithStdin

func (c *Client) ExecWithStdin(
	ctx context.Context,
	stdin io.Reader,
	args ...string,
) ([]byte, []byte, error)

ExecWithStdin runs eksctl with the given arguments and feeds stdin from the provided reader. Useful for `eksctl create cluster -f -` style invocations.

func (*Client) GetCluster

func (c *Client) GetCluster(
	ctx context.Context,
	name, region string,
) (*ClusterSummary, error)

GetCluster returns the summary for a named cluster. Returns ErrClusterNotFound when no cluster with the given name exists.

func (*Client) ListClusters

func (c *Client) ListClusters(ctx context.Context, region string) ([]ClusterSummary, error)

ListClusters returns the summary of all EKS clusters in the given region. Pass "" for region to rely on eksctl's default (AWS_REGION env or AWS profile).

func (*Client) ListNodegroups

func (c *Client) ListNodegroups(
	ctx context.Context,
	clusterName, region string,
) ([]NodegroupSummary, error)

ListNodegroups returns the nodegroup summaries for a named cluster.

func (*Client) ScaleNodegroup

func (c *Client) ScaleNodegroup(
	ctx context.Context,
	clusterName, nodegroupName, region string,
	desiredCapacity int,
	minSize, maxSize int,
) error

ScaleNodegroup invokes `eksctl scale nodegroup` with the provided sizes. minSize and maxSize are optional; pass a negative value to skip.

func (*Client) UpgradeCluster

func (c *Client) UpgradeCluster(
	ctx context.Context,
	configPath string,
	approve bool,
) error

UpgradeCluster invokes `eksctl upgrade cluster -f <configPath>`. When approve is true, `--approve` is appended, which eksctl requires to perform (rather than preview) the upgrade.

type ClusterSummary

type ClusterSummary struct {
	Name   string `json:"Name"`
	Region string `json:"Region"`
	// EKSCTLCreated reports whether the cluster was created by eksctl.
	// eksctl prints the string "True"/"False"; we keep it as-is.
	EKSCTLCreated string `json:"EksctlCreated"`
}

ClusterSummary represents a single cluster entry returned by `eksctl get cluster -o json`. Field tags preserve eksctl's PascalCase JSON keys (eksctl emits these names verbatim).

type ExecRunner

type ExecRunner struct{}

ExecRunner is the default Runner that shells out via os/exec.

func (ExecRunner) Run

func (ExecRunner) Run(
	ctx context.Context,
	name string,
	args []string,
	stdin io.Reader,
) ([]byte, []byte, error)

Run executes the given command using os/exec and returns the collected stdout and stderr buffers.

type NodegroupSummary

type NodegroupSummary struct {
	Cluster       string `json:"Cluster"`
	Name          string `json:"Name"`
	Status        string `json:"Status"`
	DesiredCap    int    `json:"DesiredCapacity"`
	MinSize       int    `json:"MinSize"`
	MaxSize       int    `json:"MaxSize"`
	InstanceType  string `json:"InstanceType"`
	ImageID       string `json:"ImageID"`
	CreationTime  string `json:"CreationTime"`
	NodeGroupType string `json:"NodeGroupType"`
	Version       string `json:"Version"`
}

NodegroupSummary represents a single managed nodegroup returned by `eksctl get nodegroup --cluster <name> -o json`. Field tags preserve eksctl's PascalCase JSON keys.

type Option

type Option func(*Client)

Option configures a Client at construction time.

func WithBinary

func WithBinary(binary string) Option

WithBinary overrides the binary name/path used to invoke eksctl. Useful for tests and for callers that ship a vendored eksctl binary.

func WithRunner

func WithRunner(runner Runner) Option

WithRunner overrides the Runner used to execute eksctl commands. Primarily useful for testing without the eksctl binary on PATH.

type Runner

type Runner interface {
	Run(
		ctx context.Context,
		name string,
		args []string,
		stdin io.Reader,
	) (stdout, stderr []byte, err error)
}

Runner executes an external command and returns its stdout and stderr. Exposed as an interface so tests can inject a fake without relying on the eksctl binary being installed.

Jump to

Keyboard shortcuts

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