From d558b01e1e314d2224338e573af873e5c5fb1895 Mon Sep 17 00:00:00 2001 From: Carl Henrik Lunde Date: Tue, 20 Feb 2024 21:25:33 +0100 Subject: [PATCH] Dont do empty "modify" calls for Can be triggered every time auto-generated tags are removed --- pkg/controller/database/rdsinstance.go | 9 +++++++++ pkg/controller/database/rdsinstance_test.go | 21 ++++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/pkg/controller/database/rdsinstance.go b/pkg/controller/database/rdsinstance.go index 4296db473f..172ca26e7e 100644 --- a/pkg/controller/database/rdsinstance.go +++ b/pkg/controller/database/rdsinstance.go @@ -18,6 +18,7 @@ package database import ( "context" + "log" "reflect" "sort" @@ -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 diff --git a/pkg/controller/database/rdsinstance_test.go b/pkg/controller/database/rdsinstance_test.go index e8e2725e20..ed8a1a27d9 100644 --- a/pkg/controller/database/rdsinstance_test.go +++ b/pkg/controller/database/rdsinstance_test.go @@ -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": {