Skip to content

refactor(wait): avoid shelling out to kubectl during wait#4567

Merged
AustinAbro321 merged 99 commits intomainfrom
avoid-kubectl-wait-shell-out
Feb 17, 2026
Merged

refactor(wait): avoid shelling out to kubectl during wait#4567
AustinAbro321 merged 99 commits intomainfrom
avoid-kubectl-wait-shell-out

Conversation

@AustinAbro321
Copy link
Copy Markdown
Member

@AustinAbro321 AustinAbro321 commented Jan 29, 2026

Description

This entirely eliminates any shelling out in the wait command. Instead, we first get the kind directly from Kubernetes to replace the kubectl get calls, then call the equivalent of kubectl wait directly through the kube go dependency.

Went for parity with the current behavior of zarf tools wait-for which includes waiting for a cluster to be up, even if it currently doesn't exist. This may be behavior we want to re-evaluate when we introduce zarf tools wait-for resource #4550

This does change the logging strategy, previously wait would log each second it waits like so

zarf tools wait-for -n kube-system pods metrics-server-5985cbc9d7-92mwh1
2026-02-11 13:17:07 INF using config file location=/home/austin/code/zarf/zarf-config.toml
2026-02-11 13:17:07 INF waiting for pods/metrics-server-5985cbc9d7-92mwh1 in namespace kube-system to exist.
2026-02-11 13:17:08 INF resource error error=exit status 1
2026-02-11 13:17:09 INF resource error error=exit status 1

Now the message will not continuously update, and instead look like, unless the -l debug flag is used. This is more consistent with the logging strategy used elsewhere in Zarf

build/zarf tools wait-for -n kube-system pods metrics-server-5985cbc9d7-92mwh1 ready 
2026-02-11 13:19:34 INF using config file location=/home/austin/code/zarf/zarf-config.toml
2026-02-11 13:19:34 INF waiting for resource kind=pods identifier=metrics-server-5985cbc9d7-92mwh1 condition=condition=ready namespace=kube-system

Checklist before merging

Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented Jan 29, 2026

Codecov Report

❌ Patch coverage is 1.14943% with 172 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/pkg/wait/wait.go 1.14% 172 Missing ⚠️
Files with missing lines Coverage Δ
src/pkg/wait/wait.go 16.28% <1.14%> (-9.42%) ⬇️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
AustinAbro321 and others added 12 commits February 5, 2026 10:19
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Copy link
Copy Markdown
Member

@brandtkeller brandtkeller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few areas of interest but overall a serious improvement.

Comment thread src/pkg/wait/wait.go Outdated
Comment thread src/pkg/wait/wait.go Outdated
Comment thread src/pkg/wait/wait.go Outdated
Comment thread src/pkg/wait/wait.go
Comment thread src/pkg/wait/wait.go Outdated
waitInterval := time.Second
l.Info("waiting for any resource of kind to exist", "kind", resource.Resource, "namespace", namespace)

resourceClient := dynamicClient.Resource(resource).Namespace(namespace)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to test this - I am not sure this can delineate between cluster-scoped resources and a lack of a namespace for a namespaced resource.

if someone forgets to add a -n to a namespaced resource I believe this will unintuitively return on the existence of that resource in the cluster.

I think we could check for resource being cluster scoped and then otherwise get the default from the kube context?

Copy link
Copy Markdown
Member Author

@AustinAbro321 AustinAbro321 Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really subtle and nice catch. Yeah release zarf tools wait-for pod will only pass if there is a pod in the default namespace, whereas this branchs zarf tools wait-for pod will pass if a pod is in the cluster. Will add a test and change the behavior

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in logic to get the users default namespace. An added bonus here is that even when a user doesn't give a namespace, their default will show up in the log

@github-project-automation github-project-automation Bot moved this to In progress in Zarf Feb 12, 2026
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
})

t.Run("wait for non-existent resource times out", func(t *testing.T) {
t.Parallel()
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decided to make these run in parallel, this brings the entire test to 6 seconds from 26. I think I'm fine with the risks here, essentially you would need to make sure another test isn't creating a resource with the same name. Definitely open to objections though

Signed-off-by: Austin Abro <austinabro321@gmail.com>
Signed-off-by: Austin Abro <austinabro321@gmail.com>
Copy link
Copy Markdown
Member

@brandtkeller brandtkeller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thoughtfully executed - lgtm

@AustinAbro321 AustinAbro321 added this pull request to the merge queue Feb 17, 2026
Merged via the queue into main with commit 3660ece Feb 17, 2026
31 checks passed
@AustinAbro321 AustinAbro321 deleted the avoid-kubectl-wait-shell-out branch February 17, 2026 13:45
@github-project-automation github-project-automation Bot moved this from In progress to Done in Zarf Feb 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants