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.database): do not send empty modify-calls #2146

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
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
Loading