Skip to content

Commit 8989b61

Browse files
committed
Fix no modification issue during sdkUpdate
1 parent cb50e3b commit 8989b61

File tree

5 files changed

+135
-104
lines changed

5 files changed

+135
-104
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
ack_generate_info:
2-
build_date: "2023-03-07T21:35:18Z"
2+
build_date: "2023-03-10T16:25:28Z"
33
build_hash: 910a8e0744a99c5c87d8c1615926985215a60d8c
44
go_version: go1.19
55
version: v0.24.3
66
api_directory_checksum: 885f952f7ca2ce7a676b9bbf8eb262de71de6238
77
api_version: v1alpha1
88
aws_sdk_go_version: v1.44.93
99
generator_config_info:
10-
file_checksum: 2461349a2827ec98ae7440fbff3301c1effcfaf4
10+
file_checksum: 19e3570173a799e42f3238ed3f213a72b9840fca
1111
original_file_name: generator.yaml
1212
last_modification:
1313
reason: API generation

apis/v1alpha1/generator.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ resources:
1818
from:
1919
operation: DescribeEvents
2020
path: Events
21+
update_operation:
22+
custom_method_name: customUpdateCacheSubnetGroup
2123
ReplicationGroup:
2224
exceptions:
2325
terminal_codes:

generator.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ resources:
1818
from:
1919
operation: DescribeEvents
2020
path: Events
21+
update_operation:
22+
custom_method_name: customUpdateCacheSubnetGroup
2123
ReplicationGroup:
2224
exceptions:
2325
terminal_codes:
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
package cache_subnet_group
2+
3+
import (
4+
"context"
5+
6+
svcapitypes "github.com/aws-controllers-k8s/elasticache-controller/apis/v1alpha1"
7+
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
8+
ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare"
9+
ackrtlog "github.com/aws-controllers-k8s/runtime/pkg/runtime/log"
10+
"github.com/aws/aws-sdk-go/aws/awserr"
11+
svcsdk "github.com/aws/aws-sdk-go/service/elasticache"
12+
)
13+
14+
func (rm *resourceManager) customUpdateCacheSubnetGroup(
15+
ctx context.Context,
16+
desired *resource,
17+
latest *resource,
18+
delta *ackcompare.Delta,
19+
) (updated *resource, err error) {
20+
rlog := ackrtlog.FromContext(ctx)
21+
exit := rlog.Trace("rm.sdkUpdate")
22+
defer func() {
23+
exit(err)
24+
}()
25+
input, err := rm.newUpdateRequestPayload(ctx, desired, delta)
26+
if err != nil {
27+
return nil, err
28+
}
29+
30+
var resp *svcsdk.ModifyCacheSubnetGroupOutput
31+
_ = resp
32+
resp, err = rm.sdkapi.ModifyCacheSubnetGroupWithContext(ctx, input)
33+
rm.metrics.RecordAPICall("UPDATE", "ModifyCacheSubnetGroup", err)
34+
if err != nil {
35+
if aerr, ok := err.(awserr.Error); ok {
36+
switch aerr.Message() {
37+
case "No modifications were requested.":
38+
return desired, nil
39+
}
40+
}
41+
return nil, err
42+
}
43+
// Merge in the information we read from the API call above to the copy of
44+
// the original Kubernetes object we passed to the function
45+
ko := desired.ko.DeepCopy()
46+
47+
if ko.Status.ACKResourceMetadata == nil {
48+
ko.Status.ACKResourceMetadata = &ackv1alpha1.ResourceMetadata{}
49+
}
50+
if resp.CacheSubnetGroup.ARN != nil {
51+
arn := ackv1alpha1.AWSResourceName(*resp.CacheSubnetGroup.ARN)
52+
ko.Status.ACKResourceMetadata.ARN = &arn
53+
}
54+
if resp.CacheSubnetGroup.CacheSubnetGroupDescription != nil {
55+
ko.Spec.CacheSubnetGroupDescription = resp.CacheSubnetGroup.CacheSubnetGroupDescription
56+
} else {
57+
ko.Spec.CacheSubnetGroupDescription = nil
58+
}
59+
if resp.CacheSubnetGroup.CacheSubnetGroupName != nil {
60+
ko.Spec.CacheSubnetGroupName = resp.CacheSubnetGroup.CacheSubnetGroupName
61+
} else {
62+
ko.Spec.CacheSubnetGroupName = nil
63+
}
64+
if resp.CacheSubnetGroup.Subnets != nil {
65+
f3 := []*svcapitypes.Subnet{}
66+
for _, f3iter := range resp.CacheSubnetGroup.Subnets {
67+
f3elem := &svcapitypes.Subnet{}
68+
if f3iter.SubnetAvailabilityZone != nil {
69+
f3elemf0 := &svcapitypes.AvailabilityZone{}
70+
if f3iter.SubnetAvailabilityZone.Name != nil {
71+
f3elemf0.Name = f3iter.SubnetAvailabilityZone.Name
72+
}
73+
f3elem.SubnetAvailabilityZone = f3elemf0
74+
}
75+
if f3iter.SubnetIdentifier != nil {
76+
f3elem.SubnetIdentifier = f3iter.SubnetIdentifier
77+
}
78+
if f3iter.SubnetOutpost != nil {
79+
f3elemf2 := &svcapitypes.SubnetOutpost{}
80+
if f3iter.SubnetOutpost.SubnetOutpostArn != nil {
81+
f3elemf2.SubnetOutpostARN = f3iter.SubnetOutpost.SubnetOutpostArn
82+
}
83+
f3elem.SubnetOutpost = f3elemf2
84+
}
85+
f3 = append(f3, f3elem)
86+
}
87+
ko.Status.Subnets = f3
88+
} else {
89+
ko.Status.Subnets = nil
90+
}
91+
if resp.CacheSubnetGroup.VpcId != nil {
92+
ko.Status.VPCID = resp.CacheSubnetGroup.VpcId
93+
} else {
94+
ko.Status.VPCID = nil
95+
}
96+
97+
rm.setStatusDefaults(ko)
98+
return &resource{ko}, nil
99+
}
100+
101+
// newUpdateRequestPayload returns an SDK-specific struct for the HTTP request
102+
// payload of the Update API call for the resource
103+
func (rm *resourceManager) newUpdateRequestPayload(
104+
ctx context.Context,
105+
r *resource,
106+
delta *ackcompare.Delta,
107+
) (*svcsdk.ModifyCacheSubnetGroupInput, error) {
108+
res := &svcsdk.ModifyCacheSubnetGroupInput{}
109+
110+
if r.ko.Spec.CacheSubnetGroupDescription != nil {
111+
res.SetCacheSubnetGroupDescription(*r.ko.Spec.CacheSubnetGroupDescription)
112+
}
113+
if r.ko.Spec.CacheSubnetGroupName != nil {
114+
res.SetCacheSubnetGroupName(*r.ko.Spec.CacheSubnetGroupName)
115+
}
116+
if r.ko.Spec.SubnetIDs != nil {
117+
f2 := []*string{}
118+
for _, f2iter := range r.ko.Spec.SubnetIDs {
119+
var f2elem string
120+
f2elem = *f2iter
121+
f2 = append(f2, &f2elem)
122+
}
123+
res.SetSubnetIds(f2)
124+
}
125+
126+
return res, nil
127+
}

pkg/resource/cache_subnet_group/sdk.go

Lines changed: 2 additions & 102 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)