-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 cert handling #9463
Refactor cert handling #9463
Conversation
Signed-off-by: Katherine Stanley <[email protected]>
Signed-off-by: Katherine Stanley <[email protected]>
580114a
to
147d95e
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.
The certificate-manager
module has nothing to do with Secrets. It is only responsible for issuing the certificates. So I'm not sure if we should put any logic related to the Secrets into it. I'm surprised it even builds, because it IMHO should not have any dependency on Fabric8 and should therefore not know the Secret
class.
@@ -25,6 +25,117 @@ | |||
*/ | |||
public class SecretCertProvider { | |||
|
|||
/** | |||
* A certificate entry in a ConfigMap. Each entry contains an entry name and data. |
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.
* A certificate entry in a ConfigMap. Each entry contains an entry name and data. | |
* A certificate entry in a Secret. Each entry contains an entry name and data. |
The SecretCertProvider class was already in the certificate-manager module and contained methods to create Secrets for certificates so I moved the methods there rather than creating another separate class that deals with certificate Secrets. It looks like the addSecret methods in that class are currently used from the Ca class which is in operator-common, so the other methods in SecretCertProvider that are there already can't be moved into cluster-operator without a refactor of the Ca class. However I could move the new methods that I am adding to SecretCertProvider to a new class in cluster-operator? In a follow-up PR I think it would be good to remove any mention of Secrets from the Ca, but I am hesitant to do that as part of this PR as the bigger the refactor the harder it is to review. I did wonder though if as part of that refactor the best outcome would be to have the cluster-operator and user-operator modules have their own separate logic for storing certificates in Secrets, rather than having any of that in operator-common. But I figured that change probably needed an agreed proposal first, what do you think? |
That is a good point. But maybe the best would be to move the |
It might be also worth thinking about whether all of these things are really needed. |
That's a good idea. Yeah, I did also notice that. It seemed like this whole module was added in a commit to introduce a separate certificate module, but the commit message implies that there might be follow up changes, but I didn't see any. @ppatierno do you know if there were other changes expected that would use these methods that are currently only used in test? If not then I think we should definitely clean up the methods that aren't being used. |
My hope is to get to a point that we only have .p12 etc extensions in a single place, rather than constructed differently everywhere, but when I started looking through the changes needed it made sense to do this as a separate PR as there are so many different uses of it. I expect SecretEntry will get replaced with private constants only used by a single class in the end. |
* Change ConfigMap to Secret in Javadoc Signed-off-by: Katherine Stanley <[email protected]>
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.
I left bunch of comments. But honestly, I still don't get how you decided what should be moved to SecretCertProvider and what to CertUtils. They seem to originate from cluster-operator
(at least those I checked - apart from SecretEntry
) as well. So why not move them to CertUtils
and keep them in the same module instead of moving it into module that is shared more widely into a class that does not seem to fit the module anyway?
/** | ||
* @return the generation of the current CA certificate as an annotation | ||
*/ | ||
public Map<String, String> caCertGenerationFullAnnotation() { |
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.
- I think we use to do
Map.of()
in most of the new code. - Should it return Map.Entry if it is a singular by name?
- Why is this used from Cruise Control, ZooKeeper and then from
CertUtils
?
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.
I've updated to change it to Map.Entry. At the moment all of the clustered components (Cruise Control, ZooKeeper, Kafka) call ModelUtils directly to create certificate Secrets. The other components with a single pod call buildTrustedCertificateSecret which is in CertUtils. So that's why there are call from the different places.
cluster-operator/src/main/java/io/strimzi/operator/cluster/model/CertUtils.java
Outdated
Show resolved
Hide resolved
cluster-operator/src/main/java/io/strimzi/operator/cluster/model/CertUtils.java
Outdated
Show resolved
Hide resolved
cluster-operator/src/main/java/io/strimzi/operator/cluster/model/CertUtils.java
Outdated
Show resolved
Hide resolved
cluster-operator/src/main/java/io/strimzi/operator/cluster/model/CertUtils.java
Outdated
Show resolved
Hide resolved
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.
Do all the tests you modified here really test the ModelUtils? Or do they now test the CertUtils
?
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.
These are certificate renewal tests, so not explicitly testing either ModelUtils or CertUtils
certificate-manager/src/test/java/io/strimzi/certs/SecretCertProviderTest.java
Outdated
Show resolved
Hide resolved
I was trying to keep a separation between the classes that need to understand the structure of how certificates are stored in Kube Secrets and those that don't. However, I think you're right that sharing those methods more widely as a result is not the right choice. I think for this PR keeping them in |
Signed-off-by: Katherine Stanley <[email protected]>
Are the CI failures related to the PR? Especially these ones?
|
Signed-off-by: Katherine Stanley <[email protected]>
Yeah, looks like changing the Collections.SingletonMap to Map.of caused some failures related to mock methods, I've added the correct mocking to the tests. |
Signed-off-by: Katherine Stanley <[email protected]>
@scholzj I've added an extra commit that makes better use of the SecretEntry enum |
/azp run regression |
Azure Pipelines successfully started running 1 pipeline(s). |
It's hard to remember and tell. Maybe they were used before then not anymore and being left overs in the tests. I think that after so long time having this cert manager implementation working, we can clean up by removing these methods. |
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.
LGTM. Thanks for the refactoring!
operator-common/src/main/java/io/strimzi/operator/common/model/Ca.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Katherine Stanley <[email protected]>
/azp run regression |
Azure Pipelines successfully started running 1 pipeline(s). |
/azp run kraft-regression |
Azure Pipelines successfully started running 1 pipeline(s). |
Type of change
Description
Tidy up certificate code:
This PR contributes to #5630. I have created this as a separate PR to make it easier to review, this change reduces the number of places that are handling certificates to make it easier to remove the dependence on Kubernetes Secrets in a future PR.
Checklist
Please go through this checklist and make sure all applicable tasks have been done