Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support auora io #207

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 8 additions & 41 deletions controllers/databaseclaim_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ const (
masterSecretSuffix = "-master"
masterPasswordKey = "password"
ErrMaxNameLen = Error("dbclaim name is too long. max length is 44 characters")
ErrMaxStorageReduced = Error("reducing .spec.MaxStorageGB value is not allowed")
ErrMaxStorageLesser = Error(".spec.MaxStorageGB should always be greater or equel to spec.minStorageGB")
// InfoLevel is used to set V level to 0 as suggested by official docs
// https://github.com/kubernetes-sigs/controller-runtime/blob/main/TMP-LOGGING.md
InfoLevel = 0
Expand Down Expand Up @@ -245,12 +243,6 @@ func (r *DatabaseClaimReconciler) getMode(dbClaim *persistancev1.DatabaseClaim)
return M_UseNewDB
}

// checkIfMaxStorageReduced checks if the MaxStorageGB has been reduced or disabled compared to earlier state.
// This can be done by comparing it with MaxStorageGB in the status.
func (r *DatabaseClaimReconciler) checkIfMaxStorageReduced(dbClaim *persistancev1.DatabaseClaim) bool {
return r.Input.HostParams.MaxStorageGB < dbClaim.Status.ActiveDB.MaxStorageGB || r.Input.HostParams.MaxStorageGB < dbClaim.Status.NewDB.MaxStorageGB
}

