@@ -15,6 +15,7 @@ package db_cluster
15
15
16
16
import (
17
17
"context"
18
+ "slices"
18
19
19
20
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
20
21
ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare"
@@ -63,7 +64,7 @@ func (rm *resourceManager) customUpdate(
63
64
ackcondition .SetSynced (desired , corev1 .ConditionTrue , nil , nil )
64
65
return desired , nil
65
66
}
66
- input , err := rm .newCustomUpdateRequestPayload (ctx , desired , delta )
67
+ input , err := rm .newCustomUpdateRequestPayload (ctx , desired , latest , delta )
67
68
if err != nil {
68
69
return nil , err
69
70
}
@@ -516,112 +517,142 @@ func (rm *resourceManager) customUpdate(
516
517
// https://github.com/aws-controllers-k8s/community/issues/917
517
518
func (rm * resourceManager ) newCustomUpdateRequestPayload (
518
519
ctx context.Context ,
519
- r * resource ,
520
+ desired * resource ,
521
+ latest * resource ,
520
522
delta * ackcompare.Delta ,
521
523
) (* svcsdk.ModifyDBClusterInput , error ) {
522
524
res := & svcsdk.ModifyDBClusterInput {}
523
525
524
526
res .SetApplyImmediately (true )
525
527
res .SetAllowMajorVersionUpgrade (true )
526
- if r .ko .Spec .BacktrackWindow != nil && delta .DifferentAt ("Spec.BacktrackWindow" ) {
527
- res .SetBacktrackWindow (* r .ko .Spec .BacktrackWindow )
528
+ if desired .ko .Spec .BacktrackWindow != nil && delta .DifferentAt ("Spec.BacktrackWindow" ) {
529
+ res .SetBacktrackWindow (* desired .ko .Spec .BacktrackWindow )
528
530
}
529
- if r .ko .Spec .BackupRetentionPeriod != nil && delta .DifferentAt ("Spec.BackupRetentionPeriod" ) {
530
- res .SetBackupRetentionPeriod (* r .ko .Spec .BackupRetentionPeriod )
531
+ if desired .ko .Spec .BackupRetentionPeriod != nil && delta .DifferentAt ("Spec.BackupRetentionPeriod" ) {
532
+ res .SetBackupRetentionPeriod (* desired .ko .Spec .BackupRetentionPeriod )
531
533
}
532
- if r .ko .Spec .CopyTagsToSnapshot != nil && delta .DifferentAt ("Spec.CopyTagsToSnapshot" ) {
533
- res .SetCopyTagsToSnapshot (* r .ko .Spec .CopyTagsToSnapshot )
534
+ if desired .ko .Spec .CopyTagsToSnapshot != nil && delta .DifferentAt ("Spec.CopyTagsToSnapshot" ) {
535
+ res .SetCopyTagsToSnapshot (* desired .ko .Spec .CopyTagsToSnapshot )
534
536
}
535
537
// NOTE(jaypipes): This is a required field in the input shape. If not set,
536
538
// we get back a cryptic error message "1 Validation error(s) found."
537
- if r .ko .Spec .DBClusterIdentifier != nil {
538
- res .SetDBClusterIdentifier (* r .ko .Spec .DBClusterIdentifier )
539
+ if desired .ko .Spec .DBClusterIdentifier != nil {
540
+ res .SetDBClusterIdentifier (* desired .ko .Spec .DBClusterIdentifier )
539
541
}
540
- if r .ko .Spec .DBClusterParameterGroupName != nil && delta .DifferentAt ("Spec.DBClusterParameterGroupName" ) {
541
- res .SetDBClusterParameterGroupName (* r .ko .Spec .DBClusterParameterGroupName )
542
+ if desired .ko .Spec .DBClusterParameterGroupName != nil && delta .DifferentAt ("Spec.DBClusterParameterGroupName" ) {
543
+ res .SetDBClusterParameterGroupName (* desired .ko .Spec .DBClusterParameterGroupName )
542
544
}
543
- if r .ko .Spec .DeletionProtection != nil && delta .DifferentAt ("Spec.DeletionProtection" ) {
544
- res .SetDeletionProtection (* r .ko .Spec .DeletionProtection )
545
+ if desired .ko .Spec .DeletionProtection != nil && delta .DifferentAt ("Spec.DeletionProtection" ) {
546
+ res .SetDeletionProtection (* desired .ko .Spec .DeletionProtection )
545
547
}
546
- if r .ko .Spec .Domain != nil && delta .DifferentAt ("Spec.Domain" ) {
547
- res .SetDomain (* r .ko .Spec .Domain )
548
+ if desired .ko .Spec .Domain != nil && delta .DifferentAt ("Spec.Domain" ) {
549
+ res .SetDomain (* desired .ko .Spec .Domain )
548
550
}
549
- if r .ko .Spec .DomainIAMRoleName != nil && delta .DifferentAt ("Spec.DomainIAMRoleName" ) {
550
- res .SetDomainIAMRoleName (* r .ko .Spec .DomainIAMRoleName )
551
+ if desired .ko .Spec .DomainIAMRoleName != nil && delta .DifferentAt ("Spec.DomainIAMRoleName" ) {
552
+ res .SetDomainIAMRoleName (* desired .ko .Spec .DomainIAMRoleName )
551
553
}
552
- if r .ko .Spec .EnableGlobalWriteForwarding != nil && delta .DifferentAt ("Spec.EnableGlobalWriteForwarding" ) {
553
- res .SetEnableGlobalWriteForwarding (* r .ko .Spec .EnableGlobalWriteForwarding )
554
+ if desired .ko .Spec .EnableGlobalWriteForwarding != nil && delta .DifferentAt ("Spec.EnableGlobalWriteForwarding" ) {
555
+ res .SetEnableGlobalWriteForwarding (* desired .ko .Spec .EnableGlobalWriteForwarding )
554
556
}
555
- if r .ko .Spec .EnableHTTPEndpoint != nil && delta .DifferentAt ("Spec.EnableHTTPEndpoint" ) {
556
- res .SetEnableHttpEndpoint (* r .ko .Spec .EnableHTTPEndpoint )
557
+ if desired .ko .Spec .EnableHTTPEndpoint != nil && delta .DifferentAt ("Spec.EnableHTTPEndpoint" ) {
558
+ res .SetEnableHttpEndpoint (* desired .ko .Spec .EnableHTTPEndpoint )
557
559
}
558
- if r .ko .Spec .EnableIAMDatabaseAuthentication != nil && delta .DifferentAt ("Spec.EnableIAMDatabaseAuthentication" ) {
559
- res .SetEnableIAMDatabaseAuthentication (* r .ko .Spec .EnableIAMDatabaseAuthentication )
560
+ if desired .ko .Spec .EnableIAMDatabaseAuthentication != nil && delta .DifferentAt ("Spec.EnableIAMDatabaseAuthentication" ) {
561
+ res .SetEnableIAMDatabaseAuthentication (* desired .ko .Spec .EnableIAMDatabaseAuthentication )
560
562
}
561
- if r .ko .Spec .EngineVersion != nil && delta .DifferentAt ("Spec.EngineVersion" ) {
562
- res .SetEngineVersion (* r .ko .Spec .EngineVersion )
563
+ if desired .ko .Spec .EngineVersion != nil && delta .DifferentAt ("Spec.EngineVersion" ) {
564
+ res .SetEngineVersion (* desired .ko .Spec .EngineVersion )
563
565
}
564
- if r .ko .Spec .MasterUserPassword != nil && delta .DifferentAt ("Spec.MasterUserPassword" ) {
565
- tmpSecret , err := rm .rr .SecretValueFromReference (ctx , r .ko .Spec .MasterUserPassword )
566
+ if desired .ko .Spec .MasterUserPassword != nil && delta .DifferentAt ("Spec.MasterUserPassword" ) {
567
+ tmpSecret , err := rm .rr .SecretValueFromReference (ctx , desired .ko .Spec .MasterUserPassword )
566
568
if err != nil {
567
569
return nil , err
568
570
}
569
571
if tmpSecret != "" {
570
572
res .SetMasterUserPassword (tmpSecret )
571
573
}
572
574
}
573
- if r .ko .Spec .OptionGroupName != nil && delta .DifferentAt ("Spec.OptionGroupName" ) {
574
- res .SetOptionGroupName (* r .ko .Spec .OptionGroupName )
575
+ if desired .ko .Spec .OptionGroupName != nil && delta .DifferentAt ("Spec.OptionGroupName" ) {
576
+ res .SetOptionGroupName (* desired .ko .Spec .OptionGroupName )
575
577
}
576
- if r .ko .Spec .Port != nil && delta .DifferentAt ("Spec.Port" ) {
577
- res .SetPort (* r .ko .Spec .Port )
578
+ if desired .ko .Spec .Port != nil && delta .DifferentAt ("Spec.Port" ) {
579
+ res .SetPort (* desired .ko .Spec .Port )
578
580
}
579
- if r .ko .Spec .PreferredBackupWindow != nil && delta .DifferentAt ("Spec.PreferredBackupkWindow" ) {
580
- res .SetPreferredBackupWindow (* r .ko .Spec .PreferredBackupWindow )
581
+ if desired .ko .Spec .PreferredBackupWindow != nil && delta .DifferentAt ("Spec.PreferredBackupkWindow" ) {
582
+ res .SetPreferredBackupWindow (* desired .ko .Spec .PreferredBackupWindow )
581
583
}
582
- if r .ko .Spec .PreferredMaintenanceWindow != nil && delta .DifferentAt ("Spec.PreferredMaintenanceWindow" ) {
583
- res .SetPreferredMaintenanceWindow (* r .ko .Spec .PreferredMaintenanceWindow )
584
+ if desired .ko .Spec .PreferredMaintenanceWindow != nil && delta .DifferentAt ("Spec.PreferredMaintenanceWindow" ) {
585
+ res .SetPreferredMaintenanceWindow (* desired .ko .Spec .PreferredMaintenanceWindow )
584
586
}
585
- if r .ko .Spec .ScalingConfiguration != nil && delta .DifferentAt ("Spec.ScalingConfiguration" ) {
587
+ if desired .ko .Spec .ScalingConfiguration != nil && delta .DifferentAt ("Spec.ScalingConfiguration" ) {
586
588
f22 := & svcsdk.ScalingConfiguration {}
587
- if r .ko .Spec .ScalingConfiguration .AutoPause != nil && delta .DifferentAt ("Spec.ScalingConfiguration.AutoPause" ) {
588
- f22 .SetAutoPause (* r .ko .Spec .ScalingConfiguration .AutoPause )
589
+ if desired .ko .Spec .ScalingConfiguration .AutoPause != nil && delta .DifferentAt ("Spec.ScalingConfiguration.AutoPause" ) {
590
+ f22 .SetAutoPause (* desired .ko .Spec .ScalingConfiguration .AutoPause )
589
591
}
590
- if r .ko .Spec .ScalingConfiguration .MaxCapacity != nil && delta .DifferentAt ("Spec.ScalingConfiguration.MaxCapacity" ) {
591
- f22 .SetMaxCapacity (* r .ko .Spec .ScalingConfiguration .MaxCapacity )
592
+ if desired .ko .Spec .ScalingConfiguration .MaxCapacity != nil && delta .DifferentAt ("Spec.ScalingConfiguration.MaxCapacity" ) {
593
+ f22 .SetMaxCapacity (* desired .ko .Spec .ScalingConfiguration .MaxCapacity )
592
594
}
593
- if r .ko .Spec .ScalingConfiguration .MinCapacity != nil && delta .DifferentAt ("Spec.ScalingConfiguration.MinCapacity" ) {
594
- f22 .SetMinCapacity (* r .ko .Spec .ScalingConfiguration .MinCapacity )
595
+ if desired .ko .Spec .ScalingConfiguration .MinCapacity != nil && delta .DifferentAt ("Spec.ScalingConfiguration.MinCapacity" ) {
596
+ f22 .SetMinCapacity (* desired .ko .Spec .ScalingConfiguration .MinCapacity )
595
597
}
596
- if r .ko .Spec .ScalingConfiguration .SecondsUntilAutoPause != nil && delta .DifferentAt ("Spec.ScalingConfiguration.SecondsUntilAutoPause" ) {
597
- f22 .SetSecondsUntilAutoPause (* r .ko .Spec .ScalingConfiguration .SecondsUntilAutoPause )
598
+ if desired .ko .Spec .ScalingConfiguration .SecondsUntilAutoPause != nil && delta .DifferentAt ("Spec.ScalingConfiguration.SecondsUntilAutoPause" ) {
599
+ f22 .SetSecondsUntilAutoPause (* desired .ko .Spec .ScalingConfiguration .SecondsUntilAutoPause )
598
600
}
599
- if r .ko .Spec .ScalingConfiguration .TimeoutAction != nil && delta .DifferentAt ("Spec.ScalingConfiguration.TimeoutAction" ) {
600
- f22 .SetTimeoutAction (* r .ko .Spec .ScalingConfiguration .TimeoutAction )
601
+ if desired .ko .Spec .ScalingConfiguration .TimeoutAction != nil && delta .DifferentAt ("Spec.ScalingConfiguration.TimeoutAction" ) {
602
+ f22 .SetTimeoutAction (* desired .ko .Spec .ScalingConfiguration .TimeoutAction )
601
603
}
602
604
res .SetScalingConfiguration (f22 )
603
605
}
604
- if r .ko .Spec .VPCSecurityGroupIDs != nil && delta .DifferentAt ("Spec.VPCSecurityGroupIDs" ) {
606
+ if desired .ko .Spec .VPCSecurityGroupIDs != nil && delta .DifferentAt ("Spec.VPCSecurityGroupIDs" ) {
605
607
f23 := []* string {}
606
- for _ , f23iter := range r .ko .Spec .VPCSecurityGroupIDs {
608
+ for _ , f23iter := range desired .ko .Spec .VPCSecurityGroupIDs {
607
609
var f23elem string
608
610
f23elem = * f23iter
609
611
f23 = append (f23 , & f23elem )
610
612
}
611
613
res .SetVpcSecurityGroupIds (f23 )
612
614
}
613
615
// For ServerlessV2ScalingConfiguration, MaxCapacity and MinCapacity, both need appear in modify call to get ServerlessV2ScalingConfiguration modified
614
- if r .ko .Spec .ServerlessV2ScalingConfiguration != nil && delta .DifferentAt ("Spec.ServerlessV2ScalingConfiguration" ) {
616
+ if desired .ko .Spec .ServerlessV2ScalingConfiguration != nil && delta .DifferentAt ("Spec.ServerlessV2ScalingConfiguration" ) {
615
617
f23 := & svcsdk.ServerlessV2ScalingConfiguration {}
616
618
if delta .DifferentAt ("Spec.ServerlessV2ScalingConfiguration.MaxCapacity" ) || delta .DifferentAt ("Spec.ServerlessV2ScalingConfiguration.MinCapacity" ) {
617
- if r .ko .Spec .ServerlessV2ScalingConfiguration .MaxCapacity != nil {
618
- f23 .SetMaxCapacity (* r .ko .Spec .ServerlessV2ScalingConfiguration .MaxCapacity )
619
+ if desired .ko .Spec .ServerlessV2ScalingConfiguration .MaxCapacity != nil {
620
+ f23 .SetMaxCapacity (* desired .ko .Spec .ServerlessV2ScalingConfiguration .MaxCapacity )
619
621
}
620
- if r .ko .Spec .ServerlessV2ScalingConfiguration .MaxCapacity != nil {
621
- f23 .SetMinCapacity (* r .ko .Spec .ServerlessV2ScalingConfiguration .MinCapacity )
622
+ if desired .ko .Spec .ServerlessV2ScalingConfiguration .MaxCapacity != nil {
623
+ f23 .SetMinCapacity (* desired .ko .Spec .ServerlessV2ScalingConfiguration .MinCapacity )
622
624
}
623
625
}
624
626
res .SetServerlessV2ScalingConfiguration (f23 )
625
627
}
628
+
629
+ if delta .DifferentAt ("Spec.EnableCloudwatchLogsExports" ) {
630
+ cloudwatchLogExportsConfigDesired := desired .ko .Spec .EnableCloudwatchLogsExports
631
+ //Latest log types config
632
+ cloudwatchLogExportsConfigLatest := latest .ko .Spec .EnableCloudwatchLogsExports
633
+ logsTypesToEnable , logsTypesToDisable := getCloudwatchLogExportsConfigDifferences (cloudwatchLogExportsConfigDesired , cloudwatchLogExportsConfigLatest )
634
+ f24 := & svcsdk.CloudwatchLogsExportConfiguration {
635
+ EnableLogTypes : logsTypesToEnable ,
636
+ DisableLogTypes : logsTypesToDisable ,
637
+ }
638
+ res .SetCloudwatchLogsExportConfiguration (f24 )
639
+ }
626
640
return res , nil
627
641
}
642
+
643
+ func getCloudwatchLogExportsConfigDifferences (cloudwatchLogExportsConfigDesired []* string , cloudwatchLogExportsConfigLatest []* string ) ([]* string , []* string ) {
644
+ logsTypesToEnable := []* string {}
645
+ logsTypesToDisable := []* string {}
646
+
647
+ for _ , config := range cloudwatchLogExportsConfigDesired {
648
+ if ! slices .Contains (cloudwatchLogExportsConfigLatest , config ) {
649
+ logsTypesToEnable = append (logsTypesToEnable , config )
650
+ }
651
+ }
652
+ for _ , config := range cloudwatchLogExportsConfigLatest {
653
+ if ! slices .Contains (cloudwatchLogExportsConfigDesired , config ) {
654
+ logsTypesToDisable = append (logsTypesToDisable , config )
655
+ }
656
+ }
657
+ return logsTypesToEnable , logsTypesToDisable
658
+ }
0 commit comments