Skip to content

Commit 3499451

Browse files
authored
Nil check for IsSync (#308)
Issue #, if available: aws-controllers-k8s/community#1231 Description of changes: Nil check fix for IsSync needed for MemoryDB and Fixed a compare ignore bug. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 0b5dc38 commit 3499451

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

pkg/generate/code/synced.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,12 @@ func scalarFieldEqual(
121121
) string {
122122
out := ""
123123
fieldPath := fmt.Sprintf("%s.%s", resVarName, *condCfg.Path)
124-
124+
// if r.ko.Status.Status == nil
125+
out += fmt.Sprintf("\tif %s == nil {\n", fieldPath)
126+
// return false, nil
127+
out += "\t\treturn false, nil\n"
128+
// }
129+
out += "\t}\n"
125130
valuesSlice := ""
126131
switch goType {
127132
case "string":
@@ -174,9 +179,8 @@ func fieldPathSafeEqual(
174179
subFieldPath := rootPath
175180
for index, shape := range shapes {
176181
if index == len(shapes)-1 {
177-
// Some aws-sdk-go scalar shapes don't contain the real name of a shape
178-
// In this case we use the full path given in condition.Path
179-
subFieldPath = fmt.Sprintf("%s.%s", resVarName, *condCfg.Path)
182+
// We would check for nil in scalarFieldEqual method so no need to loop anymore
183+
break
180184
} else {
181185
subFieldPath += "." + shape.Shape.ShapeName
182186
}

pkg/generate/code/synced_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,23 @@ func TestSyncedLambdaFunction(t *testing.T) {
3333
require.NotNil(crd)
3434

3535
expectedSyncedConditions := `
36+
if r.ko.Status.State == nil {
37+
return false, nil
38+
}
3639
stateCandidates := []string{"AVAILABLE", "ACTIVE"}
3740
if !ackutil.InStrings(*r.ko.Status.State, stateCandidates) {
3841
return false, nil
3942
}
43+
if r.ko.Status.LastUpdateStatus == nil {
44+
return false, nil
45+
}
4046
lastUpdateStatusCandidates := []string{"AVAILABLE", "ACTIVE"}
4147
if !ackutil.InStrings(*r.ko.Status.LastUpdateStatus, lastUpdateStatusCandidates) {
4248
return false, nil
4349
}
50+
if r.ko.Status.CodeSize == nil {
51+
return false, nil
52+
}
4453
codeSizeCandidates := []int{1, 2}
4554
if !ackutil.InStrings(*r.ko.Status.CodeSize, codeSizeCandidates) {
4655
return false, nil
@@ -64,6 +73,9 @@ func TestSyncedDynamodbTable(t *testing.T) {
6473
require.NotNil(crd)
6574

6675
expectedSyncedConditions := `
76+
if r.ko.Status.TableStatus == nil {
77+
return false, nil
78+
}
6779
tableStatusCandidates := []string{"AVAILABLE", "ACTIVE"}
6880
if !ackutil.InStrings(*r.ko.Status.TableStatus, tableStatusCandidates) {
6981
return false, nil
@@ -78,6 +90,9 @@ func TestSyncedDynamodbTable(t *testing.T) {
7890
if !ackutil.InStrings(*r.ko.Spec.ProvisionedThroughput.ReadCapacityUnits, provisionedThroughputCandidates) {
7991
return false, nil
8092
}
93+
if r.ko.Status.ItemCount == nil {
94+
return false, nil
95+
}
8196
itemCountCandidates := []int{0}
8297
if !ackutil.InStrings(*r.ko.Status.ItemCount, itemCountCandidates) {
8398
return false, nil

0 commit comments

Comments
 (0)