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

refactor: task status file #355

Merged

Conversation

dkoshkin
Copy link
Contributor

@dkoshkin dkoshkin commented Jan 5, 2024

What this PR does / why we need it:
This started as an effort to start increasing the code coverage, but noticed that there was some code we can remove and instead rely on the apimachine wait helper functions.

  1. Added unit tests to cover existing functions
  2. Removed the custom wait code (notice how only the error message with the timeout changed, all other tests cases stayed the same, all tests stayed the same after the refactor)
  3. While working on the PR I kept getting mixed up on "state" vs "status" as they were being used interchangeably. I made it all consistent with "status" as that is what the API returns.

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 #

How Has This Been Tested?:

New unit tests

Special notes for your reviewer:
I broke up the PR into logical commits and would recommend reviewing it that way too.

I initially started by trying to mock the client but the is a bug that prevented me from doing that nutanix-cloud-native/prism-go-client#150. I went with the http route based on the client's own test files https://github.com/nutanix-cloud-native/prism-go-client/blob/main/v3/v3_service_test.go, but can refactor back to using mocks if we find that to be easier to maintain, if/when the bug PR is merged and released.

Release note:


@dkoshkin dkoshkin force-pushed the rafactor-task-status branch from 771cd7c to 9c533b8 Compare January 5, 2024 03:11
Copy link

codecov bot commented Jan 5, 2024

Codecov Report

Attention: 3 lines in your changes are missing coverage. Please review.

Comparison is base (629d802) 11.28% compared to head (946d1c2) 12.53%.

Files Patch % Lines
controllers/helpers.go 0.00% 1 Missing ⚠️
controllers/nutanixmachine_controller.go 0.00% 1 Missing ⚠️
test/helpers/prism-go-client/v3/client.go 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #355      +/-   ##
==========================================
+ Coverage   11.28%   12.53%   +1.24%     
==========================================
  Files          19       20       +1     
  Lines        2021     2003      -18     
==========================================
+ Hits          228      251      +23     
+ Misses       1793     1752      -41     

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

@dkoshkin dkoshkin force-pushed the rafactor-task-status branch from 9c533b8 to 986b2ab Compare January 5, 2024 03:50
@thunderboltsid
Copy link
Contributor

/retest

@dkoshkin dkoshkin force-pushed the rafactor-task-status branch from 986b2ab to 004c55a Compare January 5, 2024 16:43
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.

Typo in PR name: "refacotr: ..."

pkg/client/status.go Show resolved Hide resolved
test/helpers/prism-go-client/v3/client.go Outdated Show resolved Hide resolved
@dkoshkin dkoshkin changed the title refacotr: task status file refacotor: task status file Jan 5, 2024
@thunderboltsid
Copy link
Contributor

/retest

@thunderboltsid thunderboltsid changed the title refacotor: task status file refactor: task status file Jan 5, 2024
@thunderboltsid
Copy link
Contributor

/ok-to-test

@thunderboltsid
Copy link
Contributor

/lgtm

@dkoshkin dkoshkin force-pushed the rafactor-task-status branch from 18525a6 to ba9b19d Compare January 9, 2024 18:10
@dkoshkin dkoshkin force-pushed the rafactor-task-status branch from ba9b19d to 946d1c2 Compare January 10, 2024 20:45
@thunderboltsid
Copy link
Contributor

/approve

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.

/lgtm
/approve
/meow

@nutanix-cn-prow-bot
Copy link

@adiantum: cat image

In response to this:

/lgtm
/approve
/meow

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@nutanix-cn-prow-bot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: adiantum, dkoshkin, 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:
  • OWNERS [adiantum,thunderboltsid]

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

@thunderboltsid thunderboltsid merged commit 5fd7ada into nutanix-cloud-native:main Jan 11, 2024
5 of 7 checks passed
thunderboltsid pushed a commit that referenced this pull request Apr 24, 2024
* 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
thunderboltsid pushed a commit that referenced this pull request Apr 29, 2024
* 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
thunderboltsid pushed a commit that referenced this pull request May 2, 2024
* 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
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.

4 participants