From b5b6426809f0736390eeba726a0231ba2cc34f38 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/shared/kubernetes/install.go | 8 ++++---- mgradm/shared/kubernetes/k3s.go | 4 ++-- mgradm/shared/podman/podman.go | 2 +- shared/kubernetes/utils.go | 4 ++-- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/mgradm/cmd/migrate/kubernetes/utils.go b/mgradm/cmd/migrate/kubernetes/utils.go index 59332885e..17e10f4c7 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 = kubernetes.ComputeHubXmlrpcImage(&flags.Image, &flags.HubXmlrpc.Image) if err != nil { return utils.Errorf(err, L("failed to compute image URL")) 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/shared/kubernetes/install.go b/mgradm/shared/kubernetes/install.go index ada0192f6..60be00b8d 100644 --- a/mgradm/shared/kubernetes/install.go +++ b/mgradm/shared/kubernetes/install.go @@ -25,7 +25,6 @@ const HELM_APP_NAME = "uyuni" // Compute Hub Xmlrpc image. func ComputeHubXmlrpcImage(imageFlags *types.ImageFlags, hubXmlrpcFlags *types.ImageFlags) (string, error) { - log.Info().Msg(L("Enabling Hub XML-RPC API container.")) tag := hubXmlrpcFlags.Tag if tag == "" { tag = imageFlags.Tag @@ -45,7 +44,7 @@ func Deploy(cnx *shared.Connection, imageFlags *types.ImageFlags, // If installing on k3s, install the traefik helm config in manifests isK3s := clusterInfos.IsK3s() IsRke2 := clusterInfos.IsRke2() - tcpPorts, udpPorts := CompilePortLists(hubXmlrpcFlags.Replicas > 0, debug) + tcpPorts, udpPorts := GetPortLists(hubXmlrpcFlags.Replicas > 0, debug) if isK3s { kubernetes.InstallK3sTraefikConfig(tcpPorts, udpPorts) } else if IsRke2 { @@ -59,6 +58,7 @@ func Deploy(cnx *shared.Connection, imageFlags *types.ImageFlags, hubXmlrpcImage := "" if hubXmlrpcFlags.Replicas > 0 { + log.Info().Msg(L("Enabling Hub XML-RPC API container.")) hubXmlrpcImage, err = ComputeHubXmlrpcImage(imageFlags, &hubXmlrpcFlags.Image) if err != nil { return utils.Errorf(err, L("failed to compute image URL")) @@ -131,7 +131,7 @@ func UyuniUpgrade(serverImage string, pullPolicy string, hubXmlrpcReplicas int, "--set", "images.server="+serverImage, "--set", "pullPolicy="+kubernetes.GetPullPolicy(pullPolicy), "--set", "fqdn="+fqdn, - "--set", fmt.Sprintf("hubXmlrpcReplicas=%v", hubXmlrpcReplicas), + "--set", fmt.Sprintf("hub.api.replicas=%v", hubXmlrpcReplicas), "--set", "images.hub_xmlrpc="+hubXmlrpcImage) helmParams = append(helmParams, helmArgs...) @@ -161,7 +161,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(*image) diff --git a/mgradm/shared/kubernetes/k3s.go b/mgradm/shared/kubernetes/k3s.go index 300f67649..aab6aa098 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/mgradm/shared/podman/podman.go b/mgradm/shared/podman/podman.go index d761c42ee..87e713ec1 100644 --- a/mgradm/shared/podman/podman.go +++ b/mgradm/shared/podman/podman.go @@ -498,7 +498,7 @@ func CallCloudGuestRegistryAuth() error { func SetupHubXmlrpcContainer(flags *types.HubXmlrpcFlags, defaultTag string) error { if flags.Replicas > 0 { if flags.Replicas > 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.")) } log.Info().Msg(L("Enabling Hub XML-RPC API container.")) if flags.Image.Tag == "" { diff --git a/shared/kubernetes/utils.go b/shared/kubernetes/utils.go index 4289e8a54..b23a43ea1 100644 --- a/shared/kubernetes/utils.go +++ b/shared/kubernetes/utils.go @@ -376,10 +376,10 @@ func GenerateOverrideDeployment(deployData types.Deployment) (string, error) { // GetRunningImage returns the image 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 }