-
Notifications
You must be signed in to change notification settings - Fork 33
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: certificates generation package and secrets #777
refactor: certificates generation package and secrets #777
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #777 +/- ##
==========================================
- Coverage 74.05% 72.97% -1.09%
==========================================
Files 28 26 -2
Lines 1808 1780 -28
==========================================
- Hits 1339 1299 -40
- Misses 353 366 +13
+ Partials 116 115 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
fef8105
to
bcb9c32
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.
I think we should address some naming confusion about Policy Server CA, see my notes.
Overall LGTM
@@ -164,6 +164,14 @@ func getTestPolicyServerService(policyServerName string) (*corev1.Service, error | |||
return &service, nil | |||
} | |||
|
|||
func getTestPolicyServerCASecret() (*corev1.Secret, error) { |
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.
This is retrieving the Root CA created by our controller. I suggest to rename this helper function to reflect that.
Maybe something like getInternalRootCASecret
?
type generateCertFunc = func(ca []byte, commonName string, extraSANs []string, CAPrivateKey *rsa.PrivateKey) ([]byte, []byte, error) | ||
|
||
func (r *Reconciler) fetchOrInitializePolicyServerCASecret(ctx context.Context, policyServer *policiesv1.PolicyServer, caSecret *corev1.Secret, generateCert generateCertFunc) error { | ||
func (r *Reconciler) fetchOrInitializePolicyServerCASecret(ctx context.Context, policyServer *policiesv1.PolicyServer, caSecret *corev1.Secret) error { |
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.
Again, there's a bit of naming confusion here we inherited from the past.
This method creates the certificate used by a specific Policy Server instance, there's no CA associated with a Policy Server
} | ||
|
||
func (r *Reconciler) fetchOrInitializePolicyServerCARootSecret(ctx context.Context, policyServer *policiesv1.PolicyServer, generateCA generateCAFunc, pemEncodeCertificate pemEncodeCertificateFunc) (*corev1.Secret, error) { | ||
func (r *Reconciler) fetchOrInitializePolicyServerCARootSecret(ctx context.Context, policyServer *policiesv1.PolicyServer) (*corev1.Secret, error) { |
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.
Same here, the naming is confusing since no CA is stored inside of the Secret
that is returned
return policyServerSecret, nil | ||
} | ||
|
||
func updateSecretCA(policyServerSecret *corev1.Secret, generateCA generateCAFunc, pemEncodeCertificate pemEncodeCertificateFunc) error { | ||
caRoot, err := generateCA() | ||
func updateCASecret(policyServerSecret *corev1.Secret) error { |
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.
This function is always generating the CA, it doesn't look into the contents of the secret that is passed as parameter.
Why don't we change the signature of the function to be something like that?
func createInternalCASecret() (policyServerSecret *corev1.Secret, error)
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.
Maybe something for later, but I would also rename this file since it can mislead into thinking each Policy Server has a dedicated CA
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
Signed-off-by: Fabrizio Sestito <fabrizio.sestito@suse.com>
c3cbdf4
to
c5a217e
Compare
Blocked: waiting for 1.14 release |
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.
Approving, the naming changes I've suggested are going to be done inside of future PRs
Description
This PR refactors the generation utilities in the
admissionregistration
package,removing duplication and simplifying the current implementation.
It renames
admissionregistration
incerts
and reactors the existing reconciler unit test in integration tests clauses.Additional info
This PR also changes the golangci configuration to add an exception for the
ok
map index in thevarnamelen
linter. However we should uniform and clean up the golangci configurations across all the KW repos, this is tracked by: Uniform golangci configuration across all repositories #778There are a few incongruences with the naming, for instance, this status
kubewarden-controller/pkg/apis/policies/v1/policyserver_types.go
Line 132 in 030edce
CertSecretReconciled
instead. Fixing this is out of scope for this PR and I will create an issue about it.Fixes: #775, #664