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

K8SPG-555: fix updating CA secrets to 2.5.0 #906

Merged
merged 9 commits into from
Sep 27, 2024
Merged

K8SPG-555: fix updating CA secrets to 2.5.0 #906

merged 9 commits into from
Sep 27, 2024

Conversation

pooknull
Copy link
Contributor

@pooknull pooknull commented Sep 23, 2024

K8SPG-555 Powered by Pull Request Badge

https://perconadev.atlassian.net/browse/K8SPG-555

DESCRIPTION

This PR fixes a problem introduced by #876.

Problem:
During the update to 2.5.0, the operator creates a new CA.

Solution:
Operator should create a copy of an old CA secret, if it exists, with a new name unique to a cluster.

This PR also adds validation for the following fields:

  • .spec.customRootCATLSSecret
  • .spec.customTLSSecret
  • .spec.customReplicationTLSSecret

It's necessary, because crunchy code silently creates new certificates if wrong values were set.

CHECKLIST

Jira

  • Is the Jira ticket created and referenced properly?
  • Does the Jira ticket have the proper statuses for documentation (Needs Doc) and QA (Needs QA)?
  • Does the Jira ticket link to the proper milestone (Fix Version field)?

Tests

  • Is an E2E test/test case added for the new feature/change?
  • Are unit tests added where appropriate?

Config/Logging/Testability

  • Are all needed new/changed options added to default YAML files?
  • Did we add proper logging messages for operator actions?
  • Did we ensure compatibility with the previous version or cluster upgrade process?
  • Does the change support oldest and newest supported PG version?
  • Does the change support oldest and newest supported Kubernetes version?

@pooknull pooknull marked this pull request as ready for review September 23, 2024 19:21
Comment on lines +348 to +361
if cr.CompareVersion("2.5.0") < 0 {
if k8serrors.IsNotFound(err) {
// K8SPG-555: We should create an empty secret with old name, so that crunchy part can populate it
// instead of creating secrets unique to the cluster
// TODO: remove when 2.4.0 will become unsupported
if err := r.Client.Create(ctx, oldCASecret); err != nil {
return errors.Wrap(err, "failed to create ca secret")
}
}
return nil
}
if k8serrors.IsNotFound(err) {
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

can we merge these two conditions:

Suggested change
if cr.CompareVersion("2.5.0") < 0 {
if k8serrors.IsNotFound(err) {
// K8SPG-555: We should create an empty secret with old name, so that crunchy part can populate it
// instead of creating secrets unique to the cluster
// TODO: remove when 2.4.0 will become unsupported
if err := r.Client.Create(ctx, oldCASecret); err != nil {
return errors.Wrap(err, "failed to create ca secret")
}
}
return nil
}
if k8serrors.IsNotFound(err) {
return nil
}
if k8serrors.IsNotFound(err) {
if cr.CompareVersion("2.5.0") < 0 {
// K8SPG-555: We should create an empty secret with old name, so that crunchy part can populate it
// instead of creating secrets unique to the cluster
// TODO: remove when 2.4.0 will become unsupported
if err := r.Client.Create(ctx, oldCASecret); err != nil {
return errors.Wrap(err, "failed to create ca secret")
}
}
return nil
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can't merge it, because we have to return if the version is lower than 2.5.0, even if secret was found.

// We should copy the contents of the old CA secret, if it exists, to the new one, which is unique for each cluster.
// TODO: remove when 2.4.0 will become unsupported
newCASecret := &corev1.Secret{
ObjectMeta: naming.PostgresRootCASecret(&v1beta1.PostgresCluster{ObjectMeta: metav1.ObjectMeta{Name: cr.Name, Namespace: cr.Namespace}}),
Copy link
Contributor

Choose a reason for hiding this comment

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

can we break this into multiple lines?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

egegunes
egegunes previously approved these changes Sep 25, 2024
inelpandzic
inelpandzic previously approved these changes Sep 25, 2024
Copy link
Collaborator

@hors hors left a comment

Choose a reason for hiding this comment

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

@pooknull please check test

@pooknull pooknull dismissed stale reviews from inelpandzic and egegunes via 9692e44 September 26, 2024 12:21
@JNKPercona
Copy link
Collaborator

Test name Status
custom-extensions passed
custom-tls passed
demand-backup passed
finalizers passed
init-deploy passed
major-upgrade passed
monitoring passed
one-pod passed
operator-self-healing passed
pitr passed
scaling passed
scheduled-backup passed
self-healing passed
start-from-backup passed
tablespaces passed
telemetry-transfer passed
upgrade-consistency passed
upgrade-minor passed
users passed
We run 19 out of 19

commit: 75f148f
image: perconalab/percona-postgresql-operator:PR-906-75f148fdb

@hors hors merged commit bd9bc14 into main Sep 27, 2024
16 of 17 checks passed
@hors hors deleted the dev/K8SPG-555-fix branch September 27, 2024 11:29
jvpasinatto pushed a commit that referenced this pull request Sep 27, 2024
* K8SPG-555: fix updating CA secrets to 2.5.0

https://perconadev.atlassian.net/browse/K8SPG-555

* fix

* add validation for custom certificates

* improve validation

* break into multiple lines

* fix

* small fix

---------

Co-authored-by: Viacheslav Sarzhan <[email protected]>
@pooknull pooknull mentioned this pull request Oct 2, 2024
10 tasks
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.

6 participants