Skip to content
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

fix: improve error handling for Prism Client #354

Merged

Conversation

faiq
Copy link
Contributor

@faiq faiq commented Jan 3, 2024

What this PR does / why we need it:
This adds some logic to properly format the prismCentral address string if a user provides an address with a scheme or port already included. It also adds error wrapping to clearly note where any issues might be coming from.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes errors from bad user input

previously if a user provided an address such as `https://prismcentral.com" this would cause a failure like this

2023-12-19T22:26:53Z    ERROR   Reconciler error        {"controller": "nutanixmachine", "controllerGroup": "infrastructure.cluster.x-k8s.io", "controllerKind": "NutanixMachine", "NutanixMachine": {"name":"faiq-test-mt-0-brp7d","namespace":"default"}, "namespace": "default", "name": "faiq-test-mt-0-brp7d", "reconcileID": "24ede42f-0ba6-41cd-a0b0-51c37c6f95d0", "error": "client auth error: Get \"https:///api/nutanix/v3/users/me\": http: no Host in request URL"}

this code now strips out the scheme and port number from the address if it is provided.

How Has This Been Tested?:
I deployed this to a local kind cluster. Previously I was seeing errors such as

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration and test output

Special notes for your reviewer:

Please confirm that if this PR changes any image versions, then that's the sole change this PR makes.

Release note:


Copy link

codecov bot commented Jan 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (085c903) 13.62% compared to head (40872bd) 13.62%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #354   +/-   ##
=======================================
  Coverage   13.62%   13.62%           
=======================================
  Files           4        4           
  Lines        1013     1013           
=======================================
  Hits          138      138           
  Misses        875      875           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@faiq faiq changed the title Faiq/client error handling fix: improve address parsing and handling for Prism Client Jan 4, 2024
Copy link
Contributor

@adiantum adiantum left a comment

Choose a reason for hiding this comment

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

Let's improve var naming little bit.

pkg/client/client.go Outdated Show resolved Hide resolved
pkg/client/client.go Outdated Show resolved Hide resolved
@thunderboltsid
Copy link
Contributor

/ok-to-test

@thunderboltsid
Copy link
Contributor

@faiq can you also rebase this against the latest changes in main.

@faiq faiq force-pushed the faiq/client-error-handling branch from ff401c1 to cf34f59 Compare January 4, 2024 22:24
@tuxtof
Copy link
Contributor

tuxtof commented Jan 5, 2024

/retest

1 similar comment
@thunderboltsid
Copy link
Contributor

/retest

pkg/client/client.go Outdated Show resolved Hide resolved
@faiq faiq changed the title fix: improve address parsing and handling for Prism Client fix: improve error handling for Prism Client Jan 8, 2024
pkg/client/client.go Outdated Show resolved Hide resolved
@faiq faiq force-pushed the faiq/client-error-handling branch from cf8bea5 to 40872bd Compare January 8, 2024 16:43
@thunderboltsid
Copy link
Contributor

/lgtm
/approve

@nutanix-cn-prow-bot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: faiq, thunderboltsid

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@thunderboltsid
Copy link
Contributor

/retest

Copy link
Contributor

@tuxtof tuxtof left a comment

Choose a reason for hiding this comment

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

LGTM

@thunderboltsid thunderboltsid merged commit 1f8716d into nutanix-cloud-native:main Jan 9, 2024
8 of 10 checks passed
thunderboltsid pushed a commit that referenced this pull request Apr 24, 2024
* fix: use wrapper errors to clearly denote issues in client building

* fix: adds a function to properly sanitize the address

* fix: adds tests for ip address case given

* fix: uses a defined type for port error

* fix: clean up variable naming

* fix: remove validation here to be moved into prism-client
thunderboltsid pushed a commit that referenced this pull request Apr 29, 2024
* fix: use wrapper errors to clearly denote issues in client building

* fix: adds a function to properly sanitize the address

* fix: adds tests for ip address case given

* fix: uses a defined type for port error

* fix: clean up variable naming

* fix: remove validation here to be moved into prism-client
thunderboltsid pushed a commit that referenced this pull request May 2, 2024
* fix: use wrapper errors to clearly denote issues in client building

* fix: adds a function to properly sanitize the address

* fix: adds tests for ip address case given

* fix: uses a defined type for port error

* fix: clean up variable naming

* fix: remove validation here to be moved into prism-client
thunderboltsid added a commit that referenced this pull request May 2, 2024
* fix: improve error handling for Prism Client (#354)

* fix: use wrapper errors to clearly denote issues in client building

* fix: adds a function to properly sanitize the address

* fix: adds tests for ip address case given

* fix: uses a defined type for port error

* fix: clean up variable naming

* fix: remove validation here to be moved into prism-client

* refactor: task status file (#355)

* test: add unit tests for pkg/client/state

* refactor: use wait.Poll function waiting for task state

* refactor: use consistent task status names

* fixup! test: add unit tests for pkg/client/state

* fix: revert to previous behaviod polling forever

The ctx passed into WaitForTaskToSucceed is only used to cancel HTTP reqests and not to cancel the wait.

* chore: add license headers

* fix: better function name

* refactor: client.go file helper methods (#360)

* refactor: client.go file helper methods

Refactored the existing methods and functions to be unit testable.
Also made some methods that do not use the struct as generic functions.
The changes were primarily an effort to add unit test coverage.

* refactor: more testable read file function

* test: new nutanixcluster types unit tests

* test: additional test cases for errors

* fixup! refactor: client.go file helper methods

* fixup! refactor: client.go file helper methods

* fixup! refactor: more testable read file function

* fixup! refactor: client.go file helper methods

* Switch Nutanix Client to using Session Auth (#398)

This will ensure we make fewer basic auth requests to Prism Central
IAM Services.

---------

Co-authored-by: Faiq <faiq.raza@nutanix.com>
Co-authored-by: Dimitri Koshkin <dimitri.koshkin@nutanix.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants