Skip to content

Commit

Permalink
Dont do empty "modify" calls for
Browse files Browse the repository at this point in the history
Can be triggered every time auto-generated tags are removed
  • Loading branch information
chlunde committed Feb 20, 2024
1 parent 5e41c7c commit d558b01
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
9 changes: 9 additions & 0 deletions pkg/controller/database/rdsinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package database

import (
"context"
"log"
"reflect"
"sort"

Expand Down Expand Up @@ -242,10 +243,18 @@ func (e *external) Update(ctx context.Context, mg resource.Managed) (managed.Ext
if err != nil {
return managed.ExternalUpdate{}, awsclient.Wrap(err, errDescribeFailed)
}

patch, err := rds.CreatePatch(&rsp.DBInstances[0], &cr.Spec.ForProvider)
if err != nil {
return managed.ExternalUpdate{}, errors.Wrap(err, errPatchCreationFailed)
}

upToDate, err := rds.IsUpToDate(ctx, e.kube, cr, rsp.DBInstances[0])
if len(patch.Tags) == 0 && upToDate && err == nil {
log.Println(cr.Name, "up to date after DescribeDBInstances")
return managed.ExternalUpdate{}, nil
}

modify := rds.GenerateModifyDBInstanceInput(meta.GetExternalName(cr), patch, cr.Spec.ForProvider.EnableCloudwatchLogsExports, rsp.DBInstances[0].EnabledCloudwatchLogsExports)
var conn managed.ConnectionDetails

Expand Down
21 changes: 20 additions & 1 deletion pkg/controller/database/rdsinstance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -863,11 +863,30 @@ func TestUpdate(t *testing.T) {
}, nil
},
},
cr: instance(withBackupRetentionPeriod(7)),
},
want: want{
cr: instance(withBackupRetentionPeriod(7)),
err: awsclient.Wrap(errBoom, errModifyFailed),
},
},
"NotCallingModifyWithoutModifications": {
args: args{
rds: &fake.MockRDSClient{
MockModify: func(ctx context.Context, input *awsrds.ModifyDBInstanceInput, opts []func(*awsrds.Options)) (*awsrds.ModifyDBInstanceOutput, error) {
return nil, errors.New("should not be called")
},
MockDescribe: func(ctx context.Context, input *awsrds.DescribeDBInstancesInput, opts []func(*awsrds.Options)) (*awsrds.DescribeDBInstancesOutput, error) {
return &awsrds.DescribeDBInstancesOutput{
DBInstances: []awsrdstypes.DBInstance{{}},
}, nil
},
},
cr: instance(),
},
want: want{
cr: instance(),
err: awsclient.Wrap(errBoom, errModifyFailed),
err: nil,
},
},
"FailedAddTags": {
Expand Down

0 comments on commit d558b01

Please sign in to comment.