From efc20842731eefc8ec8cc2a9a0ba4b1e659c46b2 Mon Sep 17 00:00:00 2001 From: Vladimir Nadvornik Date: Fri, 14 Jun 2024 10:17:28 +0200 Subject: [PATCH] Apply suggestions from code review --- mgradm/cmd/migrate/kubernetes/utils.go | 1 + mgradm/cmd/scale/podman.go | 2 +- mgradm/cmd/upgrade/kubernetes/utils.go | 2 +- mgradm/shared/kubernetes/install.go | 8 ++++---- mgradm/shared/kubernetes/k3s.go | 4 ++-- shared/kubernetes/utils.go | 6 +++--- uyuni-tools.changes.nadvornik.hub-xmlrpc2 | 2 +- 7 files changed, 13 insertions(+), 12 deletions(-) diff --git a/mgradm/cmd/migrate/kubernetes/utils.go b/mgradm/cmd/migrate/kubernetes/utils.go index 09a9a50fb..41de4fb1f 100644 --- a/mgradm/cmd/migrate/kubernetes/utils.go +++ b/mgradm/cmd/migrate/kubernetes/utils.go @@ -47,6 +47,7 @@ func migrateToKubernetes( hubXmlrpcImage := "" if flags.HubXmlrpc.Replicas > 0 { + log.Info().Msg(L("Enabling Hub XML-RPC API container.")) hubXmlrpcImage, err = utils.ComputeImage(globalFlags.Registry, flags.Image.Tag, flags.HubXmlrpc.Image) if err != nil { return err diff --git a/mgradm/cmd/scale/podman.go b/mgradm/cmd/scale/podman.go index 2e4e54aac..793410916 100644 --- a/mgradm/cmd/scale/podman.go +++ b/mgradm/cmd/scale/podman.go @@ -29,7 +29,7 @@ func podmanScale( } if service == podman.HubXmlrpcService { if newReplicas > 1 { - return errors.New(L("Multiple Hub XML-RPC container replicas are not currently supported.")) + return errors.New(L("Multiple Hub XML-RPC API container replicas are not currently supported.")) } return podman.ScaleService(newReplicas, service) } diff --git a/mgradm/cmd/upgrade/kubernetes/utils.go b/mgradm/cmd/upgrade/kubernetes/utils.go index be0d3d70e..090d6cd5a 100644 --- a/mgradm/cmd/upgrade/kubernetes/utils.go +++ b/mgradm/cmd/upgrade/kubernetes/utils.go @@ -18,5 +18,5 @@ func upgradeKubernetes( cmd *cobra.Command, args []string, ) error { - return kubernetes.Upgrade(globalFlags, &flags.Image, &flags.DbUpgradeImage, &flags.HubXmlrpc.Image, flags.Helm, cmd, args) + return kubernetes.Upgrade(globalFlags, &flags.Image, &flags.DbUpgradeImage, &flags.HubXmlrpc, flags.Helm, cmd, args) } diff --git a/mgradm/shared/kubernetes/install.go b/mgradm/shared/kubernetes/install.go index bd6e1706d..9e0e7f49c 100644 --- a/mgradm/shared/kubernetes/install.go +++ b/mgradm/shared/kubernetes/install.go @@ -41,7 +41,7 @@ func Deploy( isK3s := clusterInfos.IsK3s() IsRke2 := clusterInfos.IsRke2() if !prepare { - tcpPorts, udpPorts := CompilePortLists(hubXmlrpcFlags.Replicas > 0, debug) + tcpPorts, udpPorts := GetPortLists(hubXmlrpcFlags.Replicas > 0, debug) if isK3s { kubernetes.InstallK3sTraefikConfig(tcpPorts, udpPorts) } else if IsRke2 { @@ -129,7 +129,7 @@ func UyuniUpgrade(serverImage string, pullPolicy string, hubXmlrpcReplicas int, if hubXmlrpcReplicas > 0 { log.Info().Msg(L("Enabling Hub XMLRPC API container.")) helmParams = append(helmParams, - "--set", fmt.Sprintf("hubXmlrpcRepicas=%v", hubXmlrpcReplicas), + "--set", fmt.Sprintf("hub.api.replicas=%v", hubXmlrpcReplicas), "--set", "images.hub_xmlrpc="+hubXmlrpcImage) } helmParams = append(helmParams, helmArgs...) @@ -160,7 +160,7 @@ func Upgrade( origHubXmlrpcImage, err := kubernetes.GetRunningImage("hub-xmlrpc-api") if err != nil { - return utils.Errorf(err, L("failed to query Hub XML-RPC container")) + return utils.Errorf(err, L("failed to find Hub XML-RPC API container")) } serverImage, err := utils.ComputeImage(globalFlags.Registry, utils.DefaultTag, *image) @@ -238,7 +238,7 @@ func Upgrade( return utils.Errorf(err, L("cannot run post upgrade script")) } - hubXmlrpcImageName, err := ComputeHubXmlrpcImage(image, hubXmlrpcImage) + hubXmlrpcImageName, err := utils.ComputeImage(globalFlags.Registry, image.Tag, *hubXmlrpcImage) if err != nil { return utils.Errorf(err, L("failed to compute image URL")) } diff --git a/mgradm/shared/kubernetes/k3s.go b/mgradm/shared/kubernetes/k3s.go index ebba99055..27a539e6b 100644 --- a/mgradm/shared/kubernetes/k3s.go +++ b/mgradm/shared/kubernetes/k3s.go @@ -17,8 +17,8 @@ import ( "github.com/uyuni-project/uyuni-tools/shared/utils" ) -// CompilePortLists returns compiled lists of tcp and udp ports.. -func CompilePortLists(hub bool, debug bool) ([]types.PortMap, []types.PortMap) { +// GetPortLists returns compiled lists of tcp and udp ports.. +func GetPortLists(hub bool, debug bool) ([]types.PortMap, []types.PortMap) { tcpPorts := []types.PortMap{} tcpPorts = append(tcpPorts, utils.TCP_PORTS...) if debug { diff --git a/shared/kubernetes/utils.go b/shared/kubernetes/utils.go index be01a671e..dd0b495db 100644 --- a/shared/kubernetes/utils.go +++ b/shared/kubernetes/utils.go @@ -372,12 +372,12 @@ func GenerateOverrideDeployment(deployData types.Deployment) (string, error) { return string(ret), nil } -// GetRunningImage returns the image running in the current system. +// GetRunningImage returns the image of containerNAme for the server running in the current system. func GetRunningImage(containerName string) (string, error) { - args := []string{"get", "pods", ServerFilter, "-o", "jsonpath={.items[0].spec.containers[?(@.name=='" + containerName + "')].image}"} + args := []string{"get", "pods", "-A", ServerFilter, "-o", "jsonpath={.items[0].spec.containers[?(@.name=='" + containerName + "')].image}"} image, err := utils.RunCmdOutput(zerolog.DebugLevel, "kubectl", args...) - log.Info().Msgf(L("%[1]s image is: %[2]s"), containerName, image) + log.Debug().Msgf("%[1]s container image is: %[2]s", containerName, image) if err != nil { return "", err } diff --git a/uyuni-tools.changes.nadvornik.hub-xmlrpc2 b/uyuni-tools.changes.nadvornik.hub-xmlrpc2 index 974f003fe..7202a3c2c 100644 --- a/uyuni-tools.changes.nadvornik.hub-xmlrpc2 +++ b/uyuni-tools.changes.nadvornik.hub-xmlrpc2 @@ -1 +1 @@ -- Improved Hub XML-RPC support +- Handle Hub XML-RPC during migration and upgrade and add Kubernetes support