K8SPXC-1848: update existing cert-manager Certificate CRs on operator upgrade#2414
K8SPXC-1848: update existing cert-manager Certificate CRs on operator upgrade#2414larainema wants to merge 1 commit intopercona:mainfrom
Conversation
|
|
|
|
pkg/controller/pxc/tls.go
Outdated
| return fmt.Errorf("create CA certificate: %v", err) | ||
| err := r.createOrUpdateCertificate(ctx, caCert) | ||
| if err != nil { | ||
| return fmt.Errorf("create or update CA certificate: %v", err) |
There was a problem hiding this comment.
please wrap errors here other changed lines
| return nil | ||
| } | ||
|
|
||
| func (r *ReconcilePerconaXtraDBCluster) createOrUpdateCertificate(ctx context.Context, desired *cm.Certificate) error { |
There was a problem hiding this comment.
would it be better to use controllerutil.CreateOrUpdate?
65f04b9 to
6feb7f0
Compare
egegunes
left a comment
There was a problem hiding this comment.
Code changes LGTM.
We need to add a case into e2e tests though, probably to tls-issue-cert-manager:
- Patch PerconaXtraDBCluster to change something under
spec.tls, potentially the duration. - Check if certificates are updated.
- Ensure cluster is still available.
@eleo007 wdyt?
egegunes
left a comment
There was a problem hiding this comment.
@larainema please add a case into tls-issue-cert-manager e2e tests to check certificate updates
d345033 to
41d97bd
Compare
createSSLByCertManager() uses r.client.Create() with an IsAlreadyExists guard, so any spec changes (duration, renewBefore, SANs, labels) introduced in newer operator versions are never applied to Certificate CRs that were created by an older version. The most significant impact is the CA certificate duration: clusters originally deployed with operator < 1.15.0 still carry duration=8760h (1 year) instead of the current default of 26280h (3 years). Replace the create-and-ignore pattern with a createOrUpdateCertificate helper that attempts Create first, and on AlreadyExists fetches the existing Certificate, compares Spec and Labels, and issues an Update when they differ. Fixes percona#2413
41d97bd to
d346d57
Compare
commit: d346d57 |
Problem
createSSLByCertManager()usesr.client.Create()with anIsAlreadyExistsguard for all three cert-manager Certificate resources (CA, ssl, ssl-internal). When the Certificate CR already exists, the function silently skips it — any spec changes introduced in newer operator versions are never applied.The most significant impact is the CA certificate duration: clusters originally deployed with operator < 1.15.0 still carry
duration: 8760h(1 year) instead of the current default26280h(3 years), because the Certificate CR was never updated after the operator upgrade.Fixes #2413
Root Cause
The same pattern is used for all three Certificate CRs. On
AlreadyExists, the new desired spec is discarded.Fix
Add a
createOrUpdateCertificate()helper that:Createfirst (fast path for new clusters)AlreadyExists: fetches the existing Certificate CRSpecandLabelsusingreflect.DeepEqualUpdateAll three call sites in
createSSLByCertManagernow use this helper.Affected Fields (now reconciled on upgrade)
spec.duration— CA validity (most impactful: 1yr → 3yr)spec.renewBeforespec.dnsNames(SANs)spec.commonNamelabelsRelated