Skip to content

Check future regardless of error in async helpers and return VM result for existing VM#1837

Merged
k8s-ci-robot merged 2 commits into
kubernetes-sigs:mainfrom
CecileRobertMichon:vm-fixes
Nov 10, 2021
Merged

Check future regardless of error in async helpers and return VM result for existing VM#1837
k8s-ci-robot merged 2 commits into
kubernetes-sigs:mainfrom
CecileRobertMichon:vm-fixes

Conversation

@CecileRobertMichon
Copy link
Copy Markdown
Contributor

What type of PR is this?

What this PR does / why we need it: Small followups on #1697 and comments in #1684

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 #

Special notes for your reviewer:

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

TODOs:

  • squashed commits
  • includes documentation
  • adds unit tests

Release note:

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Nov 5, 2021
@k8s-ci-robot k8s-ci-robot added area/provider/azure Issues or PRs related to azure provider sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Nov 5, 2021
}
scope.SetLongRunningOperationState(future)
return nil, azure.WithTransientError(azure.NewOperationNotDoneError(future), retryAfter(sdkFuture))
if sdkFuture != nil {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@karuppiah7890 please take a look. I believe this addresses your comment in #1684 (comment). I think it makes sense to not require an error (that way this will work whether an error is returned or not). However, I still think we shouldn't silence the error returned by WaitForCompletionRef in the clients since eventually it might return a different error besides context deadline exceeded.

if !ok {
if params == nil {
// nothing to do here.
return existingVM, nil, nil
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

this addresses #1697 (comment)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we move this to line 86 and invoke spec.Parameters() can be only for new vms? wdyt?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

in this specific VM service we technically could because we never want to update existing VMs but this pattern works best for all services in general: we pass in the existing resource to spec.Parameters(existing) and that function determines if the resource needs to be created or updated based on the existing resource. For example, for NSGs we update the group the security rules are missing. IMO it's best to use the same pattern throughout all services so it's easier to refactor them later to have even more code in common.

@CecileRobertMichon
Copy link
Copy Markdown
Contributor Author

/hold

need to investigate why e2e tests are failing

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 5, 2021
@CecileRobertMichon
Copy link
Copy Markdown
Contributor Author

/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 8, 2021
@CecileRobertMichon
Copy link
Copy Markdown
Contributor Author

/retest

@CecileRobertMichon
Copy link
Copy Markdown
Contributor Author

/assign @shysank @Jont828 @karuppiah7890

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

@CecileRobertMichon: GitHub didn't allow me to assign the following users: Jont828, karuppiah7890.

Note that only kubernetes-sigs members, repo collaborators and people who have commented on this issue/PR can be assigned. Additionally, issues/PRs can only have 10 assignees at the same time.
For more information please see the contributor guide

Details

In response to this:

/assign @shysank @Jont828 @karuppiah7890

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.

var existingVM interface{}

if existing, err := ac.Get(ctx, spec.ResourceGroupName(), spec.ResourceName()); err != nil && !azure.ResourceNotFound(err) {
return nil, nil, errors.Wrapf(err, "failed to get virtual machine %s in %s", spec.ResourceName(), spec.ResourceGroupName())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

shouldn't we handle errors that are not ResourceNotFound?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

if it's a ResourceNotFound error, that means the VM doesn't exist, so we don't set existingVM. It's not an error we want to return, it's an expected error whenever we create the resource for the first time.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

oh yeah, this used to be in a different form in virtualmachines.go. Perhaps I should be more in sync with the new code, but alas the code itself is not in sync anymore.

if !ok {
if params == nil {
// nothing to do here.
return existingVM, nil, nil
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can we move this to line 86 and invoke spec.Parameters() can be only for new vms? wdyt?

@shysank
Copy link
Copy Markdown
Contributor

shysank commented Nov 10, 2021

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Nov 10, 2021
Copy link
Copy Markdown
Contributor

@devigned devigned 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

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: devigned

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

The pull request process is described here

Details 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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Nov 10, 2021
@k8s-ci-robot k8s-ci-robot merged commit 2d4c465 into kubernetes-sigs:main Nov 10, 2021
@k8s-ci-robot k8s-ci-robot added this to the v1.1 milestone Nov 10, 2021
@CecileRobertMichon CecileRobertMichon deleted the vm-fixes branch February 17, 2023 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/provider/azure Issues or PRs related to azure provider cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants