Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
nadvornik committed Jun 14, 2024
1 parent 8dbb800 commit b5b6426
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions mgradm/cmd/migrate/kubernetes/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
2 changes: 1 addition & 1 deletion mgradm/cmd/scale/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions mgradm/shared/kubernetes/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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"))
Expand Down Expand Up @@ -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...)

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions mgradm/shared/kubernetes/k3s.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion mgradm/shared/podman/podman.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 == "" {
Expand Down
4 changes: 2 additions & 2 deletions shared/kubernetes/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit b5b6426

Please sign in to comment.