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

feat: automatic approval with capacity management #288

Merged

Conversation

MatousJobanek
Copy link
Contributor

@MatousJobanek MatousJobanek commented Sep 22, 2020

Introduces automatic approval connected to capacity management.
The logic checks if the user can be approved and provisioned to any member cluster. It the user can be approved then it picks a suitable member cluster the user will be provisioned to.
If the user is approved manually then if the target cluster is not already specified for UserSignup then it just gets a member cluster with enough capacity.
If the user is not approved manually, then it loads HostOperatorConfig to check if automatic approval is enabled or not. If it is then it checks capacity thresholds and the actual use to check if there is any suitable member cluster available.
If there is no suitable member cluster (but the user can be approved), then it returns an error and waits for the next reconcile.

Builds on top of #290 so the only commit to be reviewed is: 47aee03

TODO:

  • e2e tests

Postponed for separated PR:
when automatic approval is enabled then it should approve and provision the oldest unapproved UserSignup.

Copy link
Contributor

@alexeykazakov alexeykazakov left a comment

Choose a reason for hiding this comment

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

Overall looks good!
But I have one suggestion regarding the config.

// capacity thresholds and the actual use if there is any suitable member cluster.
func getClusterIfApproved(cl client.Client, crtConfig *crtCfg.Config, userSignup *toolchainv1alpha1.UserSignup, getMemberClusters cluster.GetMemberClustersFunc) (bool, string, error) {
config := &toolchainv1alpha1.HostOperatorConfig{}
if err := cl.Get(context.TODO(), types.NamespacedName{Namespace: userSignup.Namespace, Name: "config"}, config); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Well.. I guess we don't want to explicitly load the host operator config in every place where we need the configuration.
Can we abstract access to the config?
Something like config.HostOperatorConfig() function somewhere. And reuse this function everywhere we need access to the config. The function for now could load the corresponding "config" resource but later we can convert it to a controller which will watch the "config" resource and update the internal cache if it's changed. Not sure if we really need such cache though. Maybe the go client cache is already good enough. But we can think about that cache later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes yes yes, I had the very same concern when I was writing the code.
Actually, I started working on a controller that does exactly the same what you proposed with the cache 😄, I just want to submit it as a separated PR and when this automatic approval is done. See this: https://github.com/MatousJobanek/host-operator/tree/hostoperatorconfig-controller/pkg/controller/hostoperatorconfig
For now, I decided to load it here and then replace it with calling the cache.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK. Makes sense. Let's keep it for a separate PR then!

pkg/controller/usersignup/approval.go Outdated Show resolved Hide resolved
pkg/controller/usersignup/approval.go Show resolved Hide resolved
pkg/controller/usersignup/approval.go Outdated Show resolved Hide resolved
Copy link
Contributor

@rajivnathan rajivnathan left a comment

Choose a reason for hiding this comment

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

Nice, really like the use of cluster condition functions and status creator functions. 👍

Added a suggestion for reducing the nesting in the hasEnoughResources function. Not sure if you think it makes it more readable so feel free to ignore if you disagree.

Copy link
Contributor

@tinakurian tinakurian left a comment

Choose a reason for hiding this comment

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

looks great @MatousJobanek thanks for addressing my comments!

@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alexeykazakov, MatousJobanek, rajivnathan, tinakurian

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 [MatousJobanek,alexeykazakov]

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

@codecov
Copy link

codecov bot commented Oct 7, 2020

Codecov Report

❗ No coverage uploaded for pull request base (master@c97e93e). Click here to learn what that means.
The diff coverage is 83.76%.

@@            Coverage Diff            @@
##             master     #288   +/-   ##
=========================================
  Coverage          ?   83.58%           
=========================================
  Files             ?       25           
  Lines             ?     2151           
  Branches          ?        0           
=========================================
  Hits              ?     1798           
  Misses            ?      275           
  Partials          ?       78           
Impacted Files Coverage Δ
pkg/counter/cache.go 93.65% <ø> (ø)
...es/notificationtemplates/notification_generator.go 93.33% <ø> (ø)
...plates/nstemplatetiers/nstemplatetier_generator.go 90.76% <ø> (ø)
pkg/controller/masteruserrecord/sync.go 95.34% <60.00%> (ø)
...controller/deactivation/deactivation_controller.go 66.66% <66.66%> (ø)
pkg/controller/usersignup/usersignup_controller.go 69.09% <68.64%> (ø)
pkg/configuration/configuration.go 71.42% <68.75%> (ø)
...controller/notification/notification_controller.go 72.56% <72.56%> (ø)
pkg/controller/nstemplatetier/label_selector.go 76.47% <76.47%> (ø)
pkg/controller/usersignup/masteruserrecord.go 88.46% <78.57%> (ø)
... and 14 more

@MatousJobanek MatousJobanek merged commit 643e1f1 into codeready-toolchain:master Oct 7, 2020
ibuziuk pushed a commit to ibuziuk/host-operator that referenced this pull request Mar 16, 2023
…n#288)

* remove minishft support in makefile

* updated readme to remove minishift reference

* remove login-as-admin

* PR suggestions added

* added indentation

* updated indentation

* if indentation updated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants