Skip to content

Commit

Permalink
Revert "Reverts to allow forward porting from 2024.10"
Browse files Browse the repository at this point in the history
This reverts commit 114f207.

Also fixes the build after the forward port.
  • Loading branch information
cbosdo committed Nov 19, 2024
1 parent a39327f commit f3edd7c
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 26 deletions.
9 changes: 6 additions & 3 deletions mgradm/cmd/install/podman/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package podman

import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/uyuni-project/uyuni-tools/mgradm/cmd/install/shared"
. "github.com/uyuni-project/uyuni-tools/shared/l10n"
"github.com/uyuni-project/uyuni-tools/shared/podman"
Expand All @@ -31,9 +32,11 @@ NOTE: installing on a remote podman is not supported yet!
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
var flags podmanInstallFlags
flags.Coco.IsChanged = cmd.Flags().Changed("coco-replicas")
flags.HubXmlrpc.IsChanged = cmd.Flags().Changed("hubxmlrpc-replicas")
return utils.CommandHelper(globalFlags, cmd, args, &flags, installForPodman)
flagsUpdater := func(v *viper.Viper) {
flags.InstallFlags.Coco.IsChanged = v.IsSet("coco.replicas")
flags.InstallFlags.HubXmlrpc.IsChanged = v.IsSet("hubxmlrpc.replicas")
}
return utils.CommandHelper(globalFlags, cmd, args, &flags, flagsUpdater, run)
},
}

Expand Down
6 changes: 3 additions & 3 deletions mgradm/cmd/install/podman/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ func installForPodman(

if flags.Coco.Replicas > 0 {
// This may need to be moved up later once more containers require DB access
if err := shared_podman.CreateDbSecrets(flags.Db.User, flags.Db.Password); err != nil {
if err := shared_podman.CreateDBSecrets(flags.DB.User, flags.DB.Password); err != nil {
return err
}
if err := coco.SetupCocoContainer(
authFile, flags.Image.Registry, flags.Coco, flags.Image,
flags.Db.Name, flags.Db.Port,
systemd, authFile, flags.Image.Registry, flags.Coco, flags.Image,
flags.DB.Name, flags.DB.Port,
); err != nil {
return err
}
Expand Down
10 changes: 6 additions & 4 deletions mgradm/cmd/uninstall/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,15 @@ func uninstallForPodman(

podman.DeleteNetwork(!flags.Force)

podman.DeleteSecret(podman.DbUserSecret, !flags.Force)
podman.DeleteSecret(podman.DbPassSecret, !flags.Force)
podman.DeleteSecret(podman.DBUserSecret, !flags.Force)
podman.DeleteSecret(podman.DBPassSecret, !flags.Force)

err := podman.ReloadDaemon(!flags.Force)
err := systemd.ReloadDaemon(!flags.Force)

if !flags.Force {
log.Warn().Msg(L("Nothing has been uninstalled, run with --force and --purge-volumes to actually uninstall and clear data"))
log.Warn().Msg(
L("Nothing has been uninstalled, run with --force and --purge-volumes to actually uninstall and clear data"),
)
} else if !flags.Purge.Volumes {
log.Warn().Msg(L("Data have been kept, use podman volume commands to clear the volumes"))
}
Expand Down
13 changes: 10 additions & 3 deletions mgradm/shared/coco/coco.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,18 @@ func Upgrade(
dbUser string,
dbPassword string,
) error {
if err := podman.CreateDbSecrets(dbUser, dbPassword); err != nil {
if cocoFlags.Image.Name == "" {
// Don't touch the coco service in ptf if not already present.
return nil
}

if err := podman.CreateDBSecrets(dbUser, dbPassword); err != nil {
return err
}

if err := writeCocoServiceFiles(authFile, registry, cocoFlags, baseImage, dbName, dbPort); err != nil {
if err := writeCocoServiceFiles(
systemd, authFile, registry, cocoFlags, baseImage, dbName, dbPort,
); err != nil {
return err
}

Expand Down Expand Up @@ -120,7 +127,7 @@ func SetupCocoContainer(
dbPort int,
) error {
if err := writeCocoServiceFiles(
authFile, registry, coco, baseImage, dbName, dbPort,
systemd, authFile, registry, coco, baseImage, dbName, dbPort,
); err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions mgradm/shared/podman/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package podman

import (
"errors"
"fmt"
"os/exec"
"path"
Expand Down
4 changes: 2 additions & 2 deletions mgradm/shared/templates/attestationServiceTemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ ExecStart=/bin/sh -c '/usr/bin/podman run \
--sdnotify=conmon \
-d \
-e database_connection \
--secret=` + podman.DbUserSecret + `,type=env,target=database_user \
--secret=` + podman.DbPassSecret + `,type=env,target=database_password \
--secret=` + podman.DBUserSecret + `,type=env,target=database_user \
--secret=` + podman.DBPassSecret + `,type=env,target=database_password \
--replace \
--name {{ .NamePrefix }}-server-attestation-%i \
--hostname {{ .NamePrefix }}-server-attestation-%i.mgr.internal \
Expand Down
22 changes: 11 additions & 11 deletions shared/podman/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ import (
)

const (
//DbUserSecret is the name of the podman secret containing the database username.
DbUserSecret = "uyuni-db-user"
//DbUserSecret is the name of the podman secret containing the database password.
DbPassSecret = "uyuni-db-pass"
//DBUserSecret is the name of the podman secret containing the database username.
DBUserSecret = "uyuni-db-user"
//DBUserSecret is the name of the podman secret containing the database password.
DBPassSecret = "uyuni-db-pass"
)

// CreateDbSecrets creates the podman secrets for the database credentials.
func CreateDbSecrets(user string, password string) error {
if err := createSecret(DbUserSecret, user); err != nil {
// CreateDBSecrets creates the podman secrets for the database credentials.
func CreateDBSecrets(user string, password string) error {
if err := createSecret(DBUserSecret, user); err != nil {
return err
}
return createSecret(DbPassSecret, password)
return createSecret(DBPassSecret, password)
}

// createSecret creates a podman secret.
Expand All @@ -35,14 +35,14 @@ func createSecret(name string, value string) error {
return nil
}

tmpDir, err := utils.TempDir()
tmpDir, cleaner, err := utils.TempDir()
if err != nil {
return err
}
defer os.RemoveAll(tmpDir)
defer cleaner()

secretFile := path.Join(tmpDir, "secret")
if err := os.WriteFile(secretFile, []byte(value), 600); err != nil {
if err := os.WriteFile(secretFile, []byte(value), 0600); err != nil {
return utils.Errorf(err, L("failed to write %s secret to file"), name)
}

Expand Down

0 comments on commit f3edd7c

Please sign in to comment.