Skip to content

Commit 0bc6c82

Browse files
authored
Fix PreferredBackupWindow not updating (#226)
Issue #, if available: [2512](aws-controllers-k8s/community#2512) Description of changes: - Fix type in delta check in newCustomUpdateRequestPayload() - Add test verifying PreferredBackupkWindow is correctly included in update input - Add .vscode to .gitignore By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent b71699b commit 0bc6c82

File tree

4 files changed

+110
-1
lines changed

4 files changed

+110
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
*.swp
33
*~
44
.idea
5+
.vscode
56
/docs/site
67
bin
78
build

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ require (
1515
github.com/go-logr/logr v1.4.2
1616
github.com/samber/lo v1.37.0
1717
github.com/spf13/pflag v1.0.5
18+
github.com/stretchr/testify v1.9.0
1819
k8s.io/api v0.32.1
1920
k8s.io/apimachinery v0.32.1
2021
k8s.io/client-go v0.32.1
@@ -63,6 +64,7 @@ require (
6364
github.com/modern-go/reflect2 v1.0.2 // indirect
6465
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
6566
github.com/pkg/errors v0.9.1 // indirect
67+
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
6668
github.com/prometheus/client_golang v1.19.1 // indirect
6769
github.com/prometheus/client_model v0.6.1 // indirect
6870
github.com/prometheus/common v0.55.0 // indirect

pkg/resource/db_cluster/custom_update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ func (rm *resourceManager) newCustomUpdateRequestPayload(
572572
if desired.ko.Spec.Port != nil && delta.DifferentAt("Spec.Port") {
573573
res.Port = aws.Int32(int32(*desired.ko.Spec.Port))
574574
}
575-
if desired.ko.Spec.PreferredBackupWindow != nil && delta.DifferentAt("Spec.PreferredBackupkWindow") {
575+
if desired.ko.Spec.PreferredBackupWindow != nil && delta.DifferentAt("Spec.PreferredBackupWindow") {
576576
res.PreferredBackupWindow = desired.ko.Spec.PreferredBackupWindow
577577
}
578578
if desired.ko.Spec.PreferredMaintenanceWindow != nil && delta.DifferentAt("Spec.PreferredMaintenanceWindow") {
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"). You may
4+
// not use this file except in compliance with the License. A copy of the
5+
// License is located at
6+
//
7+
// http://aws.amazon.com/apache2.0/
8+
//
9+
// or in the "license" file accompanying this file. This file is distributed
10+
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
11+
// express or implied. See the License for the specific language governing
12+
// permissions and limitations under the License.
13+
14+
package db_cluster
15+
16+
import (
17+
"context"
18+
"testing"
19+
20+
ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare"
21+
"github.com/aws/aws-sdk-go-v2/aws"
22+
"github.com/stretchr/testify/assert"
23+
24+
svcapitypes "github.com/aws-controllers-k8s/rds-controller/apis/v1alpha1"
25+
)
26+
27+
func TestNewCustomUpdateRequestPayload_PreferredBackupWindow(t *testing.T) {
28+
// Test case to verify that PreferredBackupWindow is included in the ModifyDBCluster API call
29+
// when Spec.PreferredBackupWindow is in the delta
30+
31+
// Setup
32+
rm := &resourceManager{}
33+
ctx := context.Background()
34+
35+
// Create desired resource with PreferredBackupWindow set
36+
desired := &resource{
37+
ko: &svcapitypes.DBCluster{
38+
Spec: svcapitypes.DBClusterSpec{
39+
DBClusterIdentifier: aws.String("test-cluster"),
40+
PreferredBackupWindow: aws.String("07:00-09:00"),
41+
},
42+
},
43+
}
44+
45+
// Create latest resource with different PreferredBackupWindow
46+
latest := &resource{
47+
ko: &svcapitypes.DBCluster{
48+
Spec: svcapitypes.DBClusterSpec{
49+
DBClusterIdentifier: aws.String("test-cluster"),
50+
PreferredBackupWindow: aws.String("05:00-07:00"),
51+
},
52+
},
53+
}
54+
55+
// Create delta with PreferredBackupWindow difference
56+
delta := ackcompare.NewDelta()
57+
delta.Add("Spec.PreferredBackupWindow", latest.ko.Spec.PreferredBackupWindow, desired.ko.Spec.PreferredBackupWindow)
58+
59+
// Call the function under test
60+
input, err := rm.newCustomUpdateRequestPayload(ctx, desired, latest, delta)
61+
62+
// Assertions
63+
assert.NoError(t, err)
64+
assert.NotNil(t, input)
65+
assert.Equal(t, *desired.ko.Spec.PreferredBackupWindow, *input.PreferredBackupWindow)
66+
}
67+
68+
func TestNewCustomUpdateRequestPayload_PreferredBackupWindowNotInDelta(t *testing.T) {
69+
// Test case to verify that PreferredBackupWindow is NOT included in the ModifyDBCluster API call
70+
// when Spec.PreferredBackupWindow is NOT in the delta
71+
72+
// Setup
73+
rm := &resourceManager{}
74+
ctx := context.Background()
75+
76+
// Create desired resource with PreferredBackupWindow set
77+
desired := &resource{
78+
ko: &svcapitypes.DBCluster{
79+
Spec: svcapitypes.DBClusterSpec{
80+
DBClusterIdentifier: aws.String("test-cluster"),
81+
PreferredBackupWindow: aws.String("07:00-09:00"),
82+
},
83+
},
84+
}
85+
86+
// Create latest resource with same PreferredBackupWindow
87+
latest := &resource{
88+
ko: &svcapitypes.DBCluster{
89+
Spec: svcapitypes.DBClusterSpec{
90+
DBClusterIdentifier: aws.String("test-cluster"),
91+
PreferredBackupWindow: aws.String("07:00-09:00"),
92+
},
93+
},
94+
}
95+
96+
// Create delta without PreferredBackupWindow difference
97+
delta := ackcompare.NewDelta()
98+
99+
// Call the function under test
100+
input, err := rm.newCustomUpdateRequestPayload(ctx, desired, latest, delta)
101+
102+
// Assertions
103+
assert.NoError(t, err)
104+
assert.NotNil(t, input)
105+
assert.Nil(t, input.PreferredBackupWindow)
106+
}

0 commit comments

Comments
 (0)