-
Notifications
You must be signed in to change notification settings - Fork 22
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
feat: Do not create VM if system or bootstrap disks are marked for deletion #492
base: jira/NCN-101014-refactor-get-image
Are you sure you want to change the base?
feat: Do not create VM if system or bootstrap disks are marked for deletion #492
Conversation
We plan to make decisions based on some of the information.
…only Refactor further; add unit tests with mocks
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## jira/NCN-101014-refactor-get-image #492 +/- ##
======================================================================
- Coverage 34.70% 34.50% -0.21%
======================================================================
Files 18 18
Lines 2239 2252 +13
======================================================================
Hits 777 777
- Misses 1442 1455 +13
Partials 20 20 ☔ View full report in Codecov by Sentry. |
… for deletion Do not export function
84229e6
to
26b934b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Over LGTM, but have couple of questions.
// Returns an error if no image has the UUID, if no image has the name, or more than one image has the name. | ||
func GetImageByNameOrUUID(ctx context.Context, client *prismclientv3.Client, image infrav1.NutanixResourceIdentifier) (*prismclientv3.ImageIntentResponse, error) { | ||
switch { | ||
case image.UUID != nil: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we have full NutanixResourceIdentifier
, why don't we check that Type == NutanixIdentifierUUID
.
Maybe we can even create a func isUuid() bool
and func isName()
bool for NutanixResourceIdentifier
?
foundImageUUID = *imageIntentResponse.Metadata.UUID | ||
} else { // else search by name | ||
return resp, nil | ||
case image.Name != nil: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here
if foundImageUUID == "" { | ||
return "", fmt.Errorf("failed to retrieve image by name or uuid. Verify input parameters") | ||
|
||
switch { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need nested switch here?
return foundImageUUID, nil | ||
} | ||
|
||
func imageMarkedForDeletion(image *prismclientv3.ImageIntentResponse) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we going to use this helper function only in controllers
package?
imageIntentResponse, err := client.V3.GetImage(ctx, *imageUUID) | ||
// GetImageByNameOrUUID returns an image. If no UUID is provided, returns the unique image with the name. | ||
// Returns an error if no image has the UUID, if no image has the name, or more than one image has the name. | ||
func GetImageByNameOrUUID(ctx context.Context, client *prismclientv3.Client, image infrav1.NutanixResourceIdentifier) (*prismclientv3.ImageIntentResponse, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just GetImage
or GetImageByIdentifier
?
What this PR does / why we need it:
Currently, if we create the VM and any of disk images are being deleted, the create task never completes, and end up waiting for task indefinitely. (We stop waiting only when the root reconcile context is cancelled, and I believe controller-runtime cancels that context only when the manager is stopped, i.e., if the process is gracefully terminated).
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 # https://jira.nutanix.com/browse/NCN-101014
How Has This Been Tested?:
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:
Stacked on #489
Please confirm that if this PR changes any image versions, then that's the sole change this PR makes.
Release note: