Kubernetes operations CLI
The Kubernetes operations CLI is the Go command-line application for checks, health queries, network tests, storage work, and migrations in a kURL cluster. It turns operator requests into Kubernetes API actions or calls to cluster services, then reports a result through output, logs, and process status.
System purpose
The CLI gives install and upgrade workflows one command surface for cluster operations that need to run outside a long-lived controller. It uses the active Kubernetes configuration to inspect resources, change selected resources, run short-lived jobs, and wait for the cluster to reach a required state.
The command layer keeps user-facing flow separate from domain work. Rook storage behavior is described in Rook storage operations, while shared Kubernetes resource behavior is described in Kubernetes resource helpers.
Command model
The command tree groups actions by the part of the kURL system that they affect. Each command can bind its flags to the shared configuration, while operation commands use the command context so a caller can stop a long-running action.
The top-level command maps the main operational areas to a small set of command groups.
flowchart TD
KURL[kurl]
KURL --> Host[host]
KURL --> Rook[rook]
KURL --> Longhorn[longhorn]
KURL --> Cluster[cluster]
KURL --> Netutil[netutil]
KURL --> ObjectStore[object-store]
KURL --> Version[version]
Host --> HostChecks[host checks and host data]
Rook --> RookOps[Rook health and migration operations]
Longhorn --> LonghornOps[Longhorn migration preparation]
Cluster --> ClusterOps[cluster checks and storage migration]
Netutil --> NetworkOps[interface and node connectivity checks]
ObjectStore --> StoreOps[object-store synchronization]
Command groups
The command groups provide distinct entry points for host state, cluster state, storage systems, and supporting utilities. The groups share the same CLI object, so output and configuration handling remain consistent across operations.
| Group | Operational goal |
|---|---|
host | Check whether a host is ready and inspect host identity data. |
cluster | Check cluster readiness, images, disk space, and storage migration state. |
rook | Check Rook health and coordinate Rook storage changes. |
longhorn | Prepare Longhorn for storage migration and restore its changed replica state. |
netutil | Inspect network interfaces and test node-to-node reachability. |
object-store | Copy buckets and objects between object stores. |
version | Print the CLI version. |
References: pkg/…/commands.go• L7-52 pkg/…/root.go• L9-27 pkg/…/host.go• L7-20 pkg/…/rook.go• L7-20 pkg/…/cluster.go• L7-20 pkg/…/longhorn.go• L36-47 pkg/…/netutil.go• L12-24 pkg/…/object_store.go• L14-25
Command context
The process creates one CLI service object before it builds the command tree. This object supplies configuration, file access, preflight runners, streams, and loggers. That boundary lets command behavior use real terminal resources in production and replace them in other callers.
The command setup binds persistent and local flags before an operation runs. Kubernetes commands then obtain clients from the current Kubernetes configuration, so the CLI acts on the cluster selected by the caller rather than on a built-in cluster target.
References: cmd/…/main.go• L12-27 pkg/…/cli.go• L15-26 pkg/…/cli.go• L38-51 pkg/…/root.go• L15-25
Cluster operation flows
The CLI supports both read-only checks and changes that prepare a cluster for migration. Read-only commands return facts or a pass/fail result. Migration commands add readiness gates, wait for work to finish, and report enough state for an operator or an automation step to decide what happens next.
Preflight checks
Preflight checks assess a host or a whole cluster before installation, joining, or upgrade work. The command reads an installer specification from a file or standard input, combines built-in checks with optional checks, and adds connection checks when the node role requires them.
The result has three useful classes: pass, warning, or failure. A warning is distinct from a failure because callers may choose to ignore it, but the default process result still marks it as a warning.
References: pkg/…/host_preflight.go• L43-187 pkg/…/host_preflight.go• L190-307 pkg/…/errors.go• L7-8 cmd/…/main.go• L21-27
Storage migration flows
Storage migration commands protect the cluster while its storage layout changes. The cluster migration command asks the Ekco operator whether the cluster is eligible, supports a status-only mode, requests approval, and waits for completion. The Longhorn command checks storage health and can record temporary replica changes so a later rollback can restore them.
The migration boundary is important: the CLI does not own the whole migration state machine. It coordinates with the storage system or the Ekco operator, applies the required gates, and turns remote status into a command result.
sequenceDiagram
participant User
participant CLI
participant Kubernetes as Kubernetes API
participant Operator as Storage operator
User->>CLI: Start migration command
CLI->>Operator: Read current and ready status
Operator-->>CLI: Eligibility and reason
alt Not ready
CLI-->>User: Stop with reason
else Ready
CLI->>User: Request approval unless automatic mode
User-->>CLI: Confirm
CLI->>Operator: Approve migration
loop Until complete or timeout
CLI->>Operator: Read migration status
Operator-->>CLI: Progress state
end
CLI-->>User: Completed or failed result
end
CLI->>Kubernetes: Inspect or restore related resources when needed
References: pkg/…/cluster_migrate_multinode_storage.go• L40-60 pkg/…/cluster_migrate_multinode_storage.go• L204-273 pkg/…/longhorn.go• L49-118 pkg/…/longhorn.go• L120-185
Health and readiness flows
Health and rollout commands turn an eventually consistent cluster into a clear command result. Rook commands check health or wait for a requested Rook or Ceph version. Longhorn preparation checks volume and node health before it allows migration to proceed.
These commands use time limits where a caller supplies them or where an operation has a fixed wait period. A timeout is a failure of the operation to reach its target state. It is not treated as proof that the target state is unhealthy.
References: pkg/…/rook_health.go• L12-37 pkg/…/rook_wait_for_health.go• L15-51 pkg/…/rook_wait_for_version.go• L14-81 pkg/…/longhorn.go• L146-181
Network and capacity checks
Supporting checks answer whether cluster nodes can communicate and whether a storage class has enough free space. The node connectivity command deploys temporary listeners and pingers, tests each useful node pair, and removes its temporary work. Disk checks select the named or default storage class, then use the matching storage system to measure space.
These checks are used as gates for larger workflows. Their value is not only the printed report; their process result lets install and migration automation stop before it creates an unsafe condition.
References: pkg/…/nodes_connectivity.go• L73-117 pkg/…/nodes_connectivity.go• L192-232 pkg/…/nodes_connectivity.go• L319-365 pkg/…/cluster_free_disk_space.go• L152-248
Kubernetes helper layer
The Kubernetes helper layer provides common actions that several CLI operations need. It hides repeated resource polling, pod execution, job cleanup, resource labeling, node lookup, and storage relationship checks behind small, reusable operations.
The helper layer has two client roles. The standard Kubernetes client handles core resources and workload resources. The controller-runtime client supports applying embedded resource sets and working with custom resources. The Kubernetes resource helpers page covers this layer in detail.
Resource readiness
Readiness helpers give commands a shared meaning for a ready pod, a ready deployment, and a completed DaemonSet rollout. They poll the API until the observed resource meets its target or the context or timeout ends.
This shared meaning matters during migrations and temporary deployments. A command can wait for the resource that it created before it uses that resource, instead of treating an accepted API write as proof that the workload is ready.
References: pkg/…/pod.go• L36-69 pkg/…/deployment.go• L12-43 pkg/…/daemonset.go• L13-35
Jobs and pod execution
Job helpers provide a short-lived work pattern for cluster checks and migrations. A job is created with kURL ownership labels, monitored until success or failure, and removed after its logs and container states are collected. Pod execution provides the lower-level path for commands that must run inside an existing pod.
The distinction between process failure and command failure is deliberate. Synchronous pod execution returns an exit code and captured output, while a job reports its completion state and logs. Callers can therefore decide whether a non-zero tool result is expected data or an operation error.
References: pkg/…/job.go• L17-39 pkg/…/job.go• L41-117 pkg/…/exec.go• L38-103
Resource identity and storage relationships
The helpers add kURL ownership and version labels to resources created by the CLI. They also translate Kubernetes relationships into useful facts, such as the node address for a Node or the pods that use a PersistentVolumeClaim.
Storage checks build on these facts to connect storage classes to persistent volumes, claims, pods, and nodes. This lets higher-level commands compare capacity with actual use without repeating Kubernetes object traversal.
References: pkg/…/labels.go• L7-21 pkg/…/node.go• L12-65 pkg/…/pod.go• L12-33 pkg/…/storage.go• L12-112
Resource apply and removal
The apply helpers let an operation render embedded Kubernetes resources, adjust them for the current cluster, and apply them through a Kubernetes client. Applied resources receive kURL labels so the operation can identify its own work. A delete helper supports removal of YAML-defined resources through kubectl when that path is required.
Temporary resources use this boundary to follow a complete lifecycle: render, apply, wait, inspect output, and remove. The lifecycle prevents diagnostic jobs and listeners from becoming permanent cluster objects.
References: pkg/…/apply.go• L14-37 pkg/…/nodes_connectivity.go• L194-232 pkg/…/nodes_connectivity.go• L290-317
Dependency compatibility
The module dependency set defines the compatibility boundary for the CLI and its Kubernetes helpers. The current module targets Go 1.27.3, Kubernetes client and API packages at v0.37.2, controller-runtime v0.25.2, Rook v1.21.1, and Longhorn v1.13.0.
The dependency rules keep Kubernetes API, Kustomize, and OpenAPI packages on compatible version lines. Changes to this boundary can affect both the command groups that talk to cluster services and the helper layer that reads or applies resources.
References: go.mod• L1-3 go.mod• L19-29 go.mod• L45-55 go.mod• L328-378
Error and result model
The CLI reports errors at the boundary between a user action and a cluster operation. Commands wrap failures with the action that failed, while the process entry point converts the final result into an exit status. Output and logs give human users context; exit statuses give automation a simple decision signal.
Input and dependency errors
Commands reject invalid argument counts and invalid values before they start cluster work. After validation, failures to load the Kubernetes configuration, create a client, read input, call a remote service, or decode a response return as wrapped errors.
The command tree silences usage text for operation failures where a syntax reminder does not help. This keeps operational faults distinct from command-line syntax faults and preserves the underlying action in the error message.
References: pkg/…/host_preflight.go• L45-61 pkg/…/nodes_connectivity.go• L79-111 pkg/…/cluster_migrate_multinode_storage.go• L115-161 pkg/…/cluster_free_disk_space.go• L189-224
Exit status semantics
The process normally exits with status 0 for success and 1 for an operation failure. Preflight warnings have a separate result through ErrWarn, which the main program maps to status 3. Commands that are intended for shell tests can also use their own status contract, such as a non-zero result when the cluster lacks enough block devices.
Callers should use the documented status for automation instead of parsing human output. A warning is not the same as a failed operation, but it still needs an explicit policy from the caller.
References: cmd/…/main.go• L21-27 pkg/…/errors.go• L7-8 pkg/…/host_preflight.go• L148-171 pkg/…/rook_has_sufficient_blockdevices.go• L13-35
Cancellation and cleanup
Long operations use command contexts for cancellation and bounded waits. Temporary jobs and resources are removed after use, including cleanup that can continue after the caller context is canceled when necessary.
Cleanup is part of the command contract because leftover listeners, pingers, or jobs can affect later checks and can make a migration look active when it is not. A failed cleanup is reported through logs or a wrapped error according to the resource lifecycle.
References: pkg/…/nodes_connectivity.go• L113-125 pkg/…/job.go• L51-60 pkg/…/cluster_migrate_multinode_storage.go• L241-271 pkg/…/exec.go• L64-78
Change checklist
When these files or sections are changed, remember to consider these:
- When a command is added or moved in pkg/…/commands.go, check its parent group, flag binding, help path, and any related documentation link.
- When a command changes its exit result, check both cmd/…/main.go and callers that use preflight or capacity checks as shell gates.
- When a migration status or readiness contract changes, keep the remote Ekko endpoint, response fields, timeout behavior, and operator-facing messages aligned.
- When temporary Kubernetes resources change, preserve kURL labels, readiness waits, selector use, and cleanup order together.
- When storage class or provisioner handling changes, update the mapping between the CLI decision and the corresponding storage helper or client.
- When helper readiness rules change, review every command that treats the helper result as a migration or deployment gate.
- When Go or Kubernetes dependencies change in
go.mod, check the client and API compatibility assumptions used by command groups and helper operations.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| The active Kubernetes configuration is missing or points to the wrong cluster. | A command cannot start or may inspect the wrong cluster. | Obtain the client from the caller's Kubernetes configuration and fail before changing resources. |
| A preflight has warnings and the caller does not set an ignore policy. | The command returns the warning status instead of reporting success. | Handle ErrWarn or use the explicit warning and exit-code flags. |
| A storage migration is not ready or reports a failed status. | The CLI stops before approval or returns a migration error. | Check cluster and operator readiness, then poll status until completion or timeout. |
| A temporary listener or pinger does not become ready. | Node connectivity cannot be proved and temporary work may remain. | Wait for rollout, use context bounds, and delete the pinger and related pods. |
| A job fails or its pod logs cannot be read. | A cluster check loses its evidence or reports a failed operation. | Return container state and logs where possible, and treat missing logs on a successful job as an error. |
| The selected storage provisioner is unsupported. | The disk check cannot measure capacity for that class. | Recognize only the supported OpenEBS and Rook provisioners and report unsupported classes. |
| A Go or Kubernetes dependency moves outside the supported compatibility set. | Commands or resource helpers can fail to build or can use mismatched API behavior. | Keep the version set and compatibility rules in go.mod aligned across Kubernetes, Kustomize, OpenAPI, Rook, and Longhorn clients. |
Key files
| File | Why to read it |
|---|---|
| cmd/…/main.go | Shows process startup and the final exit-status contract. |
| pkg/…/commands.go | Shows the public command tree and command ownership. |
| pkg/…/cli.go | Shows the shared CLI services used by commands. |
| pkg/…/host_preflight.go | Shows the preflight input, check assembly, result, and warning flow. |
| pkg/…/cluster_migrate_multinode_storage.go | Shows coordination with the Ekco storage migration service. |
| pkg/…/longhorn.go | Shows storage readiness checks and reversible Longhorn preparation. |
| pkg/…/nodes_connectivity.go | Shows a complete temporary-resource lifecycle for a cluster network test. |
| pkg/…/job.go | Shows job execution, status collection, log capture, and cleanup. |
| pkg/…/apply.go | Shows the shared boundary for applying and deleting Kubernetes resources. |
| pkg/…/storage.go | Shows how storage usage is related to claims, pods, and nodes. |
go.mod | Shows the Go, Kubernetes, storage-system, and compatibility versions that set the CLI boundary. |