Skip to content

Commit

Permalink
Add saline container
Browse files Browse the repository at this point in the history
  • Loading branch information
vzhestkov committed Nov 25, 2024
1 parent e83438e commit cec9420
Show file tree
Hide file tree
Showing 30 changed files with 347 additions and 3 deletions.
1 change: 1 addition & 0 deletions mgradm/cmd/install/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ NOTE: installing on a remote cluster is not supported yet!
flagsUpdater := func(v *viper.Viper) {
flags.InstallFlags.Coco.IsChanged = v.IsSet("coco.replicas")
flags.InstallFlags.HubXmlrpc.IsChanged = v.IsSet("hubxmlrpc.replicas")
flags.InstallFlags.Saline.IsChanged = v.IsSet("saline.replicas") || v.IsSet("saline.port")
}
return utils.CommandHelper(globalFlags, cmd, args, &flags, flagsUpdater, run)
},
Expand Down
1 change: 1 addition & 0 deletions mgradm/cmd/install/podman/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ NOTE: installing on a remote podman is not supported yet!
flagsUpdater := func(v *viper.Viper) {
flags.InstallFlags.Coco.IsChanged = v.IsSet("coco.replicas")
flags.InstallFlags.HubXmlrpc.IsChanged = v.IsSet("hubxmlrpc.replicas")
flags.InstallFlags.Saline.IsChanged = v.IsSet("saline.replicas") || v.IsSet("saline.port")
}
return utils.CommandHelper(globalFlags, cmd, args, &flags, flagsUpdater, run)
},
Expand Down
11 changes: 10 additions & 1 deletion mgradm/cmd/install/podman/podman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ func TestParamsChangedConfig(t *testing.T) {
coco:
replicas: 2
hubxmlrpc:
replicas: 0`
replicas: 0
saline:
port: 8226
replicas: 1`

dir := t.TempDir()
configPath := path.Join(dir, "config.yaml")
Expand All @@ -59,6 +62,9 @@ hubxmlrpc:
testutils.AssertTrue(t, "Coco replicas not marked as changed", flags.Coco.IsChanged)
testutils.AssertEquals(t, "Hub XML-RPC API replicas badly parsed", 0, flags.HubXmlrpc.Replicas)
testutils.AssertTrue(t, "Hub XML-RPC API replicas not marked as changed", flags.HubXmlrpc.IsChanged)
testutils.AssertEquals(t, "Saline replicas badly parsed", 1, flags.Saline.Replicas)
testutils.AssertEquals(t, "Saline port badly parsed", 8226, flags.Saline.Port)
testutils.AssertTrue(t, "Saline flags not marked as changed", flags.Saline.IsChanged)
return nil
}

Expand All @@ -79,6 +85,9 @@ func TestParamsNoConfig(t *testing.T) {
testutils.AssertTrue(t, "Coco replicas marked as changed", !flags.Coco.IsChanged)
testutils.AssertEquals(t, "Hub XML-RPC API replicas badly parsed", 0, flags.HubXmlrpc.Replicas)
testutils.AssertTrue(t, "Hub XML-RPC API replicas marked as changed", !flags.HubXmlrpc.IsChanged)
testutils.AssertEquals(t, "Saline replicas badly parsed", 0, flags.Saline.Replicas)
testutils.AssertEquals(t, "Saline port badly parsed", 8216, flags.Saline.Port)
testutils.AssertTrue(t, "Saline flags marked as changed", !flags.Saline.IsChanged)
return nil
}

Expand Down
10 changes: 10 additions & 0 deletions mgradm/cmd/install/podman/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/spf13/viper"
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/podman"
"github.com/uyuni-project/uyuni-tools/mgradm/shared/saline"
"github.com/uyuni-project/uyuni-tools/shared"
. "github.com/uyuni-project/uyuni-tools/shared/l10n"
shared_podman "github.com/uyuni-project/uyuni-tools/shared/podman"
Expand Down Expand Up @@ -148,6 +150,14 @@ func installForPodman(
}
}

if flags.Saline.Replicas > 0 {
if err := saline.SetupSalineContainer(
systemd, authFile, flags.Image.Registry, flags.Saline, flags.Image, flags.TZ, viper.GetStringSlice("podman.arg"),
); err != nil {
return err
}
}

if flags.SSL.UseExisting() {
if err := podman.UpdateSSLCertificate(cnx, &flags.SSL.Ca, &flags.SSL.Server); err != nil {
return utils.Errorf(err, L("cannot update SSL certificate"))
Expand Down
3 changes: 3 additions & 0 deletions mgradm/cmd/install/shared/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type InstallFlags struct {
Image types.ImageFlags `mapstructure:",squash"`
Coco cmd_utils.CocoFlags
HubXmlrpc cmd_utils.HubXmlrpcFlags
Saline cmd_utils.SalineFlags
Admin apiTypes.User
Organization string
}
Expand Down Expand Up @@ -188,6 +189,8 @@ func AddInstallFlags(cmd *cobra.Command) {

cmd_utils.AddHubXmlrpcFlags(cmd)

cmd_utils.AddSalineFlag(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
1 change: 1 addition & 0 deletions mgradm/cmd/migrate/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ NOTE: migrating to a remote cluster is not supported yet!
flagsUpdater := func(v *viper.Viper) {
flags.MigrateFlags.Coco.IsChanged = v.IsSet("coco.replicas")
flags.MigrateFlags.HubXmlrpc.IsChanged = v.IsSet("hubxmlrpc.replicas")
flags.MigrateFlags.Saline.IsChanged = v.IsSet("saline.replicas") || v.IsSet("saline.port")
}
return utils.CommandHelper(globalFlags, cmd, args, &flags, flagsUpdater, run)
},
Expand Down
2 changes: 2 additions & 0 deletions mgradm/cmd/migrate/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func TestParamsParsing(t *testing.T) {
args = append(args, flagstests.DBUpdateImageFlagTestArgs...)
args = append(args, flagstests.CocoFlagsTestArgs...)
args = append(args, flagstests.HubXmlrpcFlagsTestArgs...)
args = append(args, flagstests.SalineFlagsTestArgs...)
args = append(args, flagstests.ServerHelmFlagsTestArgs...)

// Test function asserting that the args are properly parsed
Expand All @@ -42,6 +43,7 @@ func TestParamsParsing(t *testing.T) {
flagstests.AssertDBUpgradeImageFlag(t, &flags.DBUpgradeImage)
flagstests.AssertCocoFlag(t, &flags.Coco)
flagstests.AssertHubXmlrpcFlag(t, &flags.HubXmlrpc)
flagstests.AssertSalineFlag(t, &flags.Saline)
testutils.AssertEquals(t, "Error parsing --user", "sudoer", flags.User)
flagstests.AssertServerHelmFlags(t, &flags.Helm)
testutils.AssertEquals(t, "Error parsing --ssl-password", "sslsecret", flags.SSL.Password)
Expand Down
1 change: 1 addition & 0 deletions mgradm/cmd/migrate/podman/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ NOTE: migrating to a remote podman is not supported yet!
flagsUpdater := func(v *viper.Viper) {
flags.MigrateFlags.Coco.IsChanged = v.IsSet("coco.replicas")
flags.MigrateFlags.HubXmlrpc.IsChanged = v.IsSet("hubxmlrpc.replicas")
flags.MigrateFlags.Saline.IsChanged = v.IsSet("saline.replicas") || v.IsSet("saline.port")
}
return utils.CommandHelper(globalFlags, cmd, args, &flags, flagsUpdater, run)
},
Expand Down
2 changes: 2 additions & 0 deletions mgradm/cmd/migrate/podman/podman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func TestParamsParsing(t *testing.T) {
args = append(args, flagstests.DBUpdateImageFlagTestArgs...)
args = append(args, flagstests.CocoFlagsTestArgs...)
args = append(args, flagstests.HubXmlrpcFlagsTestArgs...)
args = append(args, flagstests.SalineFlagsTestArgs...)
args = append(args, flagstests.PodmanFlagsTestArgs...)

// Test function asserting that the args are properly parsed
Expand All @@ -37,6 +38,7 @@ func TestParamsParsing(t *testing.T) {
flagstests.AssertDBUpgradeImageFlag(t, &flags.DBUpgradeImage)
flagstests.AssertCocoFlag(t, &flags.Coco)
flagstests.AssertHubXmlrpcFlag(t, &flags.HubXmlrpc)
flagstests.AssertSalineFlag(t, &flags.Saline)
testutils.AssertEquals(t, "Error parsing --user", "sudoer", flags.User)
flagstests.AssertPodmanInstallFlags(t, &flags.Podman)
testutils.AssertEquals(t, "Wrong FQDN", "source.fq.dn", args[0])
Expand Down
16 changes: 16 additions & 0 deletions mgradm/cmd/migrate/podman/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"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/podman"
"github.com/uyuni-project/uyuni-tools/mgradm/shared/saline"
"github.com/uyuni-project/uyuni-tools/shared"
podman_utils "github.com/uyuni-project/uyuni-tools/shared/podman"
"github.com/uyuni-project/uyuni-tools/shared/types"
Expand Down Expand Up @@ -144,6 +145,21 @@ func migrateToPodman(
}
}

// Prepare Saline containers
if flags.Saline.Replicas > 0 {
if err = saline.Upgrade(
systemd, authFile, flags.Image.Registry, flags.Saline, flags.Image,
extractedData.Timezone, flags.Podman.Args,
); err != nil {
return utils.Errorf(err, L("cannot setup saline service"))
}

err := systemd.ScaleService(flags.Saline.Replicas, podman_utils.ServerSalineService)
if err != nil {
return err
}
}

log.Info().Msg(L("Server migrated"))

if err := podman_utils.EnablePodmanSocket(); err != nil {
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 @@ -21,6 +21,7 @@ type MigrateFlags struct {
Mirror string
HubXmlrpc utils.HubXmlrpcFlags
SCC types.SCCCredentials
Saline utils.SalineFlags
}

// AddMigrateFlags add migration flags to a command.
Expand All @@ -32,6 +33,7 @@ func AddMigrateFlags(cmd *cobra.Command) {
utils.AddDBUpgradeImageFlag(cmd)
utils.AddUpgradeCocoFlag(cmd)
utils.AddUpgradeHubXmlrpcFlags(cmd)
utils.AddUpgradeSalineFlag(cmd)
cmd.Flags().String("user", "root",
L("User on the source server. Non-root user must have passwordless sudo privileges (NOPASSWD tag in /etc/sudoers)."),
)
Expand Down
1 change: 1 addition & 0 deletions mgradm/cmd/support/ptf/podman/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type podmanPTFFlags struct {
SCC types.SCCCredentials
Coco adm_utils.CocoFlags
Hubxmlrpc adm_utils.HubXmlrpcFlags
Saline adm_utils.SalineFlags
}

func newCmd(globalFlags *types.GlobalFlags, run utils.CommandFunc[podmanPTFFlags]) *cobra.Command {
Expand Down
2 changes: 1 addition & 1 deletion mgradm/cmd/support/ptf/podman/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func ptfForPodman(
return err
}

return podman.Upgrade(systemd, authFile, "", flags.Image, dummyImage, flags.Coco, flags.Hubxmlrpc)
return podman.Upgrade(systemd, authFile, "", flags.Image, dummyImage, flags.Coco, flags.Hubxmlrpc, flags.Saline)
}

// variables for unit testing.
Expand Down
2 changes: 2 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.ServerSalineService + "@"),
}

// 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.ServerSalineService, !flags.Force)

// Remove the volumes
if flags.Purge.Volumes {
Expand Down
1 change: 1 addition & 0 deletions mgradm/cmd/upgrade/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func newCmd(globalFlags *types.GlobalFlags, run utils.CommandFunc[kubernetesUpgr
flagsUpdater := func(v *viper.Viper) {
flags.UpgradeFlags.Coco.IsChanged = v.IsSet("coco.replicas")
flags.UpgradeFlags.HubXmlrpc.IsChanged = v.IsSet("hubxmlrpc.replicas")
flags.UpgradeFlags.Saline.IsChanged = v.IsSet("saline.replicas") || v.IsSet("saline.port")
}
return utils.CommandHelper(globalFlags, cmd, args, &flags, flagsUpdater, run)
},
Expand Down
2 changes: 2 additions & 0 deletions mgradm/cmd/upgrade/kubernetes/kubernetes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func TestParamsParsing(t *testing.T) {
args = append(args, flagstests.DBUpdateImageFlagTestArgs...)
args = append(args, flagstests.CocoFlagsTestArgs...)
args = append(args, flagstests.HubXmlrpcFlagsTestArgs...)
args = append(args, flagstests.SalineFlagsTestArgs...)
args = append(args, flagstests.SCCFlagTestArgs...)
args = append(args, flagstests.ServerHelmFlagsTestArgs...)

Expand All @@ -33,6 +34,7 @@ func TestParamsParsing(t *testing.T) {
flagstests.AssertDBUpgradeImageFlag(t, &flags.DBUpgradeImage)
flagstests.AssertCocoFlag(t, &flags.Coco)
flagstests.AssertHubXmlrpcFlag(t, &flags.HubXmlrpc)
flagstests.AssertSalineFlag(t, &flags.Saline)
// TODO Assert SCC flags
flagstests.AssertServerHelmFlags(t, &flags.Helm)
return nil
Expand Down
1 change: 1 addition & 0 deletions mgradm/cmd/upgrade/podman/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func newCmd(globalFlags *types.GlobalFlags, run utils.CommandFunc[podmanUpgradeF
flagsUpdater := func(v *viper.Viper) {
flags.UpgradeFlags.Coco.IsChanged = v.IsSet("coco.replicas")
flags.UpgradeFlags.HubXmlrpc.IsChanged = v.IsSet("hubxmlrpc.replicas")
flags.UpgradeFlags.Saline.IsChanged = v.IsSet("saline.replicas") || v.IsSet("saline.port")
}
return utils.CommandHelper(globalFlags, cmd, args, &flags, flagsUpdater, run)
},
Expand Down
2 changes: 2 additions & 0 deletions mgradm/cmd/upgrade/podman/podman_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func TestParamsParsing(t *testing.T) {
args = append(args, flagstests.DBUpdateImageFlagTestArgs...)
args = append(args, flagstests.CocoFlagsTestArgs...)
args = append(args, flagstests.HubXmlrpcFlagsTestArgs...)
args = append(args, flagstests.SalineFlagsTestArgs...)
args = append(args, flagstests.SCCFlagTestArgs...)
args = append(args, flagstests.PodmanFlagsTestArgs...)

Expand All @@ -29,6 +30,7 @@ func TestParamsParsing(t *testing.T) {
flagstests.AssertDBUpgradeImageFlag(t, &flags.DBUpgradeImage)
flagstests.AssertCocoFlag(t, &flags.Coco)
flagstests.AssertHubXmlrpcFlag(t, &flags.HubXmlrpc)
flagstests.AssertSalineFlag(t, &flags.Saline)
flagstests.AssertSCCFlag(t, &flags.SCC)
flagstests.AssertPodmanInstallFlags(t, &flags.Podman)
return nil
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(_ *types.GlobalFlags, flags *podmanUpgradeFlags, _ *cobra.Com
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.Saline,
)
}
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
Saline utils.SalineFlags
}

// 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.AddUpgradeSalineFlag(cmd)
}

// AddUpgradeListFlags add upgrade list flags to a command.
Expand Down
9 changes: 9 additions & 0 deletions mgradm/shared/podman/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ import (

"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
"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/saline"
"github.com/uyuni-project/uyuni-tools/mgradm/shared/templates"
adm_utils "github.com/uyuni-project/uyuni-tools/mgradm/shared/utils"
"github.com/uyuni-project/uyuni-tools/shared"
Expand Down Expand Up @@ -363,6 +365,7 @@ func Upgrade(
upgradeImage types.ImageFlags,
cocoFlags adm_utils.CocoFlags,
hubXmlrpcFlags adm_utils.HubXmlrpcFlags,
salineFlags adm_utils.SalineFlags,
) error {
if err := CallCloudGuestRegistryAuth(); err != nil {
return err
Expand Down Expand Up @@ -455,6 +458,12 @@ func Upgrade(
return err
}

if err := saline.Upgrade(systemd, authFile, registry, salineFlags, image,
utils.GetLocalTimezone(), viper.GetStringSlice("podman.arg"),
); err != nil {
return utils.Errorf(err, L("error upgrading saline service."))
}

return systemd.ReloadDaemon(false)
}

Expand Down
Loading

0 comments on commit cec9420

Please sign in to comment.