Skip to content

chore(role_assignment): make roleassignment reconcile async#1873

Merged
k8s-ci-robot merged 1 commit into
kubernetes-sigs:mainfrom
sonasingh46:async_roleassignment
Mar 28, 2022
Merged

chore(role_assignment): make roleassignment reconcile async#1873
k8s-ci-robot merged 1 commit into
kubernetes-sigs:mainfrom
sonasingh46:async_roleassignment

Conversation

@sonasingh46
Copy link
Copy Markdown
Contributor

@sonasingh46 sonasingh46 commented Nov 17, 2021

Signed-off-by: Ashutosh Kumar sonasingh46@gmail.com

What type of PR is this?

What this PR does / why we need it:
Implementation of async service for role assignment.

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 #1718

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:

Make roleassignment reconcile async

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 17, 2021
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Hi @sonasingh46. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

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.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 17, 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. labels Nov 17, 2021
@mboersma
Copy link
Copy Markdown
Contributor

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 17, 2021
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Nov 22, 2021
Comment thread azure/scope/machine.go Outdated
Comment thread azure/services/roleassignments/roleassignments.go
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 8, 2021
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jan 12, 2022
@sonasingh46 sonasingh46 force-pushed the async_roleassignment branch 2 times, most recently from 5b5d1d9 to 3073807 Compare January 19, 2022 16:37
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jan 19, 2022
actual := NewService(mps, resourceskus.NewStaticCache(nil, ""))
g.Expect(actual).ToNot(BeNil())
}
// ToDo: Fix this test case
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.

@CecileRobertMichon @shysank -- Any suggestions on fixing this test case. This test case requires to import scope package and hence causes import loop.

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.

looking, I don't think we should be creating real scopes to test NewService(). NewService takes a ScaleSetScope, which we have a mock for, so we should be able to do:

mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
 scopeMock := NewMockScaleSetScope(mockCtrl)
actual := NewService(scopeMock, resourceskus.NewStaticCache(nil, ""))
g.Expect(actual).ToNot(BeNil())

If that doesn't work, that test isn't testing much since the NewService func just sets the parameters into a struct and returns it, so worst case we can get rid of the test altogether.

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.

I tried something like below:

scopeMock := mock_scalesets.NewMockScaleSetScope(mockCtrl)
	rec:=scopeMock.EXPECT()
	rec.SubscriptionID().Return("123")
	rec.BaseURI().Return("/dummy")
	rec.Authorizer().Return(scopeMock)
	actual := NewService(scopeMock, resourceskus.NewStaticCache(nil, ""))
	g.Expect(actual).ToNot(BeNil())

I added those mock Returns as they were expected but at the end I got error something like this:

wrong type of argument 0 to Return for *mock_scalesets.MockScaleSetScope.Authorizer: *mock_scalesets.MockScaleSetScope is not assignable to autorest.Authorizer [/Users/kuashutosh/go/src/sigs.k8s.io/cluster-api-provider-azure/azure/services/scalesets/scalesets_test.go:66]

@Jont828
Copy link
Copy Markdown
Contributor

Jont828 commented Jan 24, 2022

