Skip to content

fix: wait works when no conditions set - #40

Merged
Cali0707 merged 1 commit into
mcpchecker:mainfrom
Cali0707:fix-k8s.wait
Apr 13, 2026
Merged

fix: wait works when no conditions set#40
Cali0707 merged 1 commit into
mcpchecker:mainfrom
Cali0707:fix-k8s.wait

Conversation

@Cali0707

@Cali0707 Cali0707 commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

Resolves #39

Summary by CodeRabbit

  • Bug Fixes
    • The condition field is now optional for the wait operation; resources can be validated by checking existence alone.
    • Improved timeout and error messaging when resources fail to be found or created within the specified timeout period.

Signed-off-by: Calum Murray <cmurray@redhat.com>
@coderabbitai

coderabbitai Bot commented Apr 13, 2026

Copy link
Copy Markdown
📝 Walkthrough

Walkthrough

The PR modifies the kubernetes.wait operation to make the condition field optional. When omitted, the operation now waits for resource existence rather than condition matching, enabling support for Kubernetes resources like Istio Gateway objects that lack status.conditions fields.

Changes

Cohort / File(s) Summary
kubernetes.wait schema and implementation
pkg/extension/operations.go, pkg/extension/wait.go
Removed condition from required schema fields; updated polling logic to check resource existence when condition is empty, and adjusted timeout/success messages accordingly.
Test coverage
pkg/extension/wait_test.go
Updated existing test case and added three new test cases covering: condition-free existence checks (resource found/not found), and condition-based checks on resources lacking status.conditions; added fmt import for error mocking.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Poem

🐰 No more conditions to demand,
Just waiting for resources on demand!
Existence alone now rings the bell,
Istio Gateways work just swell! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: making k8s.wait functional when no conditions are specified, which is the core objective of this PR.
Linked Issues check ✅ Passed The PR successfully addresses all coding requirements from issue #39: allowing waits without conditions, supporting existence-only verification, and maintaining backward compatibility with condition-based checks.
Out of Scope Changes check ✅ Passed All changes directly relate to the PR objective of enabling k8s.wait to work without conditions; schema changes, implementation updates, and test additions all support this core goal.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Cali0707
Cali0707 requested review from matzew and nader-ziada April 13, 2026 13:45

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/extension/wait.go (1)

60-69: ⚠️ Potential issue | 🟠 Major

Don’t mask persistent Get errors as “not found” in existence mode.

In no-condition mode, every Get error is retried and timeout is reported as “not found”. That hides real causes (e.g., auth/API errors) and makes debugging hard. Preserve/report the last Get error (or fail fast for clearly non-retryable errors).

Suggested diff
 	var lastStatus string
