forked from aws-controllers-k8s/code-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdk_update.go.tpl
71 lines (69 loc) · 2.23 KB
/
sdk_update.go.tpl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
{{- define "sdk_update" -}}
func (rm *resourceManager) sdkUpdate(
ctx context.Context,
desired *resource,
latest *resource,
delta *ackcompare.Delta,
) (updated *resource, err error) {
rlog := ackrtlog.FromContext(ctx)
exit := rlog.Trace("rm.sdkUpdate")
defer func() {
exit(err)
}()
{{- if $hookCode := Hook .CRD "sdk_update_pre_build_request" }}
{{ $hookCode }}
{{- end }}
{{- if $customMethod := .CRD.GetCustomImplementation .CRD.Ops.Update }}
updated, err = rm.{{ $customMethod }}(ctx, desired, latest, delta)
if updated != nil || err != nil {
return updated, err
}
{{- end }}
input, err := rm.newUpdateRequestPayload(ctx, desired, delta)
if err != nil {
return nil, err
}
{{- if $hookCode := Hook .CRD "sdk_update_post_build_request" }}
{{ $hookCode }}
{{- end }}
var resp {{ .CRD.GetOutputShapeGoType .CRD.Ops.Update }}; _ = resp;
resp, err = rm.sdkapi.{{ .CRD.Ops.Update.ExportedName }}WithContext(ctx, input)
{{- if $hookCode := Hook .CRD "sdk_update_post_request" }}
{{ $hookCode }}
{{- end }}
rm.metrics.RecordAPICall("UPDATE", "{{ .CRD.Ops.Update.ExportedName }}", err)
if err != nil {
return nil, err
}
// Merge in the information we read from the API call above to the copy of
// the original Kubernetes object we passed to the function
ko := desired.ko.DeepCopy()
{{- if $hookCode := Hook .CRD "sdk_update_pre_set_output" }}
{{ $hookCode }}
{{- end }}
{{ GoCodeSetUpdateOutput .CRD "resp" "ko" 1 }}
rm.setStatusDefaults(ko)
{{- if $setOutputCustomMethodName := .CRD.SetOutputCustomMethodName .CRD.Ops.Update }}
// custom set output from response
ko, err = rm.{{ $setOutputCustomMethodName }}(ctx, desired, resp, ko)
if err != nil {
return nil, err
}
{{- end }}
{{- if $hookCode := Hook .CRD "sdk_update_post_set_output" }}
{{ $hookCode }}
{{- end }}
return &resource{ko}, nil
}
// newUpdateRequestPayload returns an SDK-specific struct for the HTTP request
// payload of the Update API call for the resource
func (rm *resourceManager) newUpdateRequestPayload(
ctx context.Context,
r *resource,
delta *ackcompare.Delta,
) (*svcsdk.{{ .CRD.Ops.Update.InputRef.Shape.ShapeName }}, error) {
res := &svcsdk.{{ .CRD.Ops.Update.InputRef.Shape.ShapeName }}{}
{{ GoCodeSetUpdateInput .CRD "r.ko" "res" 1 }}
return res, nil
}
{{- end -}}