Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
Signed-off-by: Ben <[email protected]>
  • Loading branch information
Neon-White committed Sep 18, 2023
1 parent 63dbb2c commit fbdcab7
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 76 deletions.
10 changes: 5 additions & 5 deletions pkg/crd/crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}

Expand Down
12 changes: 8 additions & 4 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,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",
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions pkg/operator/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
77 changes: 12 additions & 65 deletions pkg/system/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit fbdcab7

Please sign in to comment.