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

fix(controller): Ensure that OAuth2Client reconciliation creates hydra client for specs #83

Merged
merged 6 commits into from
Sep 14, 2021
Merged

fix(controller): Ensure that OAuth2Client reconciliation creates hydra client for specs #83

merged 6 commits into from
Sep 14, 2021

Conversation

alexandrem
Copy link
Contributor

@alexandrem alexandrem commented Aug 27, 2021

The reconciliation logic for OAuth2Client resources doesn't create custom hydra client for the requested CR spec and always falls back to the default hydra client.

This PR fixes this issue and ensures that different hydra clients with their own admin URLs, ports and endpoints can be used concurrently.

Note that some code refactoring was required to get rid of some import cycles introduced by the change.

I'm looking for some guidance to add a unit test if necessary.

Related issue(s)

#82

Checklist

  • I have read the contributing guidelines
    and signed the CLA.
  • I have read the security policy.
  • I confirm that this pull request does not address a security
    vulnerability. If this pull request addresses a security vulnerability, I
    confirm that I got green light (please contact
    [email protected]) from the maintainers to push
    the changes.
  • I have added tests that prove my fix is effective or that my feature
    works.
  • I have added necessary documentation within the code base (if
    appropriate).

@CLAassistant
Copy link

CLAassistant commented Aug 27, 2021

CLA assistant check
All committers have signed the CLA.

@alexandrem alexandrem changed the title Ensure that OAuth2Client reconciliation creates hydra client for specs fix(controller): Ensure that OAuth2Client reconciliation creates hydra client for specs Aug 27, 2021
@piotrmsc
Copy link
Collaborator

Hey @alexandrem, thank you for such a fast contribution! I take your PR and review it (already started) :)

@piotrmsc piotrmsc self-requested a review August 31, 2021 12:03
Copy link
Collaborator

@piotrmsc piotrmsc left a comment

Choose a reason for hiding this comment

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

I went through your PR, I left you couple of comments but in general going into fixed direction 😃

controllers/oauth2client_controller.go Outdated Show resolved Hide resolved
@@ -352,17 +364,27 @@ func parseSecret(secret apiv1.Secret, authMethod hydrav1alpha1.TokenEndpointAuth
}, nil
}

func (r *OAuth2ClientReconciler) getHydraClientForClient(oauth2client hydrav1alpha1.OAuth2Client) (HydraClientInterface, error) {
func (r *OAuth2ClientReconciler) getHydraClientForClient(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This IMO should have a test, unit at least

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'll work on this today.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Usually I find it a bit anti-idiomatic to create a unit test for a private function.

I'm wondering if we should we create an integration test for this instead?

hydra/client.go Show resolved Hide resolved
@piotrmsc
Copy link
Collaborator

piotrmsc commented Sep 2, 2021

@alexandrem Thank you for replying, I will address your changes and comments today but later in the day, I have to finish first my stuff :)

@alexandrem
Copy link
Contributor Author

@piotrmsc I just pushed some fixes in 9633930

I was able to setup my environment to run the integration tests. Everything passes now.

I had to introduce a oauth2 client factory function for the new reconciler logic introduced in this PR to be able to work with the mock object used during the integration tests. This is abstracted with functional options so that it doesn't complicate normal usage outside of tests. Let me know if you think there's a better way though.

The tests made me realize there was an issue with the oauth2 client map concurrent usage during reconciliation loops, so it's now secured with a mutex.

@piotrmsc
Copy link
Collaborator

piotrmsc commented Sep 2, 2021

so what issues did you have with integration tests to set it up?

@alexandrem
Copy link
Contributor Author

alexandrem commented Sep 2, 2021

I have a Mac M1. Kubebuilder tooling and K8s ecosystem is not up to par yet, unfortunately.

It would help to have all of that containerized or rework the tooling in this project to simplify the tests prerequisites. I might propose something in another PR :)

@piotrmsc
Copy link
Collaborator

piotrmsc commented Sep 6, 2021

yeah, some time ago I see there was an upgrade to kubebuilder v2 done but make targets were not updated and for ex env-test setup is outdated.

Regarding your changes, I will take a look tomorrow in the morning (CEST) :)

Copy link
Collaborator

@piotrmsc piotrmsc left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution 🎉

@piotrmsc piotrmsc merged commit 028c3df into ory:master Sep 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants