Skip to content

Commit

Permalink
Move the RunSetup function to shared
Browse files Browse the repository at this point in the history
In order to share the same code for installation, migration and upgrade
the RunSetup() function needs to move to the shared utils module.
  • Loading branch information
cbosdo committed Oct 24, 2024
1 parent b963ef7 commit 9b3adf7
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions mgradm/cmd/install/kubernetes/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (

"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
install_shared "github.com/uyuni-project/uyuni-tools/mgradm/cmd/install/shared"
"github.com/uyuni-project/uyuni-tools/mgradm/shared/kubernetes"
adm_utils "github.com/uyuni-project/uyuni-tools/mgradm/shared/utils"
"github.com/uyuni-project/uyuni-tools/shared"
shared_kubernetes "github.com/uyuni-project/uyuni-tools/shared/kubernetes"
. "github.com/uyuni-project/uyuni-tools/shared/l10n"
Expand Down Expand Up @@ -151,7 +151,7 @@ func installForKubernetes(
// TODO Ideally we would need a job running at an earlier stage to persist the logs in a kubernetes-friendly way.
cnx := shared.NewConnection("kubectl", "", shared_kubernetes.ServerFilter)

if err := install_shared.RunSetup(
if err := adm_utils.RunSetup(
cnx, &flags.ServerFlags, fqdn, map[string]string{"NO_SSL": "Y"},
); err != nil {
if stopErr := shared_kubernetes.Stop(namespace, shared_kubernetes.ServerApp); stopErr != nil {
Expand Down
4 changes: 2 additions & 2 deletions mgradm/cmd/install/podman/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
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"
adm_utils "github.com/uyuni-project/uyuni-tools/mgradm/shared/utils"
"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 @@ -114,7 +114,7 @@ func installForPodman(

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

if err := install_shared.RunSetup(cnx, &flags.ServerFlags, fqdn, env); err != nil {
if err := adm_utils.RunSetup(cnx, &flags.ServerFlags, fqdn, env); err != nil {
if stopErr := systemd.StopService(shared_podman.ServerService); stopErr != nil {
log.Error().Msgf(L("Failed to stop service: %v"), stopErr)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// SPDX-License-Identifier: Apache-2.0

package shared
package utils

import (
"errors"
Expand All @@ -13,7 +13,6 @@ import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"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"
"github.com/uyuni-project/uyuni-tools/shared/api"
"github.com/uyuni-project/uyuni-tools/shared/api/org"
Expand All @@ -24,7 +23,7 @@ import (
const setupName = "setup.sh"

// RunSetup execute the setup.
func RunSetup(cnx *shared.Connection, flags *adm_utils.ServerFlags, fqdn string, env map[string]string) error {
func RunSetup(cnx *shared.Connection, flags *ServerFlags, fqdn string, env map[string]string) error {
// Containers should be running now, check storage if it is using volume from already configured server
preconfigured := false
if isServerConfigured(cnx) {
Expand All @@ -44,7 +43,7 @@ func RunSetup(cnx *shared.Connection, flags *adm_utils.ServerFlags, fqdn string,
return utils.Errorf(err, L("cannot copy /tmp/setup.sh"))
}

err = adm_utils.ExecCommand(zerolog.InfoLevel, cnx, "/tmp/setup.sh")
err = ExecCommand(zerolog.InfoLevel, cnx, "/tmp/setup.sh")
if err != nil && !preconfigured {
return utils.Errorf(err, L("error running the setup script"))
}
Expand Down Expand Up @@ -105,7 +104,7 @@ func RunSetup(cnx *shared.Connection, flags *adm_utils.ServerFlags, fqdn string,
// The script exports all the needed environment variables and calls uyuni's mgr-setup.
// Podman or kubernetes-specific variables can be passed using extraEnv parameter.
func generateSetupScript(
flags *adm_utils.InstallationFlags,
flags *InstallationFlags,
fqdn string,
mirror string,
extraEnv map[string]string,
Expand Down

0 comments on commit 9b3adf7

Please sign in to comment.