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 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions mgradm/cmd/install/podman/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
install_shared "github.com/uyuni-project/uyuni-tools/mgradm/cmd/install/shared"
"github.com/uyuni-project/uyuni-tools/mgradm/shared/coco"
"github.com/uyuni-project/uyuni-tools/mgradm/shared/hub"
"github.com/uyuni-project/uyuni-tools/mgradm/shared/pgsql"
"github.com/uyuni-project/uyuni-tools/mgradm/shared/podman"
"github.com/uyuni-project/uyuni-tools/shared"
. "github.com/uyuni-project/uyuni-tools/shared/l10n"
Expand Down Expand Up @@ -110,6 +111,18 @@ func installForPodman(
"CERT_PASS": caPassword,
}

if flags.ReportDB.Host == "" {
flags.ReportDB.Host = "uyuni-pgsql-server.mgr.internal"
}

if flags.DB.Host == "" {
flags.DB.Host = "uyuni-pgsql-server.mgr.internal"

if err := pgsql.SetupPgsql(systemd, authFile, flags.Pgsql, flags.DB.Admin.User, flags.DB.Admin.Password); err != nil {
return err
}
}

log.Info().Msg(L("Run setup command in the container"))

if err := install_shared.RunSetup(cnx, &flags.InstallFlags, fqdn, env); err != nil {
Expand All @@ -119,6 +132,11 @@ func installForPodman(
return err
}

log.Info().Msg(L("Enabling SSL in the postgres container"))
if err := pgsql.EnableSSL(systemd); err != nil {
return err
}

if path, err := exec.LookPath("uyuni-payg-extract-data"); err == nil {
// the binary is installed
err = utils.RunCmdStdMapping(zerolog.DebugLevel, path)
Expand Down
12 changes: 8 additions & 4 deletions mgradm/cmd/install/shared/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type InstallFlags struct {
Scc types.SCCCredentials
Debug DebugFlags
Image types.ImageFlags `mapstructure:",squash"`
Pgsql cmd_utils.PgsqlFlags
Coco cmd_utils.CocoFlags
HubXmlrpc cmd_utils.HubXmlrpcFlags
Admin apiTypes.User
Expand Down Expand Up @@ -100,6 +101,7 @@ func (flags *InstallFlags) CheckParameters(cmd *cobra.Command, command string) {
if flags.TZ == "" {
flags.TZ = utils.GetLocalTimezone()
}
utils.AskPasswordIfMissing(&flags.DB.Admin.Password, cmd.Flag("db-admin-password").Usage, 5, 48)

utils.AskIfMissing(&flags.Email, cmd.Flag("email").Usage, 1, 128, emailChecker)
utils.AskIfMissing(&flags.EmailFrom, cmd.Flag("emailfrom").Usage, 0, 0, emailChecker)
Expand Down Expand Up @@ -129,11 +131,11 @@ func AddInstallFlags(cmd *cobra.Command) {
cmd.Flags().String("db-user", "spacewalk", L("Database user"))
cmd.Flags().String("db-password", "", L("Database password. Randomly generated by default"))
cmd.Flags().String("db-name", "susemanager", L("Database name"))
cmd.Flags().String("db-host", "localhost", L("Database host"))
cmd.Flags().String("db-host", "", L("Database host"))
cmd.Flags().Int("db-port", 5432, L("Database port"))
cmd.Flags().String("db-protocol", "tcp", L("Database protocol"))
cmd.Flags().String("db-admin-user", "", L("External database admin user name"))
cmd.Flags().String("db-admin-password", "", L("External database admin password"))
cmd.Flags().String("db-admin-user", "postgres", L("Database admin user name"))
cmd.Flags().String("db-admin-password", "", L("Database admin password"))
cmd.Flags().String("db-provider", "", L("External database provider. Possible values 'aws'"))

_ = utils.AddFlagHelpGroup(cmd, &utils.Group{ID: "db", Title: L("Database Flags")})
Expand All @@ -149,7 +151,7 @@ func AddInstallFlags(cmd *cobra.Command) {

cmd.Flags().Bool("tftp", true, L("Enable TFTP"))
cmd.Flags().String("reportdb-name", "reportdb", L("Report database name"))
cmd.Flags().String("reportdb-host", "localhost", L("Report database host"))
cmd.Flags().String("reportdb-host", "", L("Report database host"))
cmd.Flags().Int("reportdb-port", 5432, L("Report database port"))
cmd.Flags().String("reportdb-user", "pythia_susemanager", L("Report Database username"))
cmd.Flags().String("reportdb-password", "", L("Report database password. Randomly generated by default"))
Expand Down Expand Up @@ -200,6 +202,8 @@ func AddInstallFlags(cmd *cobra.Command) {

cmd_utils.AddHubXmlrpcFlags(cmd)

cmd_utils.AddPgsqlFlags(cmd)

cmd.Flags().String("admin-login", "admin", L("Administrator user name"))
cmd.Flags().String("admin-password", "", L("Administrator password"))
cmd.Flags().String("admin-firstName", "Administrator", L("First name of the administrator"))
Expand Down
2 changes: 1 addition & 1 deletion mgradm/cmd/migrate/kubernetes/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func migrateToKubernetes(
sshConfigPath, sshKnownhostsPath := migration_shared.GetSSHPaths()

// Prepare the migration script and folder
scriptDir, cleaner, err := adm_utils.GenerateMigrationScript(fqdn, flags.User, true, flags.Prepare)
scriptDir, cleaner, err := adm_utils.GenerateMigrationScript(fqdn, flags.User, true, flags.Prepare, "fixme", "fixme")
if err != nil {
return utils.Errorf(err, L("failed to generate migration script"))
}
Expand Down
11 changes: 11 additions & 0 deletions mgradm/cmd/migrate/podman/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
migration_shared "github.com/uyuni-project/uyuni-tools/mgradm/cmd/migrate/shared"
"github.com/uyuni-project/uyuni-tools/mgradm/shared/coco"
"github.com/uyuni-project/uyuni-tools/mgradm/shared/hub"
"github.com/uyuni-project/uyuni-tools/mgradm/shared/pgsql"
"github.com/uyuni-project/uyuni-tools/mgradm/shared/podman"
"github.com/uyuni-project/uyuni-tools/shared"
podman_utils "github.com/uyuni-project/uyuni-tools/shared/podman"
Expand Down Expand Up @@ -86,6 +87,16 @@ func migrateToPodman(
}
}

if err := podman_utils.SetupNetwork(false); err != nil {
return err
}

if err := pgsql.Upgrade(
systemd, authFile, flags.Pgsql,
); err != nil {
return err
}

schemaUpdateRequired := oldPgVersion != newPgVersion
if err := podman.RunPgsqlFinalizeScript(preparedImage, schemaUpdateRequired, true); err != nil {
return utils.Errorf(err, L("cannot run PostgreSQL finalize script"))
Expand Down
2 changes: 2 additions & 0 deletions mgradm/cmd/migrate/shared/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type MigrateFlags struct {
Prepare bool
Image types.ImageFlags `mapstructure:",squash"`
DBUpgradeImage types.ImageFlags `mapstructure:"dbupgrade"`
Pgsql utils.PgsqlFlags
Coco utils.CocoFlags
User string
Mirror string
Expand All @@ -30,6 +31,7 @@ func AddMigrateFlags(cmd *cobra.Command) {
utils.AddSCCFlag(cmd)
utils.AddImageFlag(cmd)
utils.AddDBUpgradeImageFlag(cmd)
utils.AddUpgradePgsqlFlags(cmd)
utils.AddUpgradeCocoFlag(cmd)
utils.AddUpgradeHubXmlrpcFlags(cmd)
cmd.Flags().String("user", "root",
Expand Down
3 changes: 2 additions & 1 deletion mgradm/cmd/support/ptf/podman/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func ptfForPodman(
dummyImage := types.ImageFlags{}
dummyCoco := adm_utils.CocoFlags{}
dummyHubXmlrpc := adm_utils.HubXmlrpcFlags{}
dummyPgsql := adm_utils.PgsqlFlags{}
if err := flags.checkParameters(); err != nil {
return err
}
Expand All @@ -46,7 +47,7 @@ func ptfForPodman(
}
defer cleaner()

return podman.Upgrade(systemd, authFile, "", flags.Image, dummyImage, dummyCoco, dummyHubXmlrpc)
return podman.Upgrade(systemd, authFile, "", flags.Image, dummyImage, dummyCoco, dummyHubXmlrpc, dummyPgsql)
}

func (flags *podmanPTFFlags) checkParameters() error {
Expand Down
5 changes: 5 additions & 0 deletions mgradm/cmd/uninstall/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func uninstallForPodman(
podman.GetServiceImage(podman.ServerService),
podman.GetServiceImage(podman.ServerAttestationService + "@"),
podman.GetServiceImage(podman.HubXmlrpcService),
podman.GetServiceImage(podman.PgsqlService),
}

// Uninstall the service
Expand All @@ -35,6 +36,7 @@ func uninstallForPodman(

systemd.UninstallInstantiatedService(podman.ServerAttestationService, !flags.Force)
systemd.UninstallInstantiatedService(podman.HubXmlrpcService, !flags.Force)
systemd.UninstallInstantiatedService(podman.PgsqlService, !flags.Force)

// Remove the volumes
if flags.Purge.Volumes {
Expand All @@ -43,6 +45,9 @@ func uninstallForPodman(
for _, volume := range utils.ServerVolumeMounts {
volumes = append(volumes, volume.Name)
}
for _, volume := range utils.PgsqlRequiredVolumeMounts {
volumes = append(volumes, volume.Name)
}
for _, volume := range volumes {
if err := podman.DeleteVolume(volume, !flags.Force); err != nil {
log.Warn().Err(err).Msgf(L("Failed to remove volume %s"), volume)
Expand Down
2 changes: 1 addition & 1 deletion mgradm/cmd/upgrade/podman/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ func upgradePodman(globalFlags *types.GlobalFlags, flags *podmanUpgradeFlags, cm
defer cleaner()

return podman.Upgrade(
systemd, authFile, flags.Image.Registry, flags.Image, flags.DBUpgradeImage, flags.Coco, flags.HubXmlrpc,
systemd, authFile, flags.Image.Registry, flags.Image, flags.DBUpgradeImage, flags.Coco, flags.HubXmlrpc, flags.Pgsql,
)
}
2 changes: 2 additions & 0 deletions mgradm/cmd/upgrade/shared/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type UpgradeFlags struct {
DBUpgradeImage types.ImageFlags `mapstructure:"dbupgrade"`
Coco utils.CocoFlags
HubXmlrpc utils.HubXmlrpcFlags
Pgsql utils.PgsqlFlags
}

// AddUpgradeFlags add upgrade flags to a command.
Expand All @@ -26,6 +27,7 @@ func AddUpgradeFlags(cmd *cobra.Command) {

utils.AddUpgradeCocoFlag(cmd)
utils.AddUpgradeHubXmlrpcFlags(cmd)
utils.AddUpgradePgsqlFlags(cmd)
}

// AddUpgradeListFlags add upgrade list flags to a command.
Expand Down
2 changes: 1 addition & 1 deletion mgradm/shared/kubernetes/k3s.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func RunPgsqlFinalizeScript(
defer cleaner()
pgsqlFinalizeContainer := "uyuni-finalize-pgsql"
pgsqlFinalizeScriptName, err := adm_utils.GenerateFinalizePostgresScript(
scriptDir, true, schemaUpdateRequired, true, migration, true,
scriptDir, true, schemaUpdateRequired, migration, true,
)
if err != nil {
return utils.Errorf(err, L("cannot generate PostgreSQL finalization script"))
Expand Down
Loading