Skip to content

Commit

Permalink
fix(rdsinstance.database): do not send empty modify-calls
Browse files Browse the repository at this point in the history
Signed-off-by: Charel Baum (external expert on behalf of DB InfraGO AG) <[email protected]>
  • Loading branch information
Charel Baum (external expert on behalf of DB InfraGO AG) committed Jan 22, 2025
1 parent e4fd057 commit 3be4e04
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 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

0 comments on commit 3be4e04

Please sign in to comment.