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

allow for approved status false after user sign up deactivated #351

Conversation

mmulholla
Copy link
Contributor

@mmulholla mmulholla commented Oct 5, 2023

Fix required for: codeready-toolchain/host-operator#868

it should not cause a regression because this condition:
approvedCondition.Reason != toolchainv1alpha1.UserSignupUserDeactivatedReason
can only be true without codeready-toolchain/host-operator#868

This is the issue it fixes as a result of codeready-toolchain/host-operator#868

=== NAME  TestSignupOK/test_activation-deactivation_workflow
    host.go:711: waiting for UserSignup 'testuser-e808fd7d-bf83-4cdc-abe8-1b72c80c1a9e' in namespace 'toolchain-host-05094958' to match criteria
    host.go:1982: waiting until Space 'testuser-e808fd7d-bf' in namespace 'toolchain-host-05094958' is deleted
    host.go:2028: waiting until SpaceBindings with labels 'map[toolchain.dev.openshift.com/space:testuser-e808fd7d-bf]' in namespace 'toolchain-host-05094958' are deleted
    regsvc.go:16: invoking http request: GET https://registration-service-toolchain-host-05094958.apps.martin-4.12-092615.qe.openshiftappsvc.org/api/v1/signup
    regsvc.go:26: response status code: 200
    regsvc.go:33: 
           Error Trace:   /Users/martinmulholland/codeready-toolchain/toolchain-e2e/testsupport/regsvc.go:33
                                   /Users/martinmulholland/codeready-toolchain/toolchain-e2e/test/e2e/parallel/registration_service_test.go:805
                                   /Users/martinmulholland/codeready-toolchain/toolchain-e2e/test/e2e/parallel/registration_service_test.go:381
           Error:         Not equal: 
                          expected: 404
                          actual  : 200
           Test:          TestSignupOK/test_activation-deactivation_workflow
           Messages:      unexpected response status with body: {"name":"testuser-e808fd7d-bf83-4cdc-abe8-1b72c80c1a9e","compliantUsername":"testuser-e808fd7d-bf","username":"testuser-e808fd7d-bf83-4cdc-abe8-1b72c80c1a9e","givenName":"","familyName":"","company":"","status":{"ready":false,"reason":"PendingApproval","verificationRequired":false}}

@openshift-ci
Copy link

openshift-ci bot commented Oct 5, 2023

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: mmulholla
Once this PR has been reviewed and has the lgtm label, please assign alexeykazakov for approval. For more information see the Kubernetes Code Review Process.

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

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

@openshift-ci
Copy link

openshift-ci bot commented Oct 5, 2023

Hi @mmulholla. Thanks for your PR.

I'm waiting for a codeready-toolchain 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.

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.

@alexeykazakov
Copy link
Contributor

/ok-to-test

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.

I think the unit tests should be updated to.

@@ -438,7 +438,8 @@ func (s *ServiceImpl) DoGetSignup(ctx *gin.Context, provider ResourceProvider, u
// Check UserSignup status to determine whether user signup is complete
approvedCondition, approvedFound := condition.FindConditionByType(userSignup.Status.Conditions, toolchainv1alpha1.UserSignupApproved)
completeCondition, completeFound := condition.FindConditionByType(userSignup.Status.Conditions, toolchainv1alpha1.UserSignupComplete)
if !approvedFound || !completeFound || approvedCondition.Status != apiv1.ConditionTrue {
if !approvedFound || !completeFound ||
( approvedCondition.Status != apiv1.ConditionTrue && approvedCondition.Reason != toolchainv1alpha1.UserSignupUserDeactivatedReason) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should replace it by:

Suggested change
( approvedCondition.Status != apiv1.ConditionTrue && approvedCondition.Reason != toolchainv1alpha1.UserSignupUserDeactivatedReason) {
condition.IsFalseWithReason(userSignup.Status.Conditions, toolchainv1alpha1.UserSignupApproved, toolchainv1alpha1.UserSignupPendingApprovalReason {

This is the actual condition we set for UserSignup when it's pending approval:

  - reason: PendingApproval
    status: "False"
    type: Approved

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 can do that if you prefer but my concern would be that is is more strict than the current code which could lead to other behavior changes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I still think it's better to rely on the PendingApproval reason.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated

Comment on lines 439 to 442
approvedCondition, approvedFound := condition.FindConditionByType(userSignup.Status.Conditions, toolchainv1alpha1.UserSignupApproved)
completeCondition, completeFound := condition.FindConditionByType(userSignup.Status.Conditions, toolchainv1alpha1.UserSignupComplete)
if !approvedFound || !completeFound || approvedCondition.Status != apiv1.ConditionTrue {
if !approvedFound || !completeFound ||
(approvedCondition.Status != apiv1.ConditionTrue && approvedCondition.Reason != toolchainv1alpha1.UserSignupUserDeactivatedReason) {
Copy link
Contributor

@MatousJobanek MatousJobanek Oct 9, 2023

Choose a reason for hiding this comment

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

EDIT: I misread the conditions - all good ;-)

this would mean that if the approved is found, but the status is not true (is pending approval), then the if statement would be evaluated as "false", which would mean (in this context) as approved, which is wrong, right?

Please try to play with the condition. package - you may found some useful functions there that could simplify it.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm idiot 🤦‍♂️
It's Monday and I cannot read the if statement correctly. Your version should work fine.
Could you please add/update some unit tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have updated the tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also changed the if statement per Alexey's comment .

@openshift-ci
Copy link

openshift-ci bot commented Oct 9, 2023

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

Test name Commit Details Required Rerun command
ci/prow/e2e f2b1b0a link true /test e2e

Full PR test history. Your PR dashboard.

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.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Oct 9, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@@ -1093,7 +1093,8 @@ func (s *TestSignupServiceSuite) TestGetSignupDeactivated() {
// given
s.ServiceConfiguration(configuration.Namespace(), true, "", 5)

us := s.newUserSignupCompleteWithReason("Deactivated")
us := s.newUserSignupComplete()
us.Status.Conditions = deactivated()
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I'm missing something but this test doesn't seem to check the signup payload status in lines 1132-1133. So it doesn't really test the changed signup service. Could you please add it to the test? Check the status.

@mmulholla
Copy link
Contributor Author

Had to rename the branch because it was picking up the toolchain-e2e branch in my fork which was causing failures but are needed for host-operator changes. New PR is: #354

@mmulholla mmulholla closed this Oct 9, 2023
@mmulholla mmulholla deleted the RemoveUserSignUpApprovalAfterDeactivation branch October 11, 2023 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants