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(rdsinstance/dbinstance): check optiongroupname correctly #1816

Merged
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
3 changes: 2 additions & 1 deletion examples/database/rdsinstance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ spec:
forProvider:
region: us-east-1
allocatedStorage: 20
applyModificationsImmediately: true # default is false
autoMinorVersionUpgrade: true
backupRetentionPeriod: 0
caCertificateIdentifier: rds-ca-2019
Expand All @@ -15,7 +16,7 @@ spec:
enableIAMDatabaseAuthentication: false
enablePerformanceInsights: false
engine: mysql
engineVersion: 8.0.28
engineVersion: "8.0.28"
finalDBSnapshotIdentifier: muvaf-test
licenseModel: general-public-license
masterUsername: admin
Expand Down
32 changes: 31 additions & 1 deletion pkg/clients/database/rds.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,11 +677,14 @@ func IsUpToDate(ctx context.Context, kube client.Client, r *v1beta1.RDSInstance,
cmpopts.IgnoreFields(v1beta1.RDSInstanceParameters{}, "ApplyModificationsImmediately"),
cmpopts.IgnoreFields(v1beta1.RDSInstanceParameters{}, "AllowMajorVersionUpgrade"),
cmpopts.IgnoreFields(v1beta1.RDSInstanceParameters{}, "MasterPasswordSecretRef"),
cmpopts.IgnoreFields(v1beta1.RDSInstanceParameters{}, "OptionGroupName"),
)

engineVersionChanged := !isEngineVersionUpToDate(r, db)

if diff == "" && !pwdChanged && !engineVersionChanged {
optionGroupChanged := !isOptionGroupUpToDate(r, db)

if diff == "" && !pwdChanged && !engineVersionChanged && !optionGroupChanged {
return true, "", nil
}

Expand All @@ -706,6 +709,33 @@ func isEngineVersionUpToDate(cr *v1beta1.RDSInstance, db rdstypes.DBInstance) bo
return true
}

func isOptionGroupUpToDate(cr *v1beta1.RDSInstance, db rdstypes.DBInstance) bool {
// If OptionGroupName is not set, AWS sets a default OptionGroup,
// so we do not try to update in this case
if cr.Spec.ForProvider.OptionGroupName != nil {
for _, group := range db.OptionGroupMemberships {
if group.OptionGroupName != nil && (awsclients.StringValue(group.OptionGroupName) == awsclients.StringValue(cr.Spec.ForProvider.OptionGroupName)) {

switch awsclients.StringValue(group.Status) {
case "pending-maintenance-apply":
// If ApplyModificationsImmediately was turned on after the OptionGroup change was requested,
// we can make a new Modify request
if awsclients.BoolValue(cr.Spec.ForProvider.ApplyModificationsImmediately) {
return false
}
return true
case "pending-maintenance-removal":
return false
default: // "in-sync", "applying", "pending-apply", "pending-removal", "removing", "failed"
return true
}
}
}
return false
}
return true
}

// GetPassword fetches the referenced input password for an RDSInstance CRD and determines whether it has changed or not
func GetPassword(ctx context.Context, kube client.Client, in *xpv1.SecretKeySelector, out *xpv1.SecretReference) (newPwd string, changed bool, err error) {
if in == nil {
Expand Down
32 changes: 31 additions & 1 deletion pkg/controller/rds/dbinstance/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ func (e *custom) isUpToDate(cr *svcapitypes.DBInstance, out *svcsdk.DescribeDBIn

dbParameterGroupChanged := !isDBParameterGroupNameUpToDate(cr, db)

optionGroupChanged := !isOptionGroupUpToDate(cr, db)

diff := cmp.Diff(&svcapitypes.DBInstanceParameters{}, patch, cmpopts.EquateEmpty(),
cmpopts.IgnoreTypes(&xpv1.Reference{}, &xpv1.Selector{}, []xpv1.Reference{}),
cmpopts.IgnoreFields(svcapitypes.DBInstanceParameters{}, "Region"),
Expand All @@ -394,13 +396,14 @@ func (e *custom) isUpToDate(cr *svcapitypes.DBInstance, out *svcsdk.DescribeDBIn
cmpopts.IgnoreFields(svcapitypes.DBInstanceParameters{}, "AutogeneratePassword"),
cmpopts.IgnoreFields(svcapitypes.DBInstanceParameters{}, "PreferredMaintenanceWindow"),
cmpopts.IgnoreFields(svcapitypes.DBInstanceParameters{}, "PreferredBackupWindow"),
cmpopts.IgnoreFields(svcapitypes.DBInstanceParameters{}, "OptionGroupName"),
cmpopts.IgnoreFields(svcapitypes.CustomDBInstanceParameters{}, "ApplyImmediately"),
cmpopts.IgnoreFields(svcapitypes.CustomDBInstanceParameters{}, "RestoreFrom"),
cmpopts.IgnoreFields(svcapitypes.CustomDBInstanceParameters{}, "VPCSecurityGroupIDs"),
cmpopts.IgnoreFields(svcapitypes.CustomDBInstanceParameters{}, "DeleteAutomatedBackups"),
)

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

Expand Down Expand Up @@ -439,6 +442,33 @@ func isEngineVersionUpToDate(cr *svcapitypes.DBInstance, out *svcsdk.DescribeDBI
return true
}

func isOptionGroupUpToDate(cr *svcapitypes.DBInstance, out *svcsdk.DBInstance) bool {
// If OptionGroupName is not set, AWS sets a default OptionGroup,
// so we do not try to update in this case
if cr.Spec.ForProvider.OptionGroupName != nil {
for _, group := range out.OptionGroupMemberships {
if group.OptionGroupName != nil && (aws.StringValue(group.OptionGroupName) == aws.StringValue(cr.Spec.ForProvider.OptionGroupName)) {

switch aws.StringValue(group.Status) {
case "pending-maintenance-apply":
// If ApplyImmediately was turned on after the OptionGroup change was requested,
// we can make a new Modify request
if aws.BoolValue(cr.Spec.ForProvider.ApplyImmediately) {
return false
}
return true
case "pending-maintenance-removal":
return false
default: // "in-sync", "applying", "pending-apply", "pending-removal", "removing", "failed"
return true
}
}
}
return false
}
return true
}

func createPatch(out *svcsdk.DescribeDBInstancesOutput, target *svcapitypes.DBInstanceParameters) (*svcapitypes.DBInstanceParameters, error) {
currentParams := &svcapitypes.DBInstanceParameters{}
err := lateInitialize(currentParams, out)
Expand Down
Loading