Skip to content

Commit

Permalink
fixing oldDB status issue
Browse files Browse the repository at this point in the history
  • Loading branch information
abodhekar committed Nov 2, 2023
1 parent a99652d commit 4cc9352
Show file tree
Hide file tree
Showing 6 changed files with 144 additions and 218 deletions.
28 changes: 24 additions & 4 deletions api/v1/databaseclaim_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,30 @@ type DatabaseClaimStatus struct {
//non empty denotes migration in progress, unless it is S_Completed
MigrationState string `json:"migrationState,omitempty"`
// tracks the DB which is migrated and not more operational
OldDB Status `json:"oldDB,omitempty"`
OldDB StatusForOldDB `json:"oldDB,omitempty"`
}

type StatusForOldDB struct {
// Time the connection info was updated/created.
ConnectionInfo *DatabaseClaimConnectionInfo `json:"connectionInfo,omitempty"`

// Version of the provisioned Database
DBVersion string `json:"dbversion,omitempty"`

// The optional Shape values are arbitrary and help drive instance selection
Shape string `json:"shape,omitempty"`

// Specifies the type of database to provision. Only postgres is supported.
Type DatabaseType `json:"type,omitempty"`

// Time at the process of post migration actions initiated
PostMigrationActionStartedAt *metav1.Time `json:"postMigrationActionStartedAt,omitempty"`

// DbState of the DB. inprogress, "", ready
DbState DbState `json:"DbState,omitempty"`

// The optional MinStorageGB value requests the minimum database host storage capacity in GBytes
MinStorageGB int `json:"minStorageGB,omitempty"`
}