+	var lastGetErr error
 	err = wait.PollUntilContextTimeout(ctx, time.Second, timeout, true, func(ctx context.Context) (bool, error) {
 		obj, getErr := e.client.Get(ctx, gvr, ref.name, ref.namespace)
 		if getErr != nil {
+			lastGetErr = getErr
 			return false, nil // Keep polling on transient errors
 		}
@@
 	if err != nil {
 		if condition == "" {
@@
 			return sdk.FailureWithMessage(
-				fmt.Sprintf("Resource %s/%s not found", ref.kind, ref.name),
-				fmt.Errorf("timed out waiting for %s/%s to exist", ref.kind, ref.name),
+				fmt.Sprintf("Resource %s/%s not ready", ref.kind, ref.name),
+				fmt.Errorf("timed out waiting for %s/%s to exist (last get error: %v)", ref.kind, ref.name, lastGetErr),
 			), nil
 		}

Also applies to: 97-105

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/extension/wait.go` around lines 60 - 69, In the existence/no-condition
branch inside the wait.PollUntilContextTimeout loop (where you call e.client.Get
and check if condition == ""), do not always swallow getErr and return
false,nil; instead detect and immediately fail on non-retryable errors (e.g.,
auth/API errors) by returning false,getErr (or use apierrors.IsNotFound to treat
NotFound as retryable), and for retryable errors keep track of the last getErr
and propagate it after the poll times out so callers see the real failure; apply
the same change pattern to the similar logic around lines 97-105 so persistent
Get errors are preserved/reported rather than masked as “not found.”
🧹 Nitpick comments (2)
pkg/extension/wait_test.go (1)

173-181: Consider asserting response messages for new branches.

The new behavior has distinct success/failure messages for existence vs condition waits; asserting them would harden the contract and catch regressions beyond the boolean outcome.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/extension/wait_test.go` around lines 173 - 181, The test currently only
checks result.Success for handleWait; add assertions on the response message to
cover new branches (existence vs condition waits). In the
pkg/extension/wait_test.go test cases where you call
ext.handleWait(context.Background(), req) (using sdk.OperationRequest and
checking result.Success), also assert result.Message (or result.ErrorMessage if
applicable) matches the expected string for each case (e.g., "resource exists"
vs "condition met" or the appropriate failure text) so both positive and
negative branches are validated.
pkg/extension/operations.go (1)

43-47: Clarify wait operation docs for existence-only mode.

Line 73 now allows condition to be omitted, but Line 43 and Line 46 still describe condition-only waiting. Please update those descriptions so callers know omission means existence wait.

Suggested doc-only diff
- sdk.WithDescription("Wait for a condition on a Kubernetes resource"),
+ sdk.WithDescription("Wait for a condition on a Kubernetes resource, or for resource existence if condition is omitted"),
...
- Description: "Resource reference with condition to wait for",
+ Description: "Resource reference to wait on (condition optional; existence check when omitted)",

Also applies to: 73-73

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@pkg/extension/operations.go` around lines 43 - 47, Update the operation
descriptions to document that omitting the "condition" field switches the wait
to existence-only behavior: modify the text passed to sdk.WithDescription(...)
and the jsonschema.Schema Description for WithParams so they state that callers
can omit "condition" to wait only for resource existence (rather than waiting
for a specific condition), and ensure the "condition" property description in
the Properties map (the jsonschema.Schema entry for "condition") is updated
similarly to reflect optional existence-only behavior; reference
sdk.WithDescription, sdk.WithParams, jsonschema.Schema and the "condition"
property to locate and update the strings.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@pkg/extension/wait.go`:
- Around line 60-69: In the existence/no-condition branch inside the
wait.PollUntilContextTimeout loop (where you call e.client.Get and check if
condition == ""), do not always swallow getErr and return false,nil; instead
detect and immediately fail on non-retryable errors (e.g., auth/API errors) by
returning false,getErr (or use apierrors.IsNotFound to treat NotFound as
retryable), and for retryable errors keep track of the last getErr and propagate
it after the poll times out so callers see the real failure; apply the same
change pattern to the similar logic around lines 97-105 so persistent Get errors
are preserved/reported rather than masked as “not found.”

---

Nitpick comments:
In `@pkg/extension/operations.go`:
- Around line 43-47: Update the operation descriptions to document that omitting
the "condition" field switches the wait to existence-only behavior: modify the
text passed to sdk.WithDescription(...) and the jsonschema.Schema Description
for WithParams so they state that callers can omit "condition" to wait only for
resource existence (rather than waiting for a specific condition), and ensure
the "condition" property description in the Properties map (the
jsonschema.Schema entry for "condition") is updated similarly to reflect
optional existence-only behavior; reference sdk.WithDescription, sdk.WithParams,
jsonschema.Schema and the "condition" property to locate and update the strings.

In `@pkg/extension/wait_test.go`:
- Around line 173-181: The test currently only checks result.Success for
handleWait; add assertions on the response message to cover new branches
(existence vs condition waits). In the pkg/extension/wait_test.go test cases
where you call ext.handleWait(context.Background(), req) (using
sdk.OperationRequest and checking result.Success), also assert result.Message
(or result.ErrorMessage if applicable) matches the expected string for each case
(e.g., "resource exists" vs "condition met" or the appropriate failure text) so
both positive and negative branches are validated.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 277271e1-ab40-4aa2-ad82-3fc7dfa2266c

📥 Commits

Reviewing files that changed from the base of the PR and between 2a70cd2 and 899e388.

📒 Files selected for processing (3)
  • pkg/extension/operations.go
  • pkg/extension/wait.go
  • pkg/extension/wait_test.go

@nader-ziada nader-ziada left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM

@Cali0707
Cali0707 merged commit c851dc0 into mcpchecker:main Apr 13, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problems in k8s.wait for istio objects

2 participants