@@ -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.
4961func 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+ }
0 commit comments