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

Dedicated container for database #482

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

nadvornik
Copy link
Contributor

@nadvornik nadvornik commented Oct 30, 2024

What does this PR change?

Current state:

Works with the image from uyuni-project/uyuni#9469
mgradm install podman --pgsql-image <image> --pgsql-tag <tag>
Uses workarounds for the issues discussed in https://github.com/SUSE/spacewalk/issues/25363
Missing kubernetes.

Test coverage

  • No tests: add explanation

  • No tests: already covered

  • Unit tests were added

  • DONE

Links

Issue(s): #

  • DONE

Changelogs

Make sure the changelogs entries you are adding are compliant with https://github.com/uyuni-project/uyuni/wiki/Contributing#changelogs and https://github.com/uyuni-project/uyuni/wiki/Contributing#uyuni-projectuyuni-repository

If you don't need a changelog check, please mark this checkbox:

  • No changelog needed

If you uncheck the checkbox after the PR is created, you will need to re-run changelog_test (see below)

Before you merge

Check How to branch and merge properly!

Copy link
Contributor

@aaannz aaannz left a comment

Choose a reason for hiding this comment

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

Couple comments, mostly typos.

Once this is merged, smdba autotune call can be also removed from mgr-setup and others.

) error {
image := pgsqlFlags.Image
currentReplicas := systemd.CurrentReplicaCount(podman.PgsqlService)
log.Debug().Msgf("Current HUB replicas running are %d.", currentReplicas)
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
log.Debug().Msgf("Current HUB replicas running are %d.", currentReplicas)
log.Debug().Msgf("Current pgsql replicas running are %d.", currentReplicas)

log.Debug().Msgf("Current HUB replicas running are %d.", currentReplicas)

if pgsqlFlags.Replicas == 0 {
log.Debug().Msg("No pgsql requested.")
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
log.Debug().Msg("No pgsql requested.")
log.Info().Msg(L("No Postgres container requested."))

log.Debug().Msg("No pgsql requested.")
}
if !pgsqlFlags.IsChanged {
log.Info().Msgf(L("No changes requested for hub. Keep %d replicas."), currentReplicas)
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
log.Info().Msgf(L("No changes requested for hub. Keep %d replicas."), currentReplicas)
log.Info().Msgf(L("No changes requested for pgsql. Keep %d replicas."), currentReplicas)

if err := cnx.WaitForHealthcheck(); err != nil {
return err
}
// Now the servisce is up and ready, the admin credentials are no longer needed
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
// Now the servisce is up and ready, the admin credentials are no longer needed
// Now the service is up and ready, the admin credentials are no longer needed

@@ -0,0 +1,191 @@
// SPDX-FileCopyrightText: 2024 SUSE LLC
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
// SPDX-FileCopyrightText: 2024 SUSE LLC
// SPDX-FileCopyrightText: 2025 SUSE LLC

OLD_VERSION={{ .OldVersion }}
NEW_VERSION={{ .NewVersion }}
FAST_UPGRADE=--link
FAST_UPGRADE= #--link
Copy link
Contributor

Choose a reason for hiding this comment

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

Not needed anymore

@@ -209,3 +209,21 @@ Leave it unset if you want to keep the previous number of replicas.
_ = utils.AddFlagToHelpGroupID(cmd, "saline-replicas", "saline-container")
_ = utils.AddFlagToHelpGroupID(cmd, "saline-port", "saline-container")
}

// AddPgsqlFlags adds hub XML-RPC related parameters to cmd.
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
// AddPgsqlFlags adds hub XML-RPC related parameters to cmd.
// AddPgsqlFlags adds postgres related parameters to cmd.

_ = utils.AddFlagToHelpGroupID(cmd, "pgsql-replicas", "pgsql-container")
}

// AddUpgradePgsqlFlags adds hub XML-RPC related parameters to cmd upgrade.
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
// AddUpgradePgsqlFlags adds hub XML-RPC related parameters to cmd upgrade.
// AddUpgradePgsqlFlags adds postgres related parameters to cmd upgrade.

Copy link
Member

@rjmateus rjmateus left a comment

Choose a reason for hiding this comment

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

overall looks good, just a few questions on this