Hey @sonasingh46, how's it going with the role assignments PR? I worked on a lot of the async refactor PRs with @CecileRobertMichon, and I'd be happy to answer any questions or to do a code review.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 26, 2022
if len(s.Scope.RoleAssignmentSpecs(to.StringPtr(""))) < 1 {
log.V(2).Info("no role assignment spec to reconcile")
return 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 is a redundant call to role assignments spec that I had to make so that when we fetch principalID -- nil point exception does not occur.

When there is not role assignment spec, while fetching the vm details, some of fields are nil and looks more simpler to return early in case there is no role assignment spec.

So this first call passes an empty principal ID and validates if role assignment spec is present and then below finds the principal ID and calls this spec function once again to finally get the correct role assignment specs.
cc @CecileRobertMichon @Jont828

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.

I'd suggest adding another method to scope that just returns true/false if the machine/machinepool has system assigned identity for better readability.

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.

I'd suggest adding another method to scope that just returns true/false if the machine/machinepool has system assigned identity for better readability.

+1

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.

Done

@sonasingh46 sonasingh46 force-pushed the async_roleassignment branch 2 times, most recently from 1ad6487 to b9fcc7f Compare March 24, 2022 12:17
@sonasingh46
Copy link
Copy Markdown
Contributor Author

/test pull-cluster-api-provider-azure-e2e

@sonasingh46
Copy link
Copy Markdown
Contributor Author

/test pull-cluster-api-provider-azure-e2e-windows-dockershim

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

@sonasingh46: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

  • /test pull-cluster-api-provider-azure-build
  • /test pull-cluster-api-provider-azure-e2e
  • /test pull-cluster-api-provider-azure-test
  • /test pull-cluster-api-provider-azure-verify

The following commands are available to trigger optional jobs:

  • /test pull-cluster-api-provider-azure-apidiff
  • /test pull-cluster-api-provider-azure-apiversion-upgrade
  • /test pull-cluster-api-provider-azure-capi-e2e
  • /test pull-cluster-api-provider-azure-ci-entrypoint
  • /test pull-cluster-api-provider-azure-conformance
  • /test pull-cluster-api-provider-azure-conformance-with-ci-artifacts
  • /test pull-cluster-api-provider-azure-coverage
  • /test pull-cluster-api-provider-azure-e2e-exp
  • /test pull-cluster-api-provider-azure-e2e-optional
  • /test pull-cluster-api-provider-azure-e2e-workload-upgrade
  • /test pull-cluster-api-provider-azure-upstream-windows-dockershim
  • /test pull-cluster-api-provider-azure-windows-containerd-upstream-with-ci-artifacts
  • /test pull-cluster-api-provider-azure-windows-containerd-upstream-with-ci-artifacts-serial-slow

Use /test all to run the following jobs that were automatically triggered:

  • pull-cluster-api-provider-azure-apidiff
  • pull-cluster-api-provider-azure-build
  • pull-cluster-api-provider-azure-ci-entrypoint
  • pull-cluster-api-provider-azure-coverage
  • pull-cluster-api-provider-azure-e2e
  • pull-cluster-api-provider-azure-test
  • pull-cluster-api-provider-azure-verify
Details

In response to this:

/test pull-cluster-api-provider-azure-e2e-windows-dockershim

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.

Comment thread azure/services/roleassignments/spec.go
Copy link
Copy Markdown
Contributor

@CecileRobertMichon CecileRobertMichon left a comment

Choose a reason for hiding this comment

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

/lgtm
/assign @shysank

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

@sonasingh46 can you please squash?

@shysank
Copy link
Copy Markdown
Contributor

shysank commented Mar 25, 2022

@sonasingh46 were you able to find the cause of failure for the vmss e2e test?

@shysank
Copy link
Copy Markdown
Contributor

shysank commented Mar 25, 2022

/retest

@sonasingh46 sonasingh46 force-pushed the async_roleassignment branch from b9fcc7f to 71ac260 Compare March 27, 2022 11:43
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 27, 2022
@sonasingh46
Copy link
Copy Markdown
Contributor Author

@shysank -- Not sure why it failed but when I rebased and pushed again the test passed.

Signed-off-by: Ashutosh Kumar <sonasingh46@gmail.com>
@sonasingh46 sonasingh46 force-pushed the async_roleassignment branch from 71ac260 to 0b74770 Compare March 27, 2022 13:18
@sonasingh46
Copy link
Copy Markdown
Contributor Author

/retest

1 similar comment
@CecileRobertMichon
Copy link
Copy Markdown
Contributor

/retest

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

k8s-ci-robot commented Mar 28, 2022

@sonasingh46: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-cluster-api-provider-azure-e2e-windows-dockershim c488770 link true /test pull-cluster-api-provider-azure-e2e-windows-dockershim
pull-cluster-api-provider-azure-apidiff 0b74770 link false /test pull-cluster-api-provider-azure-apidiff

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Details

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. I understand the commands that are listed here.

@shysank
Copy link
Copy Markdown
Contributor

shysank commented Mar 28, 2022

/lgtm
/approve

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

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: shysank

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 Mar 28, 2022
@k8s-ci-robot k8s-ci-robot merged commit 9075098 into kubernetes-sigs:main Mar 28, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.3 milestone Mar 28, 2022
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/cluster-lifecycle Categorizes an issue or PR as relevant to SIG Cluster Lifecycle. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

async roleassignments

6 participants