Skip to content

Implemented data import from the old DB to the cluster on upgrade #1571

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

Merged
merged 1 commit into from
Mar 25, 2025

Conversation

dannyzaken
Copy link
Member

@dannyzaken dannyzaken commented Mar 24, 2025

Explain the changes

  • When upgrading from a deployment with an existing DB, provide the DB details in the cluster CR, to perform data import.
  • Upgrade flow is as follows:
    • If DB sts exist:
      • Stop core\endpoints pods
      • Create a cnpg cluster with import details in the CR
      • The cnpg operator will start the first instance and deploy an import job to import the data. After the import is completed, the second instance will started.
      • Wait for cluster to complete import and become Ready
      • Once ready scale down the noobaa-db-pg sts to 0 replicas.
      • The reconciliation will wait for the cluster to be ready, and a temp error is returned until it is.
  • The old sts is not deleted, to have it around for backup. In future versions we should cleanup all the leftovers.
  • Updated noobaa upgrade command in noobaa cli, to install the necessary cnpg resources.

Gaps

  • CNPG operator performs the import by performing a pg_dump onto the data volume of the instance and then restoring the dump to the new DB. If the existing DB is too large, we can get into an out-of-space situation. To handle this, we should check the percentage of used space in the existing DB and, above a certain threshold, provision a larger volume for the new cluster.

Testing Instructions:

  1. Install noobaa from an older version.
  2. after installed, run noobaa upgrade with a latest build of the CLI. this should install missing cnpg resources and update the noobaa CR to perform import
  • Doc added/updated
  • Tests added

r.Logger.Errorf("cnpg:: "+format, args...)
}

// wasClusterSpecChanged checks if any of the
Copy link
Contributor

Choose a reason for hiding this comment

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

typo?

@@ -514,6 +515,11 @@ func (r *Reconciler) SetDesiredCoreApp() error {
podSpec.ServiceAccountName = "noobaa-core"
coreImageChanged := false

oneReplica := int32(1)
if r.CoreApp.Spec.Replicas != nil && *r.CoreApp.Spec.Replicas == 0 {
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 add a comment here explaining why replicas=0

- When upgrading from a deployment with an existing DB, provide the DB
  details in the cluster CR, to perform data import.
- Upgrade flow is as follows:
  - If DB sts exist:
    - Stop core\endpoints pods
    - Create a cnpg cluster with import details in the CR
    - The cnpg operator will start the first instance and deploy an
      import job to import the data. After the import is completed, the
      second instance will started.
    - Wait for cluster to complete import and become Ready
    - Once ready scale down the noobaa-db-pg sts to 0 replicas.
    - The reconciliation will wait for the cluster to be ready, and a
      temp error is returned until it is.
- The old sts is not deleted, to have it around for backup. In future
  versions we should cleanup all the leftovers.

Signed-off-by: Danny Zaken <[email protected]>
@@ -103,6 +103,31 @@ func RunInstall(cmd *cobra.Command, args []string) {
util.KubeCreateSkipExisting(cnpgRes.WebhooksService)
}

// RunInstall runs the CloudNativePG operator installation
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// RunInstall runs the CloudNativePG operator installation
// RunUpgrade runs the CloudNativePG operator upgrade

r.CNPGCluster.Spec.Bootstrap = &cnpgv1.BootstrapConfiguration{
InitDB: &cnpgv1.BootstrapInitDB{
Database: "nbcore",
Owner: "noobaa",
Copy link
Member Author

Choose a reason for hiding this comment

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

Add other default properties explicitly (like collation, etc.)

func (r *Reconciler) reconcileClusterImport() error {

// The bootstrap configuration should only be set for the CR creation.

Copy link
Member Author

@dannyzaken dannyzaken Mar 25, 2025

Choose a reason for hiding this comment

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

regardless of this code only running in cluster creation flow. guard it to look at the noobaaDbStatus

// microservice type - import only the nbcore database
Type: cnpgv1.MicroserviceSnapshotType,
Databases: []string{
"nbcore",
Copy link
Member Author

Choose a reason for hiding this comment

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

remove "magic strings" and use consts\options instead

@dannyzaken
Copy link
Member Author

I added comments based on an online review with @jackyalbo and @liranmauda. Will handle them in a different PR

@dannyzaken dannyzaken merged commit 401802f into noobaa:master Mar 25, 2025
19 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants