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

fix(dbinstance): in isUpToDate consider 0 and nil to be equal for iops/storageThroughput #2037

Merged
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
35 changes: 32 additions & 3 deletions pkg/controller/rds/dbinstance/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,12 @@ func (e *custom) isUpToDate(ctx context.Context, cr *svcapitypes.DBInstance, out
return false, "", err
}

// Depending on whether the instance was created as gp2 or modified from another type (e.g. gp3) to gp2,
// AWS provides different responses for IOPS/StorageThroughput (either 0 or nil).
// Therefore, we consider both 0 and nil to be equivalent.
iopsChanged := !(pointer.Int64Value(cr.Spec.ForProvider.IOPS) == pointer.Int64Value(db.Iops))
storageThroughputChanged := !(pointer.Int64Value(cr.Spec.ForProvider.StorageThroughput) == pointer.Int64Value(db.StorageThroughput))

versionChanged := !isEngineVersionUpToDate(cr, out)

vpcSGsChanged := !areVPCSecurityGroupIDsUpToDate(cr, db)
Expand All @@ -483,6 +489,8 @@ func (e *custom) isUpToDate(ctx context.Context, cr *svcapitypes.DBInstance, out
cmpopts.IgnoreFields(svcapitypes.DBInstanceParameters{}, "AllowMajorVersionUpgrade"),
cmpopts.IgnoreFields(svcapitypes.DBInstanceParameters{}, "DBParameterGroupName"),
cmpopts.IgnoreFields(svcapitypes.DBInstanceParameters{}, "EngineVersion"),
cmpopts.IgnoreFields(svcapitypes.DBInstanceParameters{}, "IOPS"),
cmpopts.IgnoreFields(svcapitypes.DBInstanceParameters{}, "StorageThroughput"),
cmpopts.IgnoreFields(svcapitypes.DBInstanceParameters{}, "Tags"),
cmpopts.IgnoreFields(svcapitypes.DBInstanceParameters{}, "SkipFinalSnapshot"),
cmpopts.IgnoreFields(svcapitypes.DBInstanceParameters{}, "FinalDBSnapshotIdentifier"),
Expand All @@ -500,15 +508,15 @@ func (e *custom) isUpToDate(ctx context.Context, cr *svcapitypes.DBInstance, out
e.cache.addTags, e.cache.removeTags = utils.DiffTags(cr.Spec.ForProvider.Tags, db.TagList)
tagsChanged := len(e.cache.addTags) != 0 || len(e.cache.removeTags) != 0

if diff == "" && !maintenanceWindowChanged && !backupWindowChanged && !versionChanged && !vpcSGsChanged && !dbParameterGroupChanged && !optionGroupChanged && !tagsChanged {
if diff == "" && !maintenanceWindowChanged && !backupWindowChanged && !iopsChanged && !storageThroughputChanged && !versionChanged && !vpcSGsChanged && !dbParameterGroupChanged && !optionGroupChanged && !tagsChanged {
return true, diff, nil
}

diff = "Found observed difference in dbinstance\n" + diff
if maintenanceWindowChanged {
diff += "\ndesired maintanaceWindow: "
diff += "\ndesired maintenanceWindow: "
diff += *cr.Spec.ForProvider.PreferredMaintenanceWindow
diff += "\nobserved maintanaceWindow: "
diff += "\nobserved maintenanceWindow: "
diff += *db.PreferredMaintenanceWindow
}
if backupWindowChanged {
Expand All @@ -517,6 +525,27 @@ func (e *custom) isUpToDate(ctx context.Context, cr *svcapitypes.DBInstance, out
diff += "\nobserved backupWindow: "
diff += *db.PreferredBackupWindow
}
if iopsChanged {
diff += fmt.Sprintf("\ndesired iops: %d \nobserved iops: %d ", pointer.Int64Value(cr.Spec.ForProvider.IOPS), pointer.Int64Value(db.Iops))
}
if storageThroughputChanged {
diff += fmt.Sprintf("\ndesired storageThroughput: %d \nobserved storageThroughput: %d ", pointer.Int64Value(cr.Spec.ForProvider.StorageThroughput), pointer.Int64Value(db.StorageThroughput))
}
if versionChanged {
diff += fmt.Sprintf("\ndesired engineVersion: %s \nobserved engineVersion: %s ", pointer.StringValue(cr.Spec.ForProvider.EngineVersion), pointer.StringValue(db.EngineVersion))
}
if vpcSGsChanged {
diff += fmt.Sprintf("\ndesired vpcSecurityGroupIDs: %v \nobserved vpcSecurityGroupIDs: ", cr.Spec.ForProvider.VPCSecurityGroupIDs)
for _, grp := range db.VpcSecurityGroups {
diff += fmt.Sprintf("\n - %s ", pointer.StringValue(grp.VpcSecurityGroupId))
}
}
if dbParameterGroupChanged {
diff += fmt.Sprintf("\ndesired dbParameterGroupName: %s \nobserved dbParameterGroupName: %s ", pointer.StringValue(cr.Spec.ForProvider.DBParameterGroupName), pointer.StringValue(db.DBParameterGroups[0].DBParameterGroupName))
}
if optionGroupChanged {
diff += fmt.Sprintf("\ndesired optionGroupName: %s \nobserved optionGroupName: %s ", pointer.StringValue(cr.Spec.ForProvider.OptionGroupName), pointer.StringValue(db.OptionGroupMemberships[0].OptionGroupName))
}
if tagsChanged {
diff += fmt.Sprintf("\nadd %d tag(s) and remove %d tag(s)", len(e.cache.addTags), len(e.cache.removeTags))
}
Expand Down
Loading