Skip to content

feat: Support context for all Nutanix client calls #1234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 25, 2025

Conversation

dlipovetsky
Copy link
Contributor

@dlipovetsky dlipovetsky commented Jul 23, 2025

What problem does this PR solve?:
This allows us to handle context cancellation when using the Nutanix v4 go client, which itself does not support context. That, together with #1235, allows us to return check results before the API server webhook timeout. This means the client sees results, instead of an uninformative (and misleading) "failed to call webhook" error.

Before

Notice that no results are returned.

│ kubectl apply --dry-run=server -f invalid-bad-prismcentral-url.yaml -v=4
I0723 12:12:17.523594 2625398 envvar.go:172] "Feature gate default state" feature="ClientsPreferCBOR" enabled=false
I0723 12:12:17.523624 2625398 envvar.go:172] "Feature gate default state" feature="InformerResourceVersion" enabled=false
I0723 12:12:17.523627 2625398 envvar.go:172] "Feature gate default state" feature="InOrderInformers" enabled=true
I0723 12:12:17.523630 2625398 envvar.go:172] "Feature gate default state" feature="WatchListClient" enabled=false
I0723 12:12:17.523633 2625398 envvar.go:172] "Feature gate default state" feature="ClientsAllowCBOR" enabled=false
I0723 12:12:27.582271 2625398 helpers.go:246] server response object: %s[{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {},
  "status": "Failure",
  "message": "error when creating \"invalid-bad-prismcentral-url.yaml\": Internal error occurred: failed calling webhook \"preflight.cluster.caren.nutanix.com\": failed to call webhook: Post \"https://cluster-api-runtime-extensions-nutanix-admission.default.svc:443/preflight-v1beta1-cluster?timeout=10s\": context deadline exceeded",
  "reason": "InternalError",
  "details": {
    "causes": [
      {
        "message": "failed calling webhook \"preflight.cluster.caren.nutanix.com\": failed to call webhook: Post \"https://cluster-api-runtime-extensions-nutanix-admission.default.svc:443/preflight-v1beta1-cluster?timeout=10s\": context deadline exceeded"
      }
    ]
  },
  "code": 500
}]
Error from server (InternalError): error when creating "invalid-bad-prismcentral-url.yaml": Internal error occurred: failed calling webhook "preflight.cluster.caren.nutanix.com": failed to call webhook: Post "https://cluster-api-runtime-extensions-nutanix-admission.default.svc:443/preflight-v1beta1-cluster?timeout=10s": context deadline exceeded

After

Notice that the results are returned.

│ kubectl apply --dry-run=server -f invalid-bad-prismcentral-url.yaml -v=4
I0723 12:06:59.458667 2603987 envvar.go:172] "Feature gate default state" feature="ClientsAllowCBOR" enabled=false
I0723 12:06:59.458703 2603987 envvar.go:172] "Feature gate default state" feature="ClientsPreferCBOR" enabled=false
I0723 12:06:59.458706 2603987 envvar.go:172] "Feature gate default state" feature="InformerResourceVersion" enabled=false
I0723 12:06:59.458709 2603987 envvar.go:172] "Feature gate default state" feature="InOrderInformers" enabled=true
I0723 12:06:59.458711 2603987 envvar.go:172] "Feature gate default state" feature="WatchListClient" enabled=false
I0723 12:07:07.583019 2603987 helpers.go:246] server response object: %s[{
  "kind": "Status",
  "apiVersion": "v1",
  "metadata": {},
  "status": "Failure",
  "message": "error when creating \"invalid-bad-prismcentral-url.yaml\": admission webhook \"preflight.cluster.caren.nutanix.com\" denied the request: preflight checks failed due to an internal error",
  "reason": "InternalError",
  "details": {
    "causes": [
      {
        "reason": "NutanixCredentials",
        "message": "Failed to validate credentials: Get \"https://example.com:9441/api/nutanix/v3/users/me\": context deadline exceeded. This is usually a temporary error. Please retry.",
        "field": "$.spec.topology.variables[?@.name==\"clusterConfig\"].value.nutanix.prismCentralEndpoint"
      }
    ]
  },
  "code": 500
}]
Error from server (InternalError): error when creating "invalid-bad-prismcentral-url.yaml": admission webhook "preflight.cluster.caren.nutanix.com" denied the request: preflight checks failed due to an internal error

Which issue(s) this PR fixes:
Fixes #

How Has This Been Tested?:

Special notes for your reviewer:

@dlipovetsky dlipovetsky force-pushed the dlipovetsky/preflight-nutanix-support-context branch from 8d1f64f to 75a69d6 Compare July 23, 2025 21:28
@github-actions github-actions bot added feature and removed feature labels Jul 23, 2025
@dlipovetsky dlipovetsky marked this pull request as ready for review July 24, 2025 17:38
Simplify by using buffered channel, and result type
dlipovetsky added a commit that referenced this pull request Jul 24, 2025
…#1235)

**What problem does this PR solve?**:
Assuming that preflight checks return within 2 seconds of context
cancellation, the preflight checks webhook will return before the API
server webhook timeout.

Some preflight checks already meet this criteria. I'm updating others to
meet it in
#1234
 
**Which issue(s) this PR fixes**:
Fixes #

**How Has This Been Tested?**:
<!--
Please describe the tests that you ran to verify your changes.
Provide output from the tests and any manual steps needed to replicate
the tests.
-->

**Special notes for your reviewer**:
<!--
Use this to provide any additional information to the reviewers.
This may include:
- Best way to review the PR.
- Where the author wants the most review attention on.
- etc.
-->
@dlipovetsky dlipovetsky requested a review from dkoshkin July 24, 2025 21:37
Copy link
Contributor

@dkoshkin dkoshkin left a comment

Choose a reason for hiding this comment

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

Nice solution!

Copy link
Contributor

@thunderboltsid thunderboltsid left a comment

Choose a reason for hiding this comment

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

lgtm

@dlipovetsky dlipovetsky merged commit ada4eac into main Jul 25, 2025
22 checks passed
@dlipovetsky dlipovetsky deleted the dlipovetsky/preflight-nutanix-support-context branch July 25, 2025 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants