From 1cdbbad1d866becc118a4969bb29dd8564cb88f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Bosdonnat?= Date: Wed, 7 Aug 2024 12:06:44 +0200 Subject: [PATCH] Add deployments reason for helm history Migration deploys the helm chart multiple times. Identifying which revision corresponds to which step in helm history is hard without a description. --- mgradm/cmd/install/kubernetes/utils.go | 1 + mgradm/cmd/migrate/kubernetes/utils.go | 9 ++++++-- mgradm/shared/kubernetes/install.go | 30 +++++++++++++++++++++----- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/mgradm/cmd/install/kubernetes/utils.go b/mgradm/cmd/install/kubernetes/utils.go index 27a2c5856..15a94fd8a 100644 --- a/mgradm/cmd/install/kubernetes/utils.go +++ b/mgradm/cmd/install/kubernetes/utils.go @@ -70,6 +70,7 @@ func installForKubernetes(globalFlags *types.GlobalFlags, // Deploy Uyuni and wait for it to be up if err := kubernetes.Deploy( + L("Initial deployment from mgradm install"), cnx, globalFlags.Registry, &flags.Image, &flags.HubXmlrpc, &flags.Helm, &flags.Ssl, clusterInfos, fqdn, flags.Debug.Java, false, helmArgs..., ); err != nil { diff --git a/mgradm/cmd/migrate/kubernetes/utils.go b/mgradm/cmd/migrate/kubernetes/utils.go index ed1bf182a..3899b1e67 100644 --- a/mgradm/cmd/migrate/kubernetes/utils.go +++ b/mgradm/cmd/migrate/kubernetes/utils.go @@ -80,7 +80,9 @@ func migrateToKubernetes( var sslFlags adm_utils.SslCertFlags // Deploy for running migration command - if err := kubernetes.Deploy(cnx, globalFlags.Registry, &flags.Image, &flags.HubXmlrpc, + if err := kubernetes.Deploy( + fmt.Sprintf(L("Deploy to migrate the data from %s"), fqdn), + cnx, globalFlags.Registry, &flags.Image, &flags.HubXmlrpc, &flags.Helm, &sslFlags, clusterInfos, fqdn, false, flags.Prepare, "--set", "migration.ssh.agentSocket="+sshAuthSocket, "--set", "migration.ssh.configPath="+sshConfigPath, @@ -143,6 +145,7 @@ func migrateToKubernetes( // Run uyuni upgrade using the new ssl certificate // We don't need to start the Hub XML-RPC API containers during the setup phase err = kubernetes.UyuniUpgrade( + L("Upgrade with final volumes"), serverImage, flags.Image.PullPolicy, 0, hubXmlrpcImage, &flags.Helm, kubeconfig, fqdn, clusterInfos.Ingress, helmArgs..., ) @@ -187,7 +190,9 @@ func migrateToKubernetes( // This is the final deployment, all the replicas need to be correct here. err = kubernetes.UyuniUpgrade( - serverImage, flags.Image.PullPolicy, hubReplicas, hubXmlrpcImage, &flags.Helm, kubeconfig, fqdn, clusterInfos.Ingress, helmArgs..., + L("Complete deployment after migration"), + serverImage, flags.Image.PullPolicy, hubReplicas, hubXmlrpcImage, &flags.Helm, kubeconfig, fqdn, + clusterInfos.Ingress, helmArgs..., ) if err != nil { return utils.Errorf(err, L("cannot upgrade to image %s"), serverImage) diff --git a/mgradm/shared/kubernetes/install.go b/mgradm/shared/kubernetes/install.go index a8b561618..b1236c26d 100644 --- a/mgradm/shared/kubernetes/install.go +++ b/mgradm/shared/kubernetes/install.go @@ -25,6 +25,7 @@ const HELM_APP_NAME = "uyuni" // Deploy execute a deploy of a given image and helm to a cluster. func Deploy( + reason string, cnx *shared.Connection, registry string, imageFlags *types.ImageFlags, @@ -60,7 +61,10 @@ func Deploy( } // Install the uyuni server helm chart - err = UyuniUpgrade(serverImage, imageFlags.PullPolicy, hubXmlrpcFlags.Replicas, hubXmlrpcImage, helmFlags, clusterInfos.GetKubeconfig(), fqdn, clusterInfos.Ingress, helmArgs...) + err = UyuniUpgrade( + reason, serverImage, imageFlags.PullPolicy, hubXmlrpcFlags.Replicas, hubXmlrpcImage, + helmFlags, clusterInfos.GetKubeconfig(), fqdn, clusterInfos.Ingress, helmArgs..., + ) if err != nil { return utils.Errorf(err, L("cannot upgrade")) } @@ -106,8 +110,18 @@ func DeployExistingCertificate(helmFlags *cmd_utils.HelmFlags, sslFlags *cmd_uti } // UyuniUpgrade runs an helm upgrade using images and helm configuration as parameters. -func UyuniUpgrade(serverImage string, pullPolicy string, hubXmlrpcReplicas int, hubXmlrpcImage string, helmFlags *cmd_utils.HelmFlags, kubeconfig string, - fqdn string, ingress string, helmArgs ...string) error { +func UyuniUpgrade( + reason string, + serverImage string, + pullPolicy string, + hubXmlrpcReplicas int, + hubXmlrpcImage string, + helmFlags *cmd_utils.HelmFlags, + kubeconfig string, + fqdn string, + ingress string, + helmArgs ...string, +) error { log.Info().Msg(L("Installing Uyuni")) // The guessed ingress is passed before the user's value to let the user override it in case we got it wrong. @@ -124,7 +138,9 @@ func UyuniUpgrade(serverImage string, pullPolicy string, hubXmlrpcReplicas int, helmParams = append(helmParams, "--set", "images.server="+serverImage, "--set", "pullPolicy="+kubernetes.GetPullPolicy(pullPolicy), - "--set", "fqdn="+fqdn) + "--set", "fqdn="+fqdn, + "--description", reason, + ) if hubXmlrpcReplicas > 0 { log.Info().Msg(L("Enabling Hub XMLRPC API container.")) @@ -248,7 +264,11 @@ func Upgrade( hubXmlrpcReplicas = 1 } - err = UyuniUpgrade(serverImage, image.PullPolicy, hubXmlrpcReplicas, hubXmlrpcImageName, &helm, kubeconfig, fqdn, clusterInfos.Ingress) + err = UyuniUpgrade( + L("Upgrade from mgradm"), + serverImage, image.PullPolicy, hubXmlrpcReplicas, hubXmlrpcImageName, + &helm, kubeconfig, fqdn, clusterInfos.Ingress, + ) if err != nil { return utils.Errorf(err, L("cannot upgrade to image %s"), serverImage) }