Skip to content

Commit

Permalink
Merge pull request #1768 from MisterMX/feat/docdb-delete-no-update
Browse files Browse the repository at this point in the history
fix(docdb): Exit isUpToDate early if MR is deleted
  • Loading branch information
Christopher Haar committed Jun 12, 2023
2 parents 8282408 + 56ac6ef commit 3cab2a0
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/controller/docdb/dbcluster/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ func lateInitialize(cr *svcapitypes.DBClusterParameters, resp *svcsdk.DescribeDB
}

func (e *hooks) isUpToDate(cr *svcapitypes.DBCluster, resp *svcsdk.DescribeDBClustersOutput) (bool, error) { // nolint:gocyclo
if meta.WasDeleted(cr) {
return true, nil // There is no need to check for updates when we want to delete.
}

cluster := resp.DBClusters[0]

ctx := context.Background()
Expand Down
65 changes: 65 additions & 0 deletions pkg/controller/docdb/dbcluster/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ import (
"context"
"strconv"
"testing"
"time"

"github.com/google/go-cmp/cmp"
"github.com/pkg/errors"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/aws/aws-sdk-go/aws/request"
Expand Down Expand Up @@ -86,6 +88,8 @@ var (
testErrModifyDBClusterFailed = "ModifyDBCluster failed"
testErrBoom = "boom"
testErrGetSecret = "testErrGetSecret"

timeNow = time.Now()
)

type args struct {
Expand Down Expand Up @@ -119,6 +123,12 @@ func withExternalName(value string) docDBModifier {
}
}

func withDeletionTimestamp(v *metav1.Time) docDBModifier {
return func(o *svcapitypes.DBCluster) {
o.SetDeletionTimestamp(v)
}
}

func withDBClusterIdentifier(value string) docDBModifier {
return func(o *svcapitypes.DBCluster) {
o.Status.AtProvider.DBClusterIdentifier = awsclient.String(value)
Expand Down Expand Up @@ -1695,6 +1705,61 @@ func TestObserve(t *testing.T) {
},
},
},
"AvailableState_and_Deleted_should_be_UpToDate": {
args: args{
docdb: &fake.MockDocDBClient{
MockDescribeDBClustersWithContext: func(c context.Context, ddi *docdb.DescribeDBClustersInput, o []request.Option) (*docdb.DescribeDBClustersOutput, error) {
return &docdb.DescribeDBClustersOutput{
DBClusters: []*docdb.DBCluster{
{
DBClusterIdentifier: awsclient.String(testDBClusterIdentifier),
Status: awsclient.String(svcapitypes.DocDBInstanceStateAvailable),
PreferredMaintenanceWindow: awsclient.String(testPreferredMaintenanceWindow),
},
},
}, nil
},
MockListTagsForResource: func(ltfri *docdb.ListTagsForResourceInput) (*docdb.ListTagsForResourceOutput, error) {
return &docdb.ListTagsForResourceOutput{
TagList: []*docdb.Tag{},
}, nil
},
},
cr: instance(
withDBClusterIdentifier(testDBClusterIdentifier),
withDeletionTimestamp(&metav1.Time{Time: timeNow}),
withExternalName(testDBClusterIdentifier),
withPreferredMaintenanceWindow(testOtherPreferredMaintenanceWindow),
withVpcSecurityGroupIds(),
),
},
want: want{
cr: instance(
withDBClusterIdentifier(testDBClusterIdentifier),
withDeletionTimestamp(&metav1.Time{Time: timeNow}),
withPreferredMaintenanceWindow(testOtherPreferredMaintenanceWindow),
withExternalName(testDBClusterIdentifier),
withConditions(xpv1.Available()),
withStatus(svcapitypes.DocDBInstanceStateAvailable),
withVpcSecurityGroupIds(),
),
result: managed.ExternalObservation{
ResourceExists: true,
ResourceUpToDate: true,
ConnectionDetails: generateConnectionDetails("", "", "", "", 0),
},
docdb: fake.MockDocDBClientCall{
DescribeDBClustersWithContext: []*fake.CallDescribeDBClustersWithContext{
{
Ctx: context.Background(),
I: &docdb.DescribeDBClustersInput{
DBClusterIdentifier: awsclient.String(testDBClusterIdentifier),
},
},
},
},
},
},
"Empty_DescribeClustersOutput": {
args: args{
docdb: &fake.MockDocDBClient{
Expand Down

0 comments on commit 3cab2a0

Please sign in to comment.