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

migrate from databaseUsername to databaseAccount and fully use MariaDBAccount #681

Conversation

zzzeek
Copy link
Contributor

@zzzeek zzzeek commented Feb 12, 2024

This moves nova to fully use MariaDBAccount based on the dev work being done for mariadb-operator:

https://github.com/openstack-k8s-operators/mariadb-operator/pull/184/files

Lead Jira: OSPRH-4095

  1. controller calls EnsureMariaDBAccount up front to make sure MariaDBAccount is present
  2. error code from EnsureMariaDBAccount is handled, Conditions are amended when error is returned
  3. controller calls NewDatabaseForAccount instead of NewDatabase
  4. GetAccountAndSecret is used to retrieve account /secret to populate template
  5. GetDatabaseByName() , normally used for delete finalizers, replaced with GetDatabaseByNameAndAccount
  6. CreateOrPatchAll() used to patch the Database, replacing CreateOrPatchDB / CreateOrPatchDBByName
  7. controller calls DeleteUnusedMariaDBAccountFinalizers when launched pods are definitely running on a new MariaDBAccount, returns error code if present
  8. PasswordSelectors that refer to database are removed
  9. all databaseUser replaced with databaseAccount inside of all XYZ_types.go
  10. all databaseUser replaced with databaseAccount inside of all kuttl/*.yaml
  11. all default databaseUser names become databaseAccount, replacing underscores with dashes inside of all XYZ_types.go
  12. all default databaseUser names become databaseAccount, replacing underscores with dashes inside of all kuttl/*.yaml
  13. MariaDBAccountSuiteTests are used in controller ginkgo tests if it has them
  14. Use configsecrets for database URLs; remove from job hash - already was like that
  15. 184 is merged and replaces from go.mod are removed

Copy link
Contributor

openshift-ci bot commented Feb 12, 2024

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@zzzeek zzzeek requested a review from gibizer February 12, 2024 22:45
Copy link

Build failed (check pipeline). Post recheck (without leading slash)
to rerun all jobs. Make sure the failure cause has been resolved before
you rerun jobs.

https://review.rdoproject.org/zuul/buildset/5f254123d77e48df99bfe3842ed6a787

nova-operator-content-provider FAILURE in 6m 34s
⚠️ nova-operator-kuttl SKIPPED Skipped due to failed job nova-operator-content-provider
⚠️ nova-operator-tempest-multinode SKIPPED Skipped due to failed job nova-operator-content-provider

@zzzeek zzzeek force-pushed the integrate_oo_accounts branch from 9a39fa2 to 5bd427a Compare February 13, 2024 14:50
Copy link

Merge Failed.

This change or one of its cross-repo dependencies was unable to be automatically merged with the current state of its repository. Please rebase the change and upload a new patchset.
Warning:
Error merging github.com/openstack-k8s-operators/openstack-operator for 656,b5e236beee28729c77e3e70b8b352f873c67e513

@zzzeek zzzeek force-pushed the integrate_oo_accounts branch from 5bd427a to 5823996 Compare February 13, 2024 16:25
Copy link

Merge Failed.

This change or one of its cross-repo dependencies was unable to be automatically merged with the current state of its repository. Please rebase the change and upload a new patchset.
Warning:
Error merging github.com/openstack-k8s-operators/openstack-operator for 656,b5e236beee28729c77e3e70b8b352f873c67e513

@zzzeek zzzeek force-pushed the integrate_oo_accounts branch from 5823996 to fb5c036 Compare February 13, 2024 22:32
Copy link

Merge Failed.

This change or one of its cross-repo dependencies was unable to be automatically merged with the current state of its repository. Please rebase the change and upload a new patchset.
Warning:
Error merging github.com/openstack-k8s-operators/openstack-operator for 656,b5e236beee28729c77e3e70b8b352f873c67e513

Copy link

Merge Failed.

This change or one of its cross-repo dependencies was unable to be automatically merged with the current state of its repository. Please rebase the change and upload a new patchset.
Warning:
Error merging github.com/openstack-k8s-operators/nova-operator for 681,c4cf25a88bc848c8eac8e7a9ef1d587856af821f

@zzzeek
Copy link
Contributor Author

zzzeek commented Feb 14, 2024

/retest

Copy link

Build failed (check pipeline). Post recheck (without leading slash)
to rerun all jobs. Make sure the failure cause has been resolved before
you rerun jobs.

https://review.rdoproject.org/zuul/buildset/eed32e0dba6141ce8579094f069bd555

nova-operator-content-provider FAILURE in 10m 26s
⚠️ nova-operator-kuttl SKIPPED Skipped due to failed job nova-operator-content-provider
⚠️ nova-operator-tempest-multinode SKIPPED Skipped due to failed job nova-operator-content-provider

@zzzeek zzzeek marked this pull request as ready for review February 14, 2024 22:30
@openshift-ci openshift-ci bot requested review from lewisdenny and viroel February 14, 2024 22:30
@zzzeek zzzeek force-pushed the integrate_oo_accounts branch from 8534cd9 to 9f602d6 Compare February 15, 2024 17:26
Copy link

Merge Failed.

This change or one of its cross-repo dependencies was unable to be automatically merged with the current state of its repository. Please rebase the change and upload a new patchset.
Warning:
Error merging github.com/openstack-k8s-operators/openstack-operator for 656,def81966851fa35aea190d72515cefc590ef816d

@zzzeek
Copy link
Contributor Author

zzzeek commented Feb 15, 2024

/retest

@zzzeek zzzeek force-pushed the integrate_oo_accounts branch 2 times, most recently from 38cfe99 to ca814eb Compare February 15, 2024 20:24
Copy link

Build failed (check pipeline). Post recheck (without leading slash)
to rerun all jobs. Make sure the failure cause has been resolved before
you rerun jobs.

https://review.rdoproject.org/zuul/buildset/8f35d1ed9f4d445cbecc717f3653409d

✔️ nova-operator-content-provider SUCCESS in 2h 13m 13s
nova-operator-kuttl RETRY_LIMIT in 26m 25s
✔️ nova-operator-tempest-multinode SUCCESS in 1h 49m 41s

@zzzeek
Copy link
Contributor Author

zzzeek commented Feb 16, 2024

recheck

Copy link

Build failed (check pipeline). Post recheck (without leading slash)
to rerun all jobs. Make sure the failure cause has been resolved before
you rerun jobs.

https://review.rdoproject.org/zuul/buildset/f126069545674ca080e7faa6ffd1fbe1

✔️ nova-operator-content-provider SUCCESS in 2h 15m 47s
nova-operator-kuttl FAILURE in 41m 31s
✔️ nova-operator-tempest-multinode SUCCESS in 1h 53m 54s

@zzzeek zzzeek force-pushed the integrate_oo_accounts branch from ca814eb to 0a263f2 Compare February 19, 2024 20:49
@zzzeek zzzeek force-pushed the integrate_oo_accounts branch from 9637d30 to cc65abf Compare February 20, 2024 04:45
@zzzeek zzzeek changed the title migrate from databaseUsername to databaseAccount migrate from databaseUsername to databaseAccount and fully use MariaDBAccount Feb 20, 2024
Copy link
Contributor Author

@zzzeek zzzeek left a comment

Choose a reason for hiding this comment

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

this also needs GetDatabaseByName updated for the finalizer removal

@zzzeek zzzeek force-pushed the integrate_oo_accounts branch 4 times, most recently from a3bfc8c to 83a3645 Compare February 22, 2024 22:01
Copy link

Build failed (check pipeline). Post recheck (without leading slash)
to rerun all jobs. Make sure the failure cause has been resolved before
you rerun jobs.

https://review.rdoproject.org/zuul/buildset/2ed79e0ce148433fae3b0ac7d647ccb0

✔️ nova-operator-content-provider SUCCESS in 2h 06m 28s
nova-operator-kuttl FAILURE in 44m 26s
✔️ nova-operator-tempest-multinode SUCCESS in 1h 45m 39s

Copy link

Build failed (check pipeline). Post recheck (without leading slash)
to rerun all jobs. Make sure the failure cause has been resolved before
you rerun jobs.

https://review.rdoproject.org/zuul/buildset/ed6da443e61c4743b83a31492629a7d6

✔️ nova-operator-content-provider SUCCESS in 2h 09m 05s
nova-operator-kuttl FAILURE in 41m 50s
✔️ nova-operator-tempest-multinode SUCCESS in 1h 50m 40s

@zzzeek zzzeek force-pushed the integrate_oo_accounts branch from 245bd98 to 8c8b041 Compare March 4, 2024 23:31
Copy link
Contributor

@gibizer gibizer left a comment

Choose a reason for hiding this comment

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

I think all my comments can be fixed in a follow up. So let me know if you want to do that and I will approve this.

// cell.Spec.APIDatabaseHostname is empty for cells without APIDB access
"api_db_address": apiDBHostname,
"api_db_port": 3306,
"cell_db_name": getCellDatabaseName(cell.Spec.CellName),
"cell_db_user": cell.Spec.CellDatabaseUser,
"cell_db_password": string(ospSecret.Data[cellTemplate.PasswordSelectors.Database]),
Copy link
Contributor

Choose a reason for hiding this comment

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

now cellTemplate become unused so can be removed from the function params. Can be fixed n a followup

Comment on lines +725 to +734
apiDatabaseAccount, apiDbSecret, err := mariadbv1.GetAccountAndSecret(ctx, h, instance.Spec.APIDatabaseAccount, instance.Namespace)
if err != nil {
return nil, "", "", err
}

cellDatabaseAccount, cellDbSecret, err := mariadbv1.GetAccountAndSecret(ctx, h, cell.Spec.CellDatabaseAccount, instance.Namespace)
if err != nil {
return nil, "", "", err
}

Copy link
Contributor

Choose a reason for hiding this comment

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

we have the cellDB *mariadbv1.Database passed in and the caller could pass the apiDB similarly. So I think these queries are unnecessary, we could just access the accounts and secrets from the facades. Can be fixed in a followup

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes these should be calling from db.GetAccount() / db.GetSecret()

// yet associated with any MariaDBDatabase.
_, _, err := mariadbv1.EnsureMariaDBAccount(
ctx, h, cellTemplate.CellDatabaseAccount,
instance.Namespace, false, "nova_"+cellName,
Copy link
Contributor

Choose a reason for hiding this comment

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

we have a helper for that getCellDatabaseName


cellDB := mariadbv1.NewDatabaseForAccount(
cellTemplate.CellDatabaseInstance, // mariadb/galera service to target
"nova_"+cellName, // name used in CREATE DATABASE in mariadb
Copy link
Contributor

Choose a reason for hiding this comment

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

we have a helper for that getCellDatabaseName.

Comment on lines 931 to +932
cellSpec.APIDatabaseHostname = apiDB.GetDatabaseHostname()
cellSpec.APIDatabaseUser = instance.Spec.APIDatabaseUser
cellSpec.APIDatabaseAccount = instance.Spec.APIDatabaseAccount
Copy link
Contributor

Choose a reason for hiding this comment

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

OK we still use the hostname to signal if the api DB is accessible to the cell or not. Not super nice that we default the account in both case but that is not new, we did that with the APIDatabaseUser too. So I think it is good as is.

},
}

mariadbCellSuite.RunBasicSuite()
Copy link
Contributor

Choose a reason for hiding this comment

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

nice. Thanks for the generalized test cases

Comment on lines +36 to +57
BeforeEach(func() {
apiMariaDBAccount, apiMariaDBSecret := mariadb.CreateMariaDBAccountAndSecret(
novaNames.APIMariaDBDatabaseAccount, mariadbv1.MariaDBAccountSpec{})
DeferCleanup(k8sClient.Delete, ctx, apiMariaDBAccount)
DeferCleanup(k8sClient.Delete, ctx, apiMariaDBSecret)

cell0Account, cell0Secret := mariadb.CreateMariaDBAccountAndSecret(
cell0.MariaDBAccountName, mariadbv1.MariaDBAccountSpec{})
DeferCleanup(k8sClient.Delete, ctx, cell0Account)
DeferCleanup(k8sClient.Delete, ctx, cell0Secret)

cell1Account, cell1Secret := mariadb.CreateMariaDBAccountAndSecret(
cell1.MariaDBAccountName, mariadbv1.MariaDBAccountSpec{})
DeferCleanup(k8sClient.Delete, ctx, cell1Account)
DeferCleanup(k8sClient.Delete, ctx, cell1Secret)

cell2Account, cell2Secret := mariadb.CreateMariaDBAccountAndSecret(
cell2.MariaDBAccountName, mariadbv1.MariaDBAccountSpec{})
DeferCleanup(k8sClient.Delete, ctx, cell2Account)
DeferCleanup(k8sClient.Delete, ctx, cell2Secret)

})
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it intentional that we pre-create the accounts in these tests? As we create Nova CR and not some subCR in this tests we could let the nova controller's ensure call do the creation. Of course it is valid to pre-create them to simulate that it is done by the openstack-operator or the user.

If this is intentional then please leave a comment in the code nothing it as this is now different from the nova_controller_test.go and that might confuse the future reader

Copy link
Contributor Author

@zzzeek zzzeek Mar 5, 2024

Choose a reason for hiding this comment

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

if we move to openstack-operator being responsible for mariadbaccount creation then we'd be glad to have these here. I have a feeling that EnsureMariaDBAccount is going to be generating username/passwords for a long time though because it's very convenient that it takes care of itself.

given the discussion at openstack-k8s-operators/mariadb-operator#205 (review) I think I want to add Eventually() to the RunURLAssertSuites here before we merge and I can try removing some of these extraneous account creates. Between the many test suites here as well as all the changes made by @stuggi there are likely more mariadbaccoutn creates than needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

update: I am not using any RunURLAssertSuites. so we can merge this as is and address things in followup, given how much effort it is for me to keep rebasing this each time someone changes something.

@@ -50,22 +51,42 @@ func CreateNovaWith3CellsAndEnsureReady(novaNames NovaNames) {
DeferCleanup(mariadb.DeleteDBService, mariadb.CreateDBService(cell1.MariaDBDatabaseName.Namespace, cell1.MariaDBDatabaseName.Name, serviceSpec))
DeferCleanup(mariadb.DeleteDBService, mariadb.CreateDBService(cell2.MariaDBDatabaseName.Namespace, cell2.MariaDBDatabaseName.Name, serviceSpec))

apiMariaDBAccount, apiMariaDBSecret := mariadb.CreateMariaDBAccountAndSecret(
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto, we could let the nova controller create these. If this is intentional then please leave a comment

Copy link
Contributor

@gibizer gibizer left a comment

Choose a reason for hiding this comment

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

I deployed this and did a cell1 password rotation. Then I checked that the new user / pass was added to the cell mapping table automatically and I could deploy an instance to celll1 too.

the open comments can be fixed in a followup

Copy link
Contributor

openshift-ci bot commented Mar 5, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gibizer, zzzeek

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved label Mar 5, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit 90a97e1 into openstack-k8s-operators:main Mar 5, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants