Skip to content

Commit

Permalink
Initial implementation of product upgrade via CLI
Browse files Browse the repository at this point in the history
Signed-off-by: Ben <[email protected]>
  • Loading branch information
Neon-White committed Sep 4, 2023
1 parent 7aa4663 commit 63dbb2c
Show file tree
Hide file tree
Showing 5 changed files with 159 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)
}

// RunCreate runs a CLI command
func RunApply(cmd *cobra.Command, args []string) {
ForEachCRD(ApplyCRD)
}

// 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)
}

// ApplyCRD creates a CRD
func ApplyCRD(crd *CRD) {
util.KubeApply(crd)
}

// DeleteCRD deletes a CRD
func DeleteCRD(crd *CRD) {
util.KubeDelete(crd)
Expand Down
30 changes: 30 additions & 0 deletions pkg/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ func RunYaml(cmd *cobra.Command, args []string) {
log.Println("✅ Done dumping installation yaml")
}

// CmdInstall 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 +117,25 @@ func RunInstall(cmd *cobra.Command, args []string) {
}
}

func RunUpgrade(cmd *cobra.Command, args []string) {
log := util.Logger()
system.RunSystemVersionsStatus(cmd, args)
log.Printf("Namespace: %s\n", options.Namespace)
log.Printf("CRD upgrade:")
crd.RunApply(cmd, args)
log.Printf("\nOperator upgrade:")
operator.RunApply(cmd, args)
log.Printf("\nSystem apply:")
system.RunApply(cmd, args)
log.Printf("")
util.PrintThisNoteWhenFinishedApplyingAndStartWaitLoop()
log.Printf("\nWaiting for the system to be ready...")
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
}

// RunApply runs a CLI command
func RunApply(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
65 changes: 65 additions & 0 deletions pkg/system/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,71 @@ 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,
}
}

// 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)
}

// RunDelete runs a CLI command
func RunDelete(cmd *cobra.Command, args []string) {
log := util.Logger()
Expand Down

0 comments on commit 63dbb2c

Please sign in to comment.