Skip to content

Commit af1d0fa

Browse files
authored
Fix/pay per request billing mode (#55)
Issue 1595: [[dynamodb] Status always false when setting billingMode to PAY_PER_REQUEST](aws-controllers-k8s/community#1595) Description of changes: Before comparing the desire and latest status, set ProvisionedThroughput to nil(another way is to set write/readCapacityUnits to 0) when billing mode is `PAY_PER_REQUEST`. By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
1 parent 3619f05 commit af1d0fa

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

pkg/resource/table/hooks.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
ackrequeue "github.com/aws-controllers-k8s/runtime/pkg/requeue"
2525
ackrtlog "github.com/aws-controllers-k8s/runtime/pkg/runtime/log"
2626
ackutil "github.com/aws-controllers-k8s/runtime/pkg/util"
27+
"github.com/aws/aws-sdk-go/aws"
2728
svcsdk "github.com/aws/aws-sdk-go/service/dynamodb"
2829
corev1 "k8s.io/api/core/v1"
2930

@@ -418,9 +419,17 @@ func customPreCompare(
418419
a *resource,
419420
b *resource,
420421
) {
421-
// TODO(hilalymh): customDeltaFunctions for AttributeDefintions
422+
// TODO(hilalymh): customDeltaFunctions for AttributeDefinitions
422423
// TODO(hilalymh): customDeltaFunctions for GlobalSecondaryIndexes
423424

425+
// See https://github.com/aws-controllers-k8s/community/issues/1595
426+
if aws.StringValue(a.ko.Spec.BillingMode) == string(v1alpha1.BillingMode_PAY_PER_REQUEST) {
427+
a.ko.Spec.ProvisionedThroughput = nil
428+
}
429+
if aws.StringValue(b.ko.Spec.BillingMode) == string(v1alpha1.BillingMode_PAY_PER_REQUEST) {
430+
b.ko.Spec.ProvisionedThroughput = nil
431+
}
432+
424433
if len(a.ko.Spec.Tags) != len(b.ko.Spec.Tags) {
425434
delta.Add("Spec.Tags", a.ko.Spec.Tags, b.ko.Spec.Tags)
426435
} else if a.ko.Spec.Tags != nil && b.ko.Spec.Tags != nil {

pkg/resource/table/hooks_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"reflect"
1818
"testing"
1919

20+
"github.com/aws-controllers-k8s/runtime/pkg/compare"
2021
"github.com/aws/aws-sdk-go/aws"
2122

2223
"github.com/aws-controllers-k8s/dynamodb-controller/apis/v1alpha1"
@@ -130,3 +131,30 @@ func Test_computeTagsDelta(t *testing.T) {
130131
})
131132
}
132133
}
134+
135+
func Test_customPreCompare(t *testing.T) {
136+
t.Run("when billing mode is PAY_PER_REQUEST, ProvisionedThroughput should be nil", func(t *testing.T) {
137+
a := &resource{ko: &v1alpha1.Table{
138+
Spec: v1alpha1.TableSpec{
139+
BillingMode: aws.String(string(v1alpha1.BillingMode_PAY_PER_REQUEST)),
140+
ProvisionedThroughput: &v1alpha1.ProvisionedThroughput{},
141+
},
142+
}}
143+
144+
b := &resource{ko: &v1alpha1.Table{
145+
Spec: v1alpha1.TableSpec{
146+
BillingMode: aws.String(string(v1alpha1.BillingMode_PAY_PER_REQUEST)),
147+
ProvisionedThroughput: &v1alpha1.ProvisionedThroughput{},
148+
},
149+
}}
150+
delta := &compare.Delta{}
151+
customPreCompare(delta, a, b)
152+
if a.ko.Spec.ProvisionedThroughput != nil {
153+
t.Errorf("a.Spec.ProvisionedThroughput should be nil, but got %+v", a.ko.Spec.ProvisionedThroughput)
154+
}
155+
156+
if b.ko.Spec.ProvisionedThroughput != nil {
157+
t.Errorf("b.Spec.ProvisionedThroughput should be nil, but got %+v", a.ko.Spec.ProvisionedThroughput)
158+
}
159+
})
160+
}

0 commit comments

Comments
 (0)