Skip to content

Commit

Permalink
Merge pull request #2148 from crossplane-contrib/backport-2146-to-rel…
Browse files Browse the repository at this point in the history
…ease-0.51

[Backport release-0.51] fix(rdsinstance.database): do not send empty modify-calls
  • Loading branch information
anagarlau authored Jan 23, 2025
2 parents 286b475 + c8700ba commit a5dad2f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
4 changes: 4 additions & 0 deletions pkg/clients/database/rds.go
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,10 @@ func generateCloudWatchExportConfiguration(spec, current []string) *rdstypes.Clo
}
}

if len(toEnable) == 0 && len(toDisable) == 0 {
return nil
}

return &rdstypes.CloudwatchLogsExportConfiguration{
EnableLogTypes: toEnable,
DisableLogTypes: toDisable,
Expand Down
4 changes: 0 additions & 4 deletions pkg/clients/database/rds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1368,10 +1368,6 @@ func TestGenerateModifyDBInstanceInput(t *testing.T) {
params: v1beta1.RDSInstanceParameters{},
want: rds.ModifyDBInstanceInput{
DBInstanceIdentifier: &emptyName,
CloudwatchLogsExportConfiguration: &rdstypes.CloudwatchLogsExportConfiguration{
DisableLogTypes: []string{},
EnableLogTypes: []string{},
},
},
},
}
Expand Down
18 changes: 16 additions & 2 deletions pkg/controller/database/rdsinstance/rdsinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (
"github.com/crossplane/crossplane-runtime/pkg/password"
"github.com/crossplane/crossplane-runtime/pkg/reconciler/managed"
"github.com/crossplane/crossplane-runtime/pkg/resource"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/pkg/errors"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -297,8 +299,20 @@ func (e *external) Update(ctx context.Context, mg resource.Managed) (managed.Ext
modify.StorageThroughput = nil
}

if _, err = e.client.ModifyDBInstance(ctx, modify); err != nil {
return managed.ExternalUpdate{}, errorutils.Wrap(err, errModifyFailed)
// We only want to request a modification if we actually got more than ID and modify flags.
// Note: When ApplyImmediately is set to false, AWS rejects those empty calls with
// "cannot modify RDS instance: api error InalidParameterCombination: No modifications were requested"
// (but when set to true, AWS doesn't block them...)
diff := cmp.Diff(&awsrds.ModifyDBInstanceInput{}, modify, cmpopts.EquateEmpty(),
cmpopts.IgnoreUnexported(awsrds.ModifyDBInstanceInput{}),
cmpopts.IgnoreFields(awsrds.ModifyDBInstanceInput{}, "DBInstanceIdentifier"),
cmpopts.IgnoreFields(awsrds.ModifyDBInstanceInput{}, "AllowMajorVersionUpgrade"),
cmpopts.IgnoreFields(awsrds.ModifyDBInstanceInput{}, "ApplyImmediately"),
)
if diff != "" {
if _, err = e.client.ModifyDBInstance(ctx, modify); err != nil {
return managed.ExternalUpdate{}, errorutils.Wrap(err, errModifyFailed)
}
}

// Update tags if necessary
Expand Down
6 changes: 4 additions & 2 deletions pkg/controller/database/rdsinstance/rdsinstance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -857,10 +857,12 @@ func TestUpdate(t *testing.T) {
}, nil
},
},
cr: instance(),
cr: instance(
withEngineVersion(&engineVersion)),
},
want: want{
cr: instance(),
cr: instance(
withEngineVersion(&engineVersion)),
err: errorutils.Wrap(errBoom, errModifyFailed),
},
},
Expand Down

0 comments on commit a5dad2f

Please sign in to comment.