type Status struct {
Expand Down Expand Up @@ -260,9 +283,6 @@ type Status struct {
// This field used when claim is use-existing-db and attempting to migrate to newdb
// +optional
SourceDataFrom *SourceDataFrom `json:"sourceDataFrom,omitempty"`

// Time at the process of post migration actions initiated
PostMigrationActionStartedAt *metav1.Time `json:"postMigrationActionStartedAt,omitempty"`
}

// DbState keeps track of state of the DB.
Expand Down
26 changes: 23 additions & 3 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

102 changes: 1 addition & 101 deletions config/crd/bases/persistance.atlas.infoblox.com_databaseclaims.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,6 @@ spec:
description: The optional MinStorageGB value requests the minimum
database host storage capacity in GBytes
type: integer
postMigrationActionStartedAt:
description: Time at the process of post migration actions initiated
format: date-time
type: string
shape:
description: The optional Shape values are arbitrary and help
drive instance selection
Expand Down Expand Up @@ -417,10 +413,6 @@ spec:
description: The optional MinStorageGB value requests the minimum
database host storage capacity in GBytes
type: integer
postMigrationActionStartedAt:
description: Time at the process of post migration actions initiated
format: date-time
type: string
shape:
description: The optional Shape values are arbitrary and help
drive instance selection
Expand Down Expand Up @@ -518,6 +510,7 @@ spec:
description: DbState of the DB. inprogress, "", ready
type: string
connectionInfo:
description: Time the connection info was updated/created.
properties:
databaseName:
type: string
Expand All @@ -532,21 +525,9 @@ spec:
userName:
type: string
type: object
connectionUpdatedAt:
description: Time the connection info was updated/created.
format: date-time
type: string
dbCreateAt:
description: Time the database was created
format: date-time
type: string
dbversion:
description: Version of the provisioned Database
type: string
matchLabel:
description: The name of the label that was successfully matched
against the fragment key names in the db-controller configMap
type: string
minStorageGB:
description: The optional MinStorageGB value requests the minimum
database host storage capacity in GBytes
Expand All @@ -559,91 +540,10 @@ spec:
description: The optional Shape values are arbitrary and help
drive instance selection
type: string
sourceDataFrom:
description: SourceDataFrom specifies an existing database or
backup to use when initially provisioning the database. if the
dbclaim has already provisioned a database, this field is ignored
This field used when claim is use-existing-db and attempting
to migrate to newdb
properties:
database:
description: Database defines the connection information to
an existing db
properties:
dsn:
description: 'DSN is the connection string used to reach
the postgres database must have protocol specifier at
beginning (example: mysql:// postgres:// )'
type: string
secretRef:
description: 'SecretRef specifies a secret to use for
connecting to the postgresdb (should be master/root)
TODO: document/validate the secret format required'
properties:
name:
type: string
namespace:
type: string
required:
- name
type: object
required:
- dsn
type: object
s3:
description: S3 defines the location of a DB backup in an
S3 bucket
properties:
bucket:
type: string
prefix:
description: Prefix is the path prefix of the S3 bucket
within which the backup to restore is located.
type: string
region:
type: string
secretRef:
description: 'SecretRef specifies a secret to use for
connecting to the s3 bucket via AWS client TODO: document/validate
the secret format required'
properties:
name:
type: string
namespace:
type: string
required:
- name
type: object
sourceEngine:
description: SourceEngine is the engine used to create
the backup.
type: string
sourceEngineVersion:
description: 'SourceEngineVersion is the version of the
engine used to create the backup. Example: "5.7.30"'
type: string
required:
- bucket
- region
- sourceEngine
- sourceEngineVersion
type: object
type:
description: Type specifies the type of source
type: string
required:
- type
type: object
type:
description: Specifies the type of database to provision. Only
postgres is supported.
type: string
userUpdatedAt:
description: Time the user/password was updated/created
format: date-time
type: string
required:
- connectionInfo
type: object
type: object
type: object
Expand Down
17 changes: 13 additions & 4 deletions controllers/databaseclaim_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ func (r *DatabaseClaimReconciler) updateStatus(ctx context.Context, dbClaim *per
return r.manageError(ctx, dbClaim, err)
} else if !canTag {
logr.Info("Skipping post migration actions due to DB being used by other entities")
dbClaim.Status.OldDB = persistancev1.Status{}
dbClaim.Status.OldDB = persistancev1.StatusForOldDB{}
return r.manageSuccess(ctx, dbClaim)
}

Expand Down Expand Up @@ -475,7 +475,7 @@ func (r *DatabaseClaimReconciler) updateStatus(ctx context.Context, dbClaim *per
logr.Error(err, "Could not delete crossplane DBParamGroup/DBClusterParamGroup")
}

dbClaim.Status.OldDB = persistancev1.Status{}
dbClaim.Status.OldDB = persistancev1.StatusForOldDB{}
} else if time.Since(dbClaim.Status.OldDB.PostMigrationActionStartedAt.Time).Minutes() > 5 {
// Lets keep the state of old as it is for defined time to wait and verify tags before actually deleting resources
logr.Info("defined wait time is over to verify operational tags on AWS resources. Moving ahead to delete associated crossplane resources anyway")
Expand All @@ -487,7 +487,7 @@ func (r *DatabaseClaimReconciler) updateStatus(ctx context.Context, dbClaim *per
logr.Error(err, "Could not delete crossplane DBParamGroup/DBClusterParamGroup")
}

dbClaim.Status.OldDB = persistancev1.Status{}
dbClaim.Status.OldDB = persistancev1.StatusForOldDB{}
}

return r.manageSuccess(ctx, dbClaim)
Expand Down Expand Up @@ -845,7 +845,9 @@ loop:

timenow := metav1.Now()

dbClaim.Status.OldDB = *dbClaim.Status.ActiveDB.DeepCopy()
dbClaim.Status.OldDB = persistancev1.StatusForOldDB{ConnectionInfo: &persistancev1.DatabaseClaimConnectionInfo{}}
//dbClaim.Status.OldDB = *dbClaim.Status.ActiveDB.DeepCopy()
MakeDeepCopyToOldDB(&dbClaim.Status.OldDB, &dbClaim.Status.ActiveDB)
dbClaim.Status.OldDB.DbState = persistancev1.PostMigrationInProgress
dbClaim.Status.OldDB.PostMigrationActionStartedAt = &timenow

Expand All @@ -869,6 +871,13 @@ loop:
return r.manageSuccess(ctx, dbClaim)
}

func MakeDeepCopyToOldDB(to *persistancev1.StatusForOldDB, from *persistancev1.Status) {
to.ConnectionInfo = from.ConnectionInfo.DeepCopy()
to.DBVersion = from.DBVersion
to.Shape = from.Shape
to.Type = from.Type
}

func (r *DatabaseClaimReconciler) operationalTaggingForDbParamGroup(ctx context.Context, logr logr.Logger, dbParamGroupName string) {
dbParameterGroup := &crossplanerds.DBParameterGroup{}

Expand Down
Loading

0 comments on commit 4cc9352

Please sign in to comment.