From fbdcab7cc8787a22e38f2743f7fd9dc7606eef88 Mon Sep 17 00:00:00 2001 From: Ben Date: Mon, 18 Sep 2023 12:06:35 +0200 Subject: [PATCH] Address comments Signed-off-by: Ben --- pkg/crd/crd.go | 10 +++--- pkg/install/install.go | 12 ++++--- pkg/operator/operator.go | 4 +-- pkg/system/system.go | 77 +++++++--------------------------------- 4 files changed, 27 insertions(+), 76 deletions(-) diff --git a/pkg/crd/crd.go b/pkg/crd/crd.go index 1a62ddf613..1bdfd2b5a5 100644 --- a/pkg/crd/crd.go +++ b/pkg/crd/crd.go @@ -110,9 +110,9 @@ func RunCreate(cmd *cobra.Command, args []string) { ForEachCRD(CreateCRD) } -// RunCreate runs a CLI command -func RunApply(cmd *cobra.Command, args []string) { - ForEachCRD(ApplyCRD) +// RunUpgrade runs a CLI command +func RunUpgrade(cmd *cobra.Command, args []string) { + ForEachCRD(UpgradeCRD) } // RunDelete runs a CLI command @@ -180,8 +180,8 @@ func CreateCRD(crd *CRD) { util.KubeCreateSkipExisting(crd) } -// ApplyCRD creates a CRD -func ApplyCRD(crd *CRD) { +// UpgradeCRD Kubernetesically applies a CRD (create if doesn't exist, update otherwise) +func UpgradeCRD(crd *CRD) { util.KubeApply(crd) } diff --git a/pkg/install/install.go b/pkg/install/install.go index 2d001d6b3a..8ac51b9f78 100644 --- a/pkg/install/install.go +++ b/pkg/install/install.go @@ -2,6 +2,7 @@ package install import ( "fmt" + "time" "github.com/noobaa/noobaa-operator/v5/pkg/backingstore" "github.com/noobaa/noobaa-operator/v5/pkg/bucketclass" @@ -57,7 +58,7 @@ func RunYaml(cmd *cobra.Command, args []string) { log.Println("✅ Done dumping installation yaml") } -// CmdInstall returns a CLI command +// CmdUpgrade returns a CLI command func CmdUpgrade() *cobra.Command { cmd := &cobra.Command{ Use: "upgrade", @@ -117,18 +118,21 @@ func RunInstall(cmd *cobra.Command, args []string) { } } +// RunUpgrade runs a CLI command func RunUpgrade(cmd *cobra.Command, args []string) { log := util.Logger() + log.Printf("System versions prior to upgrade:\n") system.RunSystemVersionsStatus(cmd, args) log.Printf("Namespace: %s\n", options.Namespace) log.Printf("CRD upgrade:") - crd.RunApply(cmd, args) + crd.RunUpgrade(cmd, args) log.Printf("\nOperator upgrade:") - operator.RunApply(cmd, args) + operator.RunUpgrade(cmd, args) log.Printf("\nSystem apply:") - system.RunApply(cmd, args) + system.RunUpgrade(cmd, args) log.Printf("") util.PrintThisNoteWhenFinishedApplyingAndStartWaitLoop() + time.Sleep(3 * time.Second) log.Printf("\nWaiting for the system to be ready...") if system.WaitReady() { log.Printf("\n\n") diff --git a/pkg/operator/operator.go b/pkg/operator/operator.go index 0728515190..4db5366021 100644 --- a/pkg/operator/operator.go +++ b/pkg/operator/operator.go @@ -100,8 +100,8 @@ func CmdRun() *cobra.Command { return cmd } -// RunApply runs a CLI command -func RunApply(cmd *cobra.Command, args []string) { +// RunUpgrade runs a CLI command +func RunUpgrade(cmd *cobra.Command, args []string) { c := LoadOperatorConf(cmd) util.KubeApply(c.NS) util.KubeApply(c.SA) diff --git a/pkg/system/system.go b/pkg/system/system.go index 6907e25a7a..27f2f18e68 100644 --- a/pkg/system/system.go +++ b/pkg/system/system.go @@ -160,10 +160,10 @@ func LoadSystemDefaults() *nbv1.NooBaa { if options.PrometheusNamespace != "" { sys.Spec.Autoscaler.PrometheusNamespace = options.PrometheusNamespace } - if options.NooBaaImage != "" { - image := options.NooBaaImage - sys.Spec.Image = &image - } +if options.NooBaaImage != "" { + image := options.NooBaaImage + sys.Spec.Image = &image +} if options.ImagePullSecret != "" { sys.Spec.ImagePullSecret = &corev1.LocalObjectReference{Name: options.ImagePullSecret} } @@ -404,68 +404,15 @@ func RunCreate(cmd *cobra.Command, args []string) { util.KubeCreateSkipExisting(sys) } -// RunApply runs a CLI command -func RunApply(cmd *cobra.Command, args []string) { - log := util.Logger() - sys := LoadSystemDefaults() - ns := util.KubeObject(bundle.File_deploy_namespace_yaml).(*corev1.Namespace) - ns.Name = sys.Namespace - - coreResourcesJSON, _ := cmd.Flags().GetString("core-resources") - dbResourcesJSON, _ := cmd.Flags().GetString("db-resources") - endpointResourcesJSON, _ := cmd.Flags().GetString("endpoint-resources") - useOBCCleanupPolicy, _ := cmd.Flags().GetBool("use-obc-cleanup-policy") - - if useOBCCleanupPolicy { - sys.Spec.CleanupPolicy.Confirmation = nbv1.DeleteOBCConfirmation - } - if coreResourcesJSON != "" { - util.Panic(json.Unmarshal([]byte(coreResourcesJSON), &sys.Spec.CoreResources)) - } - if dbResourcesJSON != "" { - util.Panic(json.Unmarshal([]byte(dbResourcesJSON), &sys.Spec.DBResources)) - } - if endpointResourcesJSON != "" { - if sys.Spec.Endpoints == nil { - sys.Spec.Endpoints = &nbv1.EndpointsSpec{ - MinCount: 1, - MaxCount: 1, - } - } - util.Panic(json.Unmarshal([]byte(endpointResourcesJSON), &sys.Spec.Endpoints.Resources)) - } - - err := CheckMongoURL(sys) - if err != nil { - log.Fatalf(`❌ %s`, err) - } - - if options.PostgresDbURL != "" { - if sys.Spec.DBType != "postgres" { - log.Fatalf("❌ expecting the DBType to be postgres when using external PostgresDbURL, got %s", sys.Spec.DBType) - } - err = CheckPostgresURL(options.PostgresDbURL) - if err != nil { - log.Fatalf(`❌ %s`, err) - } - o := util.KubeObject(bundle.File_deploy_internal_secret_empty_yaml) - secret := o.(*corev1.Secret) - secret.Namespace = options.Namespace - secret.Name = "noobaa-external-pg-db" - secret.StringData = map[string]string{ - "db_url": options.PostgresDbURL, - } - secret.Data = nil - util.KubeApply(secret) - sys.Spec.ExternalPgSecret = &corev1.SecretReference{ - Name: secret.Name, - Namespace: secret.Namespace, - } +// RunUpgrade runs a CLI command +func RunUpgrade(cmd *cobra.Command, args []string) { + // Template the a system CR with an upgraded core image. + // We currently opt to not upgrade the DB image as part of this process to prevent complications. + sys := util.KubeObject(bundle.File_deploy_crds_noobaa_io_v1alpha1_noobaa_cr_yaml).(*nbv1.NooBaa) + if options.NooBaaImage != "" { + image := options.NooBaaImage + sys.Spec.Image = &image } - - // TODO check PVC if exist and the system does not exist - - // fail and suggest to delete them first with cli system delete. - util.KubeApply(ns) util.KubeApply(sys) }