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

K8SPSMDB-1061: Refactor reconcileStatefulSet #1386

Merged
merged 14 commits into from
Mar 27, 2024
Merged

K8SPSMDB-1061: Refactor reconcileStatefulSet #1386

merged 14 commits into from
Mar 27, 2024

Conversation

pooknull
Copy link
Contributor

@pooknull pooknull commented Nov 30, 2023

K8SPSMDB-1061 Powered by Pull Request Badge

https://perconadev.atlassian.net/browse/K8SPSMDB-1061

DESCRIPTION

Initially, I included it as part of a ticket, but later I found a better solution that didn't require refactoring. However, I believe that a small refactoring could still be beneficial for our code.

The main problem it aims to address is reducing the size of the reconcileStatefulSet and Reconcile methods for the ReconcilePerconaServerMongoDB.

Changes in pkg/controller/perconaservermongodb.go:

  • moved big part of the Reconcile method code to a new method called reconcileReplsets
  • created a new method called getStatefulsetFromReplset that returns a full statefulset based on the replset spec

Changes in pkg/psmdb/statefulset.go:

  • removed a lot of arguments in the StatefulSpec function
  • moved a lot of code from the reconcileStatefulSet method to the StatefulSpec function
  • moved the whole contents of pkg/psmdb/backup/agent.go there

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?
  • Are OpenShift compare files changed for E2E tests (compare/*-oc.yml)?

Config/Logging/Testability

  • Are all needed new/changed options added to default YAML files?
  • Are the manifests (crd/bundle) regenerated if needed?
  • 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 MongoDB version?
  • Does the change support oldest and newest supported Kubernetes version?

@pull-request-size pull-request-size bot added the size/XL 500-999 lines label Nov 30, 2023
@pooknull pooknull marked this pull request as ready for review February 28, 2024 12:08
if cr.Spec.Sharding.Enabled && replset.ClusterRole != api.ClusterRoleConfigSvr && replset.Name == api.ConfigReplSetName {
return reconcile.Result{}, errors.Errorf("%s is reserved name for config server replset", api.ConfigReplSetName)
return "", errors.Errorf("%s is reserved name for config server replset", api.ConfigReplSetName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you added AppStateNone why don't you return that rather than this empty string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This value is ignored when an error is returned. I think it's better to not use const instead of an empty string because if AppStateNone changes in the future, we would still want to have an empty string here

@pull-request-size pull-request-size bot added size/XXL 1000+ lines and removed size/XL 500-999 lines labels Mar 19, 2024
@pooknull pooknull requested a review from inelpandzic March 19, 2024 12:34
inelpandzic
inelpandzic previously approved these changes Mar 20, 2024
return reconcile.Result{}, errors.Wrap(err, "reconcile statefulsets")
}

err = r.stopMongosInCaseOfRestore(ctx, cr)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would put this inside of reconcileMongo since it is related to actually reconciling mongos, and plus, less lines in our Reconcile method.

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 Mar 20, 2024
@pooknull pooknull dismissed stale reviews from egegunes and inelpandzic via 8f80922 March 21, 2024 14:43
inelpandzic
inelpandzic previously approved these changes Mar 25, 2024
@pooknull pooknull changed the title Refactor reconcileStatefulSet K8SPSMDB-1061: Refactor reconcileStatefulSet Mar 26, 2024
egegunes
egegunes previously approved these changes Mar 26, 2024
@JNKPercona
Copy link
Collaborator

Test name Status
arbiter passed
balancer passed
custom-replset-name passed
cross-site-sharded passed
data-at-rest-encryption passed
data-sharded passed
demand-backup passed
demand-backup-eks-credentials passed
demand-backup-physical passed
demand-backup-physical-sharded passed
demand-backup-sharded passed
expose-sharded passed
ignore-labels-annotations passed
init-deploy passed
finalizer passed
ldap passed
ldap-tls passed
limits passed
liveness passed
mongod-major-upgrade passed
mongod-major-upgrade-sharded passed
monitoring-2-0 passed
multi-cluster-service failure
non-voting passed
one-pod passed
operator-self-healing-chaos passed
pitr passed
pitr-sharded passed
pitr-physical passed
recover-no-primary passed
rs-shard-migration passed
scaling passed
scheduled-backup passed
security-context passed
self-healing-chaos passed
service-per-pod passed
serviceless-external-nodes passed
smart-update passed
split-horizon passed
storage passed
tls-issue-cert-manager passed
upgrade passed
upgrade-consistency passed
upgrade-consistency-sharded passed
upgrade-sharded passed
users passed
version-service passed
We run 47 out of 47

commit: 636aa82
image: perconalab/percona-server-mongodb-operator:PR-1386-636aa826

@hors hors merged commit 2acb13c into main Mar 27, 2024
8 checks passed
@hors hors deleted the dev/refactor branch March 27, 2024 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/XXL 1000+ lines
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants