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

Refactor MasterUserRecordController and tests to use only propagated claims #943

Merged
merged 11 commits into from
Dec 14, 2023

Conversation

sbryzak
Copy link
Contributor

@sbryzak sbryzak commented Dec 1, 2023

This PR refactors the MasterUserRecordController to only use propagated claims when creating UserAccount etc.

Related toolchain-common PR: codeready-toolchain/toolchain-common#345

Fixes https://issues.redhat.com/browse/SANDBOX-482

e2e tests: codeready-toolchain/toolchain-e2e#862

Copy link
Contributor

@MatousJobanek MatousJobanek left a comment

Choose a reason for hiding this comment

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

I don't see any changes regarding to the modified UserID function from the toolchain-common. It sets different value than it did before, so my question is, do we still need the function? Does it serve to our needs and do we use it properly?

Comment on lines +2476 to +2480
IdentityClaims: toolchainv1alpha1.IdentityClaimsEmbedded{
PropagatedClaims: toolchainv1alpha1.PropagatedClaims{
Email: "[email protected]",
},
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we actually need to add the email when:

  • there was no email set before
  • in the toolchain-common PR you mentioned that you want to modify MUR and UserAccount only, not UserSignup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know that without the email address being set here, the black box mystery that is the metrics tests will fail. I've spent some time trying to work out why this is the case, and my only suspicion is that it's related to the email domain function.

Copy link
Contributor

Choose a reason for hiding this comment

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

Talking about notifications - I see that the e2e tests are failing for the idling notifications. My guess is that it's because the idler controller is still using the email annotation for sending the notification. You need to update that part first before dropping it from the MUR:
https://github.com/codeready-toolchain/member-operator/blob/f4220407cbae99fa7d3713504fef5f7dbd196ace/controllers/idler/idler_controller.go#L270-L271

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MatousJobanek thanks for pointing this out, I wasn't aware of the idler controller or what it did. I've updated it to now use the propagated claims.

Comment on lines 22 to +30
func GetEmailDomain(obj RuntimeObject) Domain {
emailAddress, exists := obj.GetAnnotations()[toolchainv1alpha1.UserSignupUserEmailAnnotationKey]
if !exists {
log.Error(nil, "no email address found in annotations", "kind", obj.GetObjectKind().GroupVersionKind().Kind, "name", obj.GetName())
emailAddress := ""

switch obj := obj.(type) {
case *toolchainv1alpha1.MasterUserRecord:
emailAddress = obj.Spec.PropagatedClaims.Email
case *toolchainv1alpha1.UserSignup:
emailAddress = obj.Spec.IdentityClaims.Email
}
Copy link
Contributor

Choose a reason for hiding this comment

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

if you change the type of the parameter of the function to take the PropagatedClaims, then it would simplify the logic and it would be also clear what the function does - where the value takes from. There is no need for checking the types.

func GetEmailDomain(claims toolchainv1alpha1.PropagatedClaims) Domain {
	emailAddress := claims.Email

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 is a little simpler yes, however it would also mean that we lose details in the logs if the email address is not found. We cannot determine the object type or the name from just the PropagatedClaims.

log.Error(nil, "no email address found in object", "kind", obj.GetObjectKind().GroupVersionKind().Kind, "name", obj.GetName())

Copy link
Contributor

Choose a reason for hiding this comment

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

fair enough 👍

Copy link

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
14.8% Duplication on New Code

See analysis details on SonarCloud

Copy link

codecov bot commented Dec 13, 2023

Codecov Report

Merging #943 (9b6be77) into master (3962b29) will decrease coverage by 0.10%.
The diff coverage is 81.81%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #943      +/-   ##
==========================================
- Coverage   83.81%   83.71%   -0.10%     
==========================================
  Files          53       53              
  Lines        6159     6128      -31     
==========================================
- Hits         5162     5130      -32     
- Misses        814      815       +1     
  Partials      183      183              
Files Coverage Δ
...rs/masteruserrecord/masteruserrecord_controller.go 80.64% <ø> (-0.90%) ⬇️
controllers/masteruserrecord/sync.go 85.63% <100.00%> (-0.45%) ⬇️
controllers/usersignup/masteruserrecord.go 100.00% <100.00%> (ø)
pkg/metrics/email_domain.go 85.71% <77.77%> (-14.29%) ⬇️

... and 1 file with indirect coverage changes

Copy link
Contributor

@MatousJobanek MatousJobanek 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 answering my comments 👍

Copy link

openshift-ci bot commented Dec 13, 2023

[APPROVALNOTIFIER] This PR is APPROVED

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

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,sbryzak]

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

@sbryzak sbryzak merged commit 11d924f into codeready-toolchain:master Dec 14, 2023
9 of 10 checks passed
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.

5 participants