Kubernetes resource helpers
The Kubernetes resource helpers provide shared operations for the cluster operations CLI. They turn manifests into managed resources, inspect cluster state, wait for resources to become usable, run short-lived work, and measure storage use so higher-level workflows can focus on their task.
Resource application and ownership
Manifest application combines embedded Kustomize resources with run-time changes, then applies the result to the cluster. The apply path adds the kurl.sh/managed and kurl.sh/version labels so later actions can identify resources managed by this product. Deletion accepts manifest data and passes it to kubectl, with caller-supplied options such as ignoring missing resources. (See the related Kubernetes operations CLI.)
KubectlApply is used by storage migration to create a temporary migrator deployment. Other callers use the same rendering model to set a namespace, image, environment, or node placement before applying a resource. This keeps the manifest as a base while allowing an operation to supply values that are known only at run time.
References: pkg/…/apply.go• L14-37 pkg/…/labels.go• L7-21 pkg/…/flexvolume.go• L215-237 pkg/…/nodes_connectivity.go• L194-231
Resource readiness
Readiness helpers turn Kubernetes status into clear checkpoints for larger workflows. A pod is ready when it has a true PodReady condition. A deployment is ready when Kubernetes has observed its generation and its updated, available, and ready replica counts all meet the requested count.
The helpers poll until the resource reaches the required state or the caller's context ends. A daemonset rollout uses the current node count as the expected number of ready daemon pods and requires that count to remain ready across repeated checks. These checks let callers avoid using a resource while it is still starting or changing.
flowchart LR
A[Apply resource] --> B[Read status]
B --> C{Ready state?}
C -- No --> D[Wait and check again]
D --> B
C -- Yes --> E[Run next operation]
C -- Context ends or timeout --> F[Return failure]
References: pkg/…/pod.go• L31-69 pkg/…/deployment.go• L12-43 pkg/…/daemonset.go• L13-34 pkg/…/flexvolume.go• L239-261 pkg/…/nodes_connectivity.go• L213-223
Pod and node information
Pod and node helpers provide the facts needed to place work and check cluster paths. Pod listing can use a label selector, and PVC use is determined from the pod's namespace and declared volume claims. Node helpers expose internal node addresses and convert node taints into tolerations.
The combined toleration set contains one entry for each distinct taint seen across all nodes. This allows a daemonset or job intended to cover the cluster to run on tainted nodes as well. An internal IP lookup fails when the named node is absent or when the node has no internal address, rather than returning an incomplete target.
References: pkg/…/pod.go• L12-34 pkg/…/node.go• L12-65 pkg/…/nodes_connectivity.go• L194-207 pkg/…/nodes_connectivity.go• L368-425
Job execution and cleanup
Job helpers provide a bounded way to run a Kubernetes job and collect its result. The flow creates the job with product ownership labels, waits for a success or failure status, finds the job pod, and returns logs and container states. It removes the job and its owned resources after the run, including when the caller has already canceled its context.
The result separates three outcomes: a successful job, a job that completed with failure, and a job that could not be observed before the timeout. Log collection is per container, which lets callers parse a named output stream or report the state of each container when work fails.
sequenceDiagram
participant Caller
participant Helpers
participant Cluster
Caller->>Helpers: Run job
Helpers->>Cluster: Create labeled Job
loop Until complete or timeout
Helpers->>Cluster: Read Job status
end
Helpers->>Cluster: Find pod and read container logs
Helpers-->>Caller: Logs and container states
Helpers->>Cluster: Delete Job and owned resources
Node image checks use this flow to run a job on a node and read its image list. Node connectivity checks use the status wait without needing the job's logs. Temporary disk checks also use jobs to inspect node-mounted storage.
References: pkg/…/job.go• L17-117 pkg/…/nodes.go• L151-189 pkg/…/openebs_free_disk_space_getter.go• L64-118 pkg/…/nodes_connectivity.go• L319-365
Container execution
Container execution provides a direct command channel for work that must run inside an existing pod. It connects to the Kubernetes pod exec subresource and can stream standard input, standard output, and standard error through the caller's streams.
The synchronous form captures output and returns the process exit code separately from transport errors. A non-zero command exit is therefore a command result, not automatically a helper error. Rook storage operations use this distinction to run commands in the Rook toolbox and the storage migrator pod. (See Rook storage operations.)
References: pkg/…/exec.go• L19-103 pkg/…/toolbox.go• L119-149 pkg/…/flexvolume.go• L185-212
Storage state
Storage helpers connect the Kubernetes storage model to the workloads that use it. They first validate a storage class, then collect its persistent volumes, map each volume to its persistent volume claim, and inspect pods to see where each claim is mounted.
The resulting reservation view splits storage into two groups:
- Attached storage is assigned to the node of the first pod found using its claim.
- Detached storage remains unassigned because no current pod mounts its claim.
This view supports migration safety checks for both Rook and OpenEBS. The validators compare source-class reservations with destination capacity. Detached reservations must fit on any possible destination node because their future placement is not known.
References: pkg/…/storage.go• L12-113 pkg/…/rook_disk_space_validator.go• L28-61 pkg/…/openebs_disk_space_validator.go• L23-111
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the ownership labels applied by manifest and job paths aligned with resource discovery and cleanup rules.
- Keep readiness checks consistent with the status fields that callers use as permission to continue.
- Preserve the job label selector contract that maps a created job to its pod and its logs.
- Keep pod volume matching namespace-aware so equal claim names in different namespaces do not share storage state.
- Keep storage reservation units and detached-volume handling aligned with Rook and OpenEBS capacity checks.
- Keep node taint conversion compatible with daemonset and job scheduling across all supported node roles.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A deployment never reaches the requested updated, available, and ready replica count | The dependent operation does not start before its context ends | Wait with a context timeout and check all three replica counts |
| A daemonset has fewer ready pods than the current node count | Node coverage is incomplete and connectivity results can be misleading | Compare ready daemon pods with the node list and fail on timeout |
| A job finishes with a non-zero result | The caller receives an execution failure and can inspect logs and container states | Return job status separately from log collection and clean up the job |
| A job pod cannot be found after the job completes | Output-dependent work cannot parse its result | Require a matching pod before reading logs |
| A persistent volume has no claim reference or its claim is missing | Storage reservation cannot be assigned safely | Fail the reservation calculation instead of guessing ownership |
| A node has no internal IP | Node-to-node checks cannot select a destination | Return an explicit node address error |
Key files
| File | Why to read it |
|---|---|
| pkg/…/apply.go | Shows the shared manifest apply and delete boundary. |
| pkg/…/labels.go | Defines the ownership and version labels used by managed resources. |
| pkg/…/pod.go | Defines pod selection, readiness, and PVC-use checks. |
| pkg/…/node.go | Defines node taint, toleration, and internal address handling. |
| pkg/…/job.go | Shows the job lifecycle, status wait, log collection, and cleanup contract. |
| pkg/…/exec.go | Shows the direct command channel and exit-code behavior. |
| pkg/…/storage.go | Shows how storage classes become per-node and detached reservations. |
| pkg/…/deployment.go | Defines the deployment readiness condition used by migration workflows. |
| pkg/…/daemonset.go | Defines the daemonset rollout condition used by node checks. |
| pkg/…/flexvolume.go | Connects resource apply, deployment readiness, pod selection, and container execution in storage migration. |
| pkg/…/nodes_connectivity.go | Shows how daemonsets and jobs support node connectivity checks. |