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

drop CRTClient abstraction #473

Merged

Conversation

MatousJobanek
Copy link
Contributor

@MatousJobanek MatousJobanek commented Oct 2, 2024

  • drops the CRTClient abstraction and all the related types.
  • It uses only the InformerService as the ResourceProvider for getting ifnromation about UserSignups. The InformerService will go away as well, it's just getting harder to make incremental changes 🤯
    • This also simplifies some of the unit-tests as we don't have to test two different types of implementation of the ResourceProvider
  • I introduced a new type called namespaced.Client which holds the Client itself plus the host operator namespace. With this type it's much easier to propagate the Client and the namespace in the services.
  • It now calls the client directly (instead of relying on the abstraction & types), in those cases where the CRTClient was used.

KUBESAW-197

Comment on lines +13 to 18
func NewMemberClusterServiceContext(_ *testing.T, cl client.Client) fake.MemberClusterServiceContext {
return fake.MemberClusterServiceContext{
CrtClient: crtClient,
Svcs: application,
NamespacedClient: namespaced.NewClient(cl, commontest.HostOperatorNs),
Svcs: server.NewInClusterApplication(cl, commontest.HostOperatorNs),
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will go away in one of the following PRs. Just wanted to minimize the number of changes so I left it here for now.

Comment on lines +629 to +634
labelSelector := client.MatchingLabels{
toolchainv1alpha1.UserSignupStateLabelKey: toolchainv1alpha1.UserSignupStateLabelValueApproved,
toolchainv1alpha1.BannedUserPhoneNumberHashLabelKey: labelValue,
}
userSignups := &toolchainv1alpha1.UserSignupList{}
if err := s.List(gocontext.TODO(), userSignups, client.InNamespace(s.Namespace), labelSelector); err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Originally, we listed UserSignups that were NOT deactivated nor not-ready.
see:

selector := labels.NewSelector()
stateRequirement, err := labels.NewRequirement(crtapi.UserSignupStateLabelKey, selection.NotIn, []string{crtapi.UserSignupStateLabelValueDeactivated, crtapi.UserSignupStateLabelValueNotReady})
if err != nil {
return nil, err
}

This means usersignups that were either approved or banned. Banned user are already covered by the BannedUser CRs, so I decided to simplify the logic and list only the approved ones.

Copy link

codecov bot commented Oct 2, 2024

Codecov Report

Attention: Patch coverage is 74.19355% with 8 lines in your changes missing coverage. Please review.

Project coverage is 85.43%. Comparing base (d0b1f7d) to head (cff0b63).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
pkg/signup/service/signup_service.go 80.00% 1 Missing and 4 partials ⚠️
pkg/server/in_cluster_application.go 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #473      +/-   ##
==========================================
+ Coverage   82.47%   85.43%   +2.96%     
==========================================
  Files          42       33       -9     
  Lines        2687     2541     -146     
==========================================
- Hits         2216     2171      -45     
+ Misses        385      283     -102     
- Partials       86       87       +1     
Flag Coverage Δ
unittests 85.43% <74.19%> (+2.96%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

Copy link
Contributor

@mfrancisc mfrancisc left a comment

Choose a reason for hiding this comment

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

Looks Good 👍

I have only few minor comments.

pkg/signup/service/signup_service.go Show resolved Hide resolved
pkg/namespaced/client.go Show resolved Hide resolved
if signup.Spec.IdentityClaims.Sub != userID && signup.Spec.IdentityClaims.PreferredUsername != username && !states.Deactivated(signup) { // nolint:gosec

for _, signup := range userSignups.Items {
userSignup := signup
Copy link
Contributor

Choose a reason for hiding this comment

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

is it needed? IIRC, signup is not a pointer

Copy link
Contributor Author

@MatousJobanek MatousJobanek Oct 2, 2024

Choose a reason for hiding this comment

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

no, it's not a pointer, but I create a pointer to the userSignup in the next line and since we still use go 1.20 we have to do this re-assignment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added a comment 8df7f52

Copy link
Contributor

Choose a reason for hiding this comment

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

great, thanks!

Copy link
Contributor

@xcoulon xcoulon left a comment

Choose a reason for hiding this comment

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

thanks for taking my comment into account, @MatousJobanek !

Copy link

openshift-ci bot commented Oct 3, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alexeykazakov, MatousJobanek, mfrancisc, xcoulon

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,mfrancisc,xcoulon]

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

Copy link

sonarcloud bot commented Oct 3, 2024

@MatousJobanek MatousJobanek merged commit c11f3a8 into codeready-toolchain:master Oct 3, 2024
9 of 11 checks passed
MatousJobanek added a commit to MatousJobanek/registration-service that referenced this pull request Oct 3, 2024
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.

4 participants