func (r *DatabaseClaimReconciler) setReqInfo(dbClaim *persistancev1.DatabaseClaim) error {
logr := r.Log.WithValues("databaseclaim", dbClaim.Namespace+"/"+dbClaim.Name, "func", "setReqInfo")

Expand Down Expand Up @@ -336,22 +328,6 @@ func (r *DatabaseClaimReconciler) setReqInfo(dbClaim *persistancev1.DatabaseClai
r.Input.EnableReplicationRole = *dbClaim.Spec.EnableReplicationRole
}

if hostParams.Engine == defaultPostgresStr {
if r.checkIfMaxStorageReduced(dbClaim) {
// if MaxStorageGB was present in earlier state, and now is being reduced or removed. This Should throw an error
return ErrMaxStorageReduced
} else if r.Input.HostParams.MaxStorageGB == 0 {
// If MaxStorageGB is currently not present or zero, and it was not present earlier as well, then we assign MinStorageGB value to it
// marking autoStorageScalling as disabled
r.Input.HostParams.MaxStorageGB = int64(r.Input.HostParams.MinStorageGB)
} else if r.Input.HostParams.MaxStorageGB != 0 {
if r.Input.HostParams.MaxStorageGB < int64(r.Input.HostParams.MinStorageGB) {
// If MaxStorageGB is being provided, but it is lasser than minStorage, This should not be allowed.
return ErrMaxStorageLesser
}
}
}

logr.V(DebugLevel).Info("setup values of ", "DatabaseClaimReconciler", r)
return nil
}
Expand Down Expand Up @@ -387,7 +363,6 @@ func (r *DatabaseClaimReconciler) Reconcile(ctx context.Context, req ctrl.Reques
if err := r.setReqInfo(&dbClaim); err != nil {
return r.manageError(ctx, &dbClaim, err)
}

// name of our custom finalizer
dbFinalizerName := "databaseclaims.persistance.atlas.infoblox.com/finalizer"

Expand Down Expand Up @@ -693,9 +668,6 @@ func (r *DatabaseClaimReconciler) reconcileNewDB(ctx context.Context,
dbClaim.Status.NewDB = *dbClaim.Status.ActiveDB.DeepCopy()
if dbClaim.Status.NewDB.MinStorageGB != r.Input.HostParams.MinStorageGB {
dbClaim.Status.NewDB.MinStorageGB = r.Input.HostParams.MinStorageGB
if r.Input.HostParams.Engine == defaultPostgresStr {
dbClaim.Status.NewDB.MaxStorageGB = r.Input.HostParams.MaxStorageGB
}
}
} else {
updateClusterStatus(&dbClaim.Status.NewDB, &r.Input.HostParams)
Expand Down Expand Up @@ -1789,6 +1761,7 @@ func (r *DatabaseClaimReconciler) manageDBCluster(ctx context.Context, dbHostNam
MasterUsername: &params.MasterUsername,
EnableIAMDatabaseAuthentication: &params.EnableIAMDatabaseAuthentication,
StorageEncrypted: &encryptStrg,
StorageType: &params.StorageType,
Port: &params.Port,
},
ResourceSpec: xpv1.ResourceSpec{
Expand Down Expand Up @@ -1870,7 +1843,6 @@ func (r *DatabaseClaimReconciler) managePostgresDBInstance(ctx context.Context,
ms64 := int64(params.MinStorageGB)
multiAZ := r.getMultiAZEnabled()
trueVal := true
storageType := r.Config.GetString("storageType")

dbClaim.Spec.Tags = r.configureBackupPolicy(dbClaim.Spec.BackupPolicy, dbClaim.Spec.Tags)

Expand Down Expand Up @@ -1905,12 +1877,11 @@ func (r *DatabaseClaimReconciler) managePostgresDBInstance(ctx context.Context,
EngineVersion: &params.EngineVersion,
},
// Items from Claim and fragmentKey
Engine: &params.Engine,
MultiAZ: &multiAZ,
DBInstanceClass: &params.Shape,
AllocatedStorage: &ms64,
MaxAllocatedStorage: &params.MaxStorageGB,
Tags: DBClaimTags(dbClaim.Spec.Tags).DBTags(),
Engine: &params.Engine,
MultiAZ: &multiAZ,
DBInstanceClass: &params.InstanceClass,
AllocatedStorage: &ms64,
Tags: DBClaimTags(dbClaim.Spec.Tags).DBTags(),
// Items from Config
MasterUsername: &params.MasterUsername,
PubliclyAccessible: &params.PubliclyAccessible,
Expand All @@ -1919,7 +1890,7 @@ func (r *DatabaseClaimReconciler) managePostgresDBInstance(ctx context.Context,
EnableCloudwatchLogsExports: r.Input.EnableCloudwatchLogsExport,
BackupRetentionPeriod: &r.Input.BackupRetentionDays,
StorageEncrypted: &trueVal,
StorageType: &storageType,
StorageType: &params.StorageType,
Port: &params.Port,
},
ResourceSpec: xpv1.ResourceSpec{
Expand Down Expand Up @@ -2013,7 +1984,7 @@ func (r *DatabaseClaimReconciler) manageAuroraDBInstance(ctx context.Context, db
DBParameterGroupName: &pgName,
// Items from Claim and fragmentKey
Engine: &params.Engine,
DBInstanceClass: &params.Shape,
DBInstanceClass: &params.InstanceClass,
Tags: DBClaimTags(dbClaim.Spec.Tags).DBTags(),
// Items from Config
PubliclyAccessible: &params.PubliclyAccessible,
Expand Down Expand Up @@ -2421,7 +2392,6 @@ func (r *DatabaseClaimReconciler) updateDBInstance(ctx context.Context, dbClaim
params := &r.Input.HostParams
ms64 := int64(params.MinStorageGB)
dbInstance.Spec.ForProvider.AllocatedStorage = &ms64
dbInstance.Spec.ForProvider.MaxAllocatedStorage = &params.MaxStorageGB
dbInstance.Spec.ForProvider.EnableCloudwatchLogsExports = r.Input.EnableCloudwatchLogsExport
dbInstance.Spec.ForProvider.MultiAZ = &multiAZ
}
Expand Down Expand Up @@ -2713,9 +2683,6 @@ func updateClusterStatus(status *persistancev1.Status, hostParams *hostparams.Ho
status.Type = persistancev1.DatabaseType(hostParams.Engine)
status.Shape = hostParams.Shape
status.MinStorageGB = hostParams.MinStorageGB
if hostParams.Engine == defaultPostgresStr {
status.MaxStorageGB = hostParams.MaxStorageGB
}
}

func getServiceNamespace() (string, error) {
Expand Down
Loading
Loading