mgradm/cmd/install/podman/podman_test.go Show resolved Hide resolved
if err := EnablePgsql(systemd, 0); err != nil {
return err
}
if err := EnablePgsql(systemd, pgsqlFlags.Replicas); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

Could you explain why first enable with 0 replicas and then with the correct number of replicas?

// This function is meant for installation or migration, to enable or disable the service after, use ScaleService.
func EnablePgsql(systemd podman.Systemd, replicas int) error {
if replicas > 1 {
log.Warn().Msg(L("Multiple Hub XML-RPC container replicas are not currently supported, setting up only one."))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
log.Warn().Msg(L("Multiple Hub XML-RPC container replicas are not currently supported, setting up only one."))
log.Warn().Msg(L("Multiple Pgsql container replicas are not supported, setting up only one."))

if err != nil {
return err
}
err = podman.RunContainer("uyuni-db-migrate", pgsqlImage, utils.PgsqlRequiredVolumeMounts, []string{},
Copy link
Member

Choose a reason for hiding this comment

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

The updade command also deals with major version upgrade? I think that at version 5.0 Michele prepared the upgrade process with the upgrade container to allow major upgrades where the database version would. Is this taken into consideration?

Image: image,
}
if err := utils.WriteTemplateToFile(
pgsqlData, podman.GetServicePath(podman.PgsqlService+"@"), 0555, true,
Copy link
Member

Choose a reason for hiding this comment

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

It uses the replica mechanism with 0 or 1. In this case would make sense to have it or should we keep more simple and generate or not the systems configuration. We can allow remote database in the future, but as for first version on 5.1 it would be possible.
Also, in the future when we support remote database and user wants to migrate to there, it would be a documented manual step, since it would have a lot involved.

user,
false,
prepare,
"uyuni-pgsql-server.mgr.internal",
Copy link
Member

Choose a reason for hiding this comment

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

In future we may allow to use external database. for now it should work, But I saw somewhere in the code that users can specify the dbhostname. We should limit that or adapt this part of the code. At this stage we can have it flexible, but users should not be allowed to define an external database fqdn.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't agree: this was already allowed for Amazon databases in 4.3 and we have to keep at least this around. Preventing users from setting an external DB FQDN would be a regression... Also remember that the product supported by SUSE is not the only one around: why preventing Uyuni users to use this?


{{ if .RunAutotune }}
echo "Running smdba system-check autotuning..."
smdba system-check autotuning
Copy link
Member

Choose a reason for hiding this comment

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

will we stop running the autotuning on install and upgrade? We would need a new mechanism or notify the user.

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 is in the postgres container uyuni-project/uyuni#9469

var PgsqlFlagsTestArgs = []string{
"--pgsql-image", "pgsqlimg",
"--pgsql-tag", "pgsqltag",
"--pgsql-replicas", "0",
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if we want to expose the replicas in here and at this stage. We may use internally, but for now users should always use pgsql container active. When we have the external database support we may add a parameter that make it clear, like --external-db which ideally would not deploy the database container (with external database have a service to start the containerized DB can be confusing)

// VarPgsqlVolumeMount defines the /var/lib/pgsql volume mount.
var VarPgsqlVolumeMount = types.VolumeMount{MountPath: "/var/lib/pgsql", Name: "var-pgsql", Size: "50Gi"}
// VarPgsqlDataVolumeMount defines the /var/lib/pgsql/data volume mount.
var VarPgsqlDataVolumeMount = types.VolumeMount{MountPath: "/var/lib/pgsql/data", Name: "var-pgsql", Size: "50Gi"}
Copy link
Member

Choose a reason for hiding this comment

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

Will this version work in the migration from 5.0 to 5.1, since the mounting point will be different?

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 is detected in inspect and eventually fixed in pgsqlMigrationScriptTemplate

Copy link

sonarqubecloud bot commented Jan 31, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
4 New issues
8.2% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

environment += fmt.Sprintf("Environment=POSTGRES_USER=\"%s\"\n", admin)
}
if password != "" {
environment += fmt.Sprintf("Environment=POSTGRES_PASSWORD=\"%s\"\n", password)
Copy link
Contributor

Choose a reason for hiding this comment

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

We cannot use passwords as environment with systemd. We'll need to use a podman secret here

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.

4 participants