-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
3879 test acme issuer setup #3938
3879 test acme issuer setup #3938
Conversation
/release-note-none |
/test pull-cert-manager-e2e-v1-20 |
Allow the functionality to set up a new ACME client and to retrieve and decode ACME account's key to be stubbed in tests Signed-off-by: irbekrm <irbekrm@gmail.com>
…erals This commit also ensures that issuer's observed generation is updated in cases where the issuer spec has changed, but the re-registration is skipped as the current registration seems already valid Signed-off-by: irbekrm <irbekrm@gmail.com>
….Registry Signed-off-by: irbekrm <irbekrm@gmail.com>
A simpler implementation than https://github.com/kubernetes/client-go/blob/master/kubernetes/typed/core/v1/fake/fake_secret.go and more suited for unit tests that don't spin up a controller Signed-off-by: irbekrm <irbekrm@gmail.com>
So they can be generated in tests with less lines of code Signed-off-by: irbekrm <irbekrm@gmail.com>
Signed-off-by: irbekrm <irbekrm@gmail.com>
Signed-off-by: irbekrm <irbekrm@gmail.com>
e0613c3
to
e82ea35
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @irbekrm and sorry for delay.
Here's a partial review....more to follow.
pkg/issuer/acme/setup.go
Outdated
apiutil.SetIssuerCondition(a.issuer, a.issuer.GetGeneration(), v1.IssuerConditionReady, cmmeta.ConditionFalse, "InvalidConfig", | ||
fmt.Sprintf("Your ACME server URL is set to a v1 endpoint (%s). "+ | ||
"You should update the spec.acme.server field to %q", a.issuer.GetSpec().ACME.Server, newURL)) | ||
reason = errorInvalidConfig | ||
msg = fmt.Sprintf(messageTemplateUpdateToV2, a.issuer.GetSpec().ACME.Server, newURL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idea: Should we / do we have API validation to prevent people using these v1 endpoints? If not, perhaps we should.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again @irbekrm
Here are some further remarks and suggestions which you can address or answer as you please.
I note there are still one or two areas of untested code in the Setup function, but the new coverage is great.
/test pull-cert-manager-e2e-v1-20-feature-issuers-venafi-tpp |
3e4ac47
to
c55f81b
Compare
Signed-off-by: irbekrm <irbekrm@gmail.com>
c55f81b
to
9ecf896
Compare
Thank you very much for the code review @wallrj ! I have tried to address all the comments, in some cases by creating new issues. Thank you for the coverage, this is very useful. I have added one new test case and created #4006 for testing the functionality for updating ACME account email. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all those followup issues and extra comments etc
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: irbekrm, wallrj 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:
Approvers can indicate their approval by writing |
This PR adds unit tests for ACME issuer's
Setup
function.This follows #3877 , see the comment about testing here .
Some notes:
This test is not a particularly good unit test- all the methods of
Acme
struct should be refactored to make them more testable. However, maybe it would be better if we merged (if we are going to at all) Remove /pkg/issuer in favour of individual controllers. #3695 first. Also maybe already having some unit test in place would make refactoring easier.We usually unit test using test builder, which helps with mocking requests to kubernetes API server. It did not seem to make sense to use the test builder here because
Setup
does not have access to controller's context etc. This made it difficult to, for example, properly mock requests to create/list secrets. Again, refactoringSetup
could help with this.This PR slightly refactors the
Setup
function:Setup
function is called due to issuer's spec having changed and we hit this code path. (I have seen this when modifyingissuer.spec.acme.externalAccountBinding
for an already valid issuer). Perhaps this should have been a separate PR?I think that the easiest way to code-review this PR might be to read through the test cases top to bottom and look at the
Setup
function's flow in parallel as the test cases are mostly ordered to follow the function's flow (/cc @wallrj ). The test does not cover all the code paths- I think that perhaps more thorough testing could be done after merging this PR when we are in a better position to refactor this function?/kind cleanup