Skip to content

Commit

Permalink
Add support for MCG upgrade via the CLI
Browse files Browse the repository at this point in the history
Signed-off-by: Ben <[email protected]>
  • Loading branch information
Neon-White committed Oct 12, 2023
1 parent f913b7f commit 3ba5839
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ Load noobaa completion to bash:
Message: "Install:",
Commands: []*cobra.Command{
install.CmdInstall(),
install.CmdUpgrade(),
install.CmdUninstall(),
install.CmdStatus(),
},
Expand Down
10 changes: 10 additions & 0 deletions pkg/crd/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
35 changes: 35 additions & 0 deletions pkg/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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()
Expand Down
53 changes: 53 additions & 0 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions pkg/system/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 3ba5839

Please sign in to comment.