diff --git a/pkg/cli/cli.go b/pkg/cli/cli.go index 82ae4abbb7..0b5c11c3c2 100644 --- a/pkg/cli/cli.go +++ b/pkg/cli/cli.go @@ -116,6 +116,7 @@ Load noobaa completion to bash: Message: "Install:", Commands: []*cobra.Command{ install.CmdInstall(), + install.CmdUpgrade(), install.CmdUninstall(), install.CmdStatus(), }, diff --git a/pkg/crd/crd.go b/pkg/crd/crd.go index b2cc6e1b9e..1bdfd2b5a5 100644 --- a/pkg/crd/crd.go +++ b/pkg/crd/crd.go @@ -110,6 +110,11 @@ func RunCreate(cmd *cobra.Command, args []string) { ForEachCRD(CreateCRD) } +// RunUpgrade runs a CLI command +func RunUpgrade(cmd *cobra.Command, args []string) { + ForEachCRD(UpgradeCRD) +} + // RunDelete runs a CLI command func RunDelete(cmd *cobra.Command, args []string) { ForEachCRD(DeleteCRD) @@ -175,6 +180,11 @@ func CreateCRD(crd *CRD) { util.KubeCreateSkipExisting(crd) } +// UpgradeCRD Kubernetesically applies a CRD (create if doesn't exist, update otherwise) +func UpgradeCRD(crd *CRD) { + util.KubeApply(crd) +} + // DeleteCRD deletes a CRD func DeleteCRD(crd *CRD) { util.KubeDelete(crd) diff --git a/pkg/install/install.go b/pkg/install/install.go index c5e71d2f81..38b3b82df8 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,6 +58,17 @@ func RunYaml(cmd *cobra.Command, args []string) { log.Println("✅ Done dumping installation yaml") } +// CmdUpgrade returns a CLI command +func CmdUpgrade() *cobra.Command { + cmd := &cobra.Command{ + Use: "upgrade", + Short: "Upgrade the system, its components and CRDS", + Run: RunUpgrade, + Args: cobra.NoArgs, + } + return cmd +} + // CmdUninstall returns a CLI command func CmdUninstall() *cobra.Command { cmd := &cobra.Command{ @@ -106,6 +118,29 @@ 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.RunUpgrade(cmd, args) + log.Printf("\nOperator upgrade:") + operator.RunUpgrade(cmd, args) + log.Printf("\nSystem apply:") + system.RunUpgrade(cmd, args) + log.Printf("") + util.PrintThisNoteWhenFinishedApplyingAndStartWaitLoop() + log.Printf("\nWaiting for the system to be ready...") + // Sleep to let the system get out of its old Ready state + time.Sleep(3 * time.Second) + if system.WaitReady() { + log.Printf("\n\n") + RunStatus(cmd, args) + } +} + // RunUninstall runs a CLI command func RunUninstall(cmd *cobra.Command, args []string) { log := util.Logger() diff --git a/pkg/operator/operator.go b/pkg/operator/operator.go index e1bb2eef80..b01d7dcf4d 100644 --- a/pkg/operator/operator.go +++ b/pkg/operator/operator.go @@ -100,6 +100,59 @@ func CmdRun() *cobra.Command { return cmd } +// RunUpgrade runs a CLI command +func RunUpgrade(cmd *cobra.Command, args []string) { + c := LoadOperatorConf(cmd) + util.KubeApply(c.NS) + util.KubeApply(c.SA) + util.KubeApply(c.SAEndpoint) + util.KubeApply(c.Role) + util.KubeApply(c.RoleEndpoint) + util.KubeApply(c.RoleBinding) + util.KubeApply(c.RoleBindingEndpoint) + util.KubeApply(c.ClusterRole) + util.KubeApply(c.ClusterRoleBinding) + + testEnv, _ := cmd.Flags().GetBool("test-env") + if testEnv { + operatorContainer := c.Deployment.Spec.Template.Spec.Containers[0] + operatorContainer.Env = append(operatorContainer.Env, corev1.EnvVar{ + Name: "TEST_ENV", + Value: "true", + }) + c.Deployment.Spec.Template.Spec.Containers[0].Env = operatorContainer.Env + } + + admission, _ := cmd.Flags().GetBool("admission") + if admission { + LoadAdmissionConf(c) + AdmissionWebhookSetup(c) + util.KubeApply(c.WebhookConfiguration) + util.KubeApply(c.WebhookSecret) + util.KubeApply(c.WebhookService) + operatorContainer := c.Deployment.Spec.Template.Spec.Containers[0] + operatorContainer.Env = append(operatorContainer.Env, corev1.EnvVar{ + Name: "ENABLE_NOOBAA_ADMISSION", + Value: "true", + }) + c.Deployment.Spec.Template.Spec.Containers[0].Env = operatorContainer.Env + } + + noDeploy, _ := cmd.Flags().GetBool("no-deploy") + if !noDeploy { + operatorContainer := c.Deployment.Spec.Template.Spec.Containers[0] + operatorContainer.Env = append( + operatorContainer.Env, + corev1.EnvVar{ + Name: "NOOBAA_CLI_DEPLOYMENT", + Value: "true", + }, + ) + c.Deployment.Spec.Template.Spec.Containers[0].Env = operatorContainer.Env + util.KubeApply(c.Deployment) + } +} + // RunInstall runs a CLI command func RunInstall(cmd *cobra.Command, args []string) { c := LoadOperatorConf(cmd) diff --git a/pkg/system/system.go b/pkg/system/system.go index d38ae3f055..606a13cddf 100644 --- a/pkg/system/system.go +++ b/pkg/system/system.go @@ -437,6 +437,18 @@ func RunCreate(cmd *cobra.Command, args []string) { util.KubeCreateSkipExisting(sys) } +// 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 + } + util.KubeApply(sys) +} + // RunDelete runs a CLI command func RunDelete(cmd *cobra.Command, args []string) { log := util.Logger()