Skip to content

Commit d7a272d

Browse files
authored
Merge pull request #2284 from crossplane-contrib/backport-2283-to-release-0.57
[Backport release-0.57] Add EnableCloudwatchLogsExports in isUpToDate and ModifyDBCluster
2 parents e2d9d4c + d816ccf commit d7a272d

2 files changed

Lines changed: 150 additions & 14 deletions

File tree

pkg/controller/rds/dbcluster/setup.go

Lines changed: 72 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,23 +45,22 @@ type custom struct {
4545
client svcsdkapi.RDSAPI
4646
}
4747

48+
func setupExternal(e *external) {
49+
h := &custom{client: e.client, kube: e.kube}
50+
e.preObserve = preObserve
51+
e.postObserve = h.postObserve
52+
e.isUpToDate = h.isUpToDate
53+
e.preUpdate = h.preUpdate
54+
e.postUpdate = h.postUpdate
55+
e.preCreate = h.preCreate
56+
e.preDelete = preDelete
57+
e.filterList = filterList
58+
}
59+
4860
// SetupDBCluster adds a controller that reconciles DbCluster.
4961
func SetupDBCluster(mgr ctrl.Manager, o controller.Options) error {
5062
name := managed.ControllerName(svcapitypes.DBClusterGroupKind)
51-
opts := []option{
52-
func(e *external) {
53-
c := &custom{client: e.client, kube: e.kube}
54-
e.preObserve = preObserve
55-
e.postObserve = c.postObserve
56-
e.isUpToDate = c.isUpToDate
57-
e.preUpdate = c.preUpdate
58-
e.postUpdate = c.postUpdate
59-
e.preCreate = c.preCreate
60-
e.preDelete = preDelete
61-
e.postDelete = c.postDelete
62-
e.filterList = filterList
63-
},
64-
}
63+
opts := []option{setupExternal}
6564

6665
cps := []managed.ConnectionPublisher{managed.NewAPISecretPublisher(mgr.GetClient(), mgr.GetScheme())}
6766
if o.Features.Enabled(features.EnableAlphaExternalSecretStores) {
@@ -615,6 +614,10 @@ func (e *custom) isUpToDate(ctx context.Context, cr *svcapitypes.DBCluster, out
615614
return false, "", nil
616615
}
617616

617+
if !areSameElements(cr.Spec.ForProvider.EnableCloudwatchLogsExports, out.DBClusters[0].EnabledCloudwatchLogsExports) {
618+
return false, "", nil
619+
}
620+
618621
if cr.Spec.ForProvider.DBClusterParameterGroupName != nil &&
619622
pointer.StringValue(cr.Spec.ForProvider.DBClusterParameterGroupName) != pointer.StringValue(out.DBClusters[0].DBClusterParameterGroup) {
620623
return false, "", nil
@@ -775,6 +778,10 @@ func (e *custom) preUpdate(ctx context.Context, cr *svcapitypes.DBCluster, obj *
775778
obj.DBClusterIdentifier = pointer.ToOrNilIfZeroValue(meta.GetExternalName(cr))
776779
obj.ApplyImmediately = cr.Spec.ForProvider.ApplyImmediately
777780

781+
obj.CloudwatchLogsExportConfiguration = generateCloudWatchExportConfiguration(
782+
cr.Spec.ForProvider.EnableCloudwatchLogsExports,
783+
cr.Status.AtProvider.EnabledCloudwatchLogsExports)
784+
778785
desiredPassword, err := dbinstance.GetDesiredPassword(ctx, e.kube, cr)
779786
if err != nil {
780787
return errors.Wrap(err, dbinstance.ErrRetrievePasswordForUpdate)
@@ -967,3 +974,54 @@ func (e *custom) updateTags(ctx context.Context, cr *svcapitypes.DBCluster, addT
967974
return nil
968975

969976
}
977+
978+
func generateCloudWatchExportConfiguration(spec, current []*string) *svcsdk.CloudwatchLogsExportConfiguration {
979+
toEnable := []*string{}
980+
toDisable := []*string{}
981+
982+
currentMap := make(map[string]struct{}, len(current))
983+
for _, currentID := range current {
984+
currentMap[pointer.StringValue(currentID)] = struct{}{}
985+
}
986+
987+
specMap := make(map[string]struct{}, len(spec))
988+
for _, specID := range spec {
989+
key := pointer.StringValue(specID)
990+
specMap[key] = struct{}{}
991+
992+
if _, exists := currentMap[key]; !exists {
993+
toEnable = append(toEnable, specID)
994+
}
995+
}
996+
997+
for _, currentID := range current {
998+
if _, exists := specMap[pointer.StringValue(currentID)]; !exists {
999+
toDisable = append(toDisable, currentID)
1000+
}
1001+
}
1002+
1003+
return &svcsdk.CloudwatchLogsExportConfiguration{
1004+
EnableLogTypes: toEnable,
1005+
DisableLogTypes: toDisable,
1006+
}
1007+
}
1008+
1009+
func areSameElements(a1, a2 []*string) bool {
1010+
if len(a1) != len(a2) {
1011+
return false
1012+
}
1013+
1014+
m2 := make(map[string]struct{}, len(a2))
1015+
for _, s2 := range a2 {
1016+
m2[pointer.StringValue(s2)] = struct{}{}
1017+
}
1018+
1019+
for _, s1 := range a1 {
1020+
v1 := pointer.StringValue(s1)
1021+
if _, exists := m2[v1]; !exists {
1022+
return false
1023+
}
1024+
}
1025+
1026+
return true
1027+
}

pkg/controller/rds/dbcluster/setup_test.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,84 @@ func TestIsUpToDate(t *testing.T) {
835835
isUpToDate: false,
836836
},
837837
},
838+
"SameEnableCloudwatchLogsExports": {
839+
args: args{
840+
kube: test.NewMockClient(),
841+
cr: &svcapitypes.DBCluster{
842+
Spec: svcapitypes.DBClusterSpec{
843+
ForProvider: svcapitypes.DBClusterParameters{
844+
DBClusterParameterGroupName: ptr.To("default.aurora-postgresql15"),
845+
EnableCloudwatchLogsExports: []*string{
846+
ptr.To("postgresql"),
847+
},
848+
},
849+
},
850+
},
851+
out: &svcsdk.DescribeDBClustersOutput{
852+
DBClusters: []*svcsdk.DBCluster{
853+
{
854+
DBClusterParameterGroup: ptr.To("default.aurora-postgresql15"),
855+
EnabledCloudwatchLogsExports: []*string{
856+
ptr.To("postgresql"),
857+
},
858+
},
859+
},
860+
},
861+
},
862+
want: want{
863+
isUpToDate: true,
864+
},
865+
},
866+
"DifferentEnableCloudwatchLogsExportsAddExports": {
867+
args: args{
868+
kube: test.NewMockClient(),
869+
cr: &svcapitypes.DBCluster{
870+
Spec: svcapitypes.DBClusterSpec{
871+
ForProvider: svcapitypes.DBClusterParameters{
872+
DBClusterParameterGroupName: ptr.To("default.aurora-postgresql15"),
873+
EnableCloudwatchLogsExports: []*string{
874+
ptr.To("postgresql"),
875+
},
876+
},
877+
},
878+
},
879+
out: &svcsdk.DescribeDBClustersOutput{
880+
DBClusters: []*svcsdk.DBCluster{
881+
{
882+
DBClusterParameterGroup: ptr.To("default.aurora-postgresql14"),
883+
},
884+
},
885+
},
886+
},
887+
want: want{
888+
isUpToDate: false,
889+
},
890+
},
891+
"DifferentEnableCloudwatchLogsExportsRemoveExports": {
892+
args: args{
893+
kube: test.NewMockClient(),
894+
cr: &svcapitypes.DBCluster{
895+
Spec: svcapitypes.DBClusterSpec{
896+
ForProvider: svcapitypes.DBClusterParameters{
897+
DBClusterParameterGroupName: ptr.To("default.aurora-postgresql15"),
898+
},
899+
},
900+
},
901+
out: &svcsdk.DescribeDBClustersOutput{
902+
DBClusters: []*svcsdk.DBCluster{
903+
{
904+
DBClusterParameterGroup: ptr.To("default.aurora-postgresql14"),
905+
EnabledCloudwatchLogsExports: []*string{
906+
ptr.To("postgresql"),
907+
},
908+
},
909+
},
910+
},
911+
},
912+
want: want{
913+
isUpToDate: false,
914+
},
915+
},
838916
}
839917

840918
for name, tc := range cases {

0 commit comments

Comments
 (0)