-
Notifications
You must be signed in to change notification settings - Fork 14
/
sdk.go
675 lines (642 loc) · 19 KB
/
sdk.go
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
// Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License"). You may
// not use this file except in compliance with the License. A copy of the
// License is located at
//
// http://aws.amazon.com/apache2.0/
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.
// Code generated by ack-generate. DO NOT EDIT.
package api
import (
"context"
"errors"
"reflect"
"strings"
ackv1alpha1 "github.com/aws-controllers-k8s/runtime/apis/core/v1alpha1"
ackcompare "github.com/aws-controllers-k8s/runtime/pkg/compare"
ackcondition "github.com/aws-controllers-k8s/runtime/pkg/condition"
ackerr "github.com/aws-controllers-k8s/runtime/pkg/errors"
ackrtlog "github.com/aws-controllers-k8s/runtime/pkg/runtime/log"
"github.com/aws/aws-sdk-go/aws"
svcsdk "github.com/aws/aws-sdk-go/service/apigatewayv2"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
svcapitypes "github.com/aws-controllers-k8s/apigatewayv2-controller/apis/v1alpha1"
)
// Hack to avoid import errors during build...
var (
_ = &metav1.Time{}
_ = strings.ToLower("")
_ = &aws.JSONValue{}
_ = &svcsdk.ApiGatewayV2{}
_ = &svcapitypes.API{}
_ = ackv1alpha1.AWSAccountID("")
_ = &ackerr.NotFound
_ = &ackcondition.NotManagedMessage
_ = &reflect.Value{}
)
// sdkFind returns SDK-specific information about a supplied resource
func (rm *resourceManager) sdkFind(
ctx context.Context,
r *resource,
) (latest *resource, err error) {
rlog := ackrtlog.FromContext(ctx)
exit := rlog.Trace("rm.sdkFind")
defer exit(err)
// If any required fields in the input shape are missing, AWS resource is
// not created yet. Return NotFound here to indicate to callers that the
// resource isn't yet created.
if rm.requiredFieldsMissingFromReadOneInput(r) {
return nil, ackerr.NotFound
}
input, err := rm.newDescribeRequestPayload(r)
if err != nil {
return nil, err
}
var resp *svcsdk.GetApiOutput
resp, err = rm.sdkapi.GetApiWithContext(ctx, input)
rm.metrics.RecordAPICall("READ_ONE", "GetApi", err)
if err != nil {
if awsErr, ok := ackerr.AWSError(err); ok && awsErr.Code() == "NotFoundException" {
return nil, ackerr.NotFound
}
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 := r.ko.DeepCopy()
if resp.ApiEndpoint != nil {
ko.Status.APIEndpoint = resp.ApiEndpoint
} else {
ko.Status.APIEndpoint = nil
}
if resp.ApiGatewayManaged != nil {
ko.Status.APIGatewayManaged = resp.ApiGatewayManaged
} else {
ko.Status.APIGatewayManaged = nil
}
if resp.ApiId != nil {
ko.Status.APIID = resp.ApiId
} else {
ko.Status.APIID = nil
}
if resp.ApiKeySelectionExpression != nil {
ko.Spec.APIKeySelectionExpression = resp.ApiKeySelectionExpression
} else {
ko.Spec.APIKeySelectionExpression = nil
}
if resp.CorsConfiguration != nil {
f4 := &svcapitypes.CORS{}
if resp.CorsConfiguration.AllowCredentials != nil {
f4.AllowCredentials = resp.CorsConfiguration.AllowCredentials
}
if resp.CorsConfiguration.AllowHeaders != nil {
f4f1 := []*string{}
for _, f4f1iter := range resp.CorsConfiguration.AllowHeaders {
var f4f1elem string
f4f1elem = *f4f1iter
f4f1 = append(f4f1, &f4f1elem)
}
f4.AllowHeaders = f4f1
}
if resp.CorsConfiguration.AllowMethods != nil {
f4f2 := []*string{}
for _, f4f2iter := range resp.CorsConfiguration.AllowMethods {
var f4f2elem string
f4f2elem = *f4f2iter
f4f2 = append(f4f2, &f4f2elem)
}
f4.AllowMethods = f4f2
}
if resp.CorsConfiguration.AllowOrigins != nil {
f4f3 := []*string{}
for _, f4f3iter := range resp.CorsConfiguration.AllowOrigins {
var f4f3elem string
f4f3elem = *f4f3iter
f4f3 = append(f4f3, &f4f3elem)
}
f4.AllowOrigins = f4f3
}
if resp.CorsConfiguration.ExposeHeaders != nil {
f4f4 := []*string{}
for _, f4f4iter := range resp.CorsConfiguration.ExposeHeaders {
var f4f4elem string
f4f4elem = *f4f4iter
f4f4 = append(f4f4, &f4f4elem)
}
f4.ExposeHeaders = f4f4
}
if resp.CorsConfiguration.MaxAge != nil {
f4.MaxAge = resp.CorsConfiguration.MaxAge
}
ko.Spec.CORSConfiguration = f4
} else {
ko.Spec.CORSConfiguration = nil
}
if resp.CreatedDate != nil {
ko.Status.CreatedDate = &metav1.Time{*resp.CreatedDate}
} else {
ko.Status.CreatedDate = nil
}
if resp.Description != nil {
ko.Spec.Description = resp.Description
} else {
ko.Spec.Description = nil
}
if resp.DisableExecuteApiEndpoint != nil {
ko.Spec.DisableExecuteAPIEndpoint = resp.DisableExecuteApiEndpoint
} else {
ko.Spec.DisableExecuteAPIEndpoint = nil
}
if resp.DisableSchemaValidation != nil {
ko.Spec.DisableSchemaValidation = resp.DisableSchemaValidation
} else {
ko.Spec.DisableSchemaValidation = nil
}
if resp.ImportInfo != nil {
f9 := []*string{}
for _, f9iter := range resp.ImportInfo {
var f9elem string
f9elem = *f9iter
f9 = append(f9, &f9elem)
}
ko.Status.ImportInfo = f9
} else {
ko.Status.ImportInfo = nil
}
if resp.Name != nil {
ko.Spec.Name = resp.Name
} else {
ko.Spec.Name = nil
}
if resp.ProtocolType != nil {
ko.Spec.ProtocolType = resp.ProtocolType
} else {
ko.Spec.ProtocolType = nil
}
if resp.RouteSelectionExpression != nil {
ko.Spec.RouteSelectionExpression = resp.RouteSelectionExpression
} else {
ko.Spec.RouteSelectionExpression = nil
}
if resp.Tags != nil {
f13 := map[string]*string{}
for f13key, f13valiter := range resp.Tags {
var f13val string
f13val = *f13valiter
f13[f13key] = &f13val
}
ko.Spec.Tags = f13
} else {
ko.Spec.Tags = nil
}
if resp.Version != nil {
ko.Spec.Version = resp.Version
} else {
ko.Spec.Version = nil
}
if resp.Warnings != nil {
f15 := []*string{}
for _, f15iter := range resp.Warnings {
var f15elem string
f15elem = *f15iter
f15 = append(f15, &f15elem)
}
ko.Status.Warnings = f15
} else {
ko.Status.Warnings = nil
}
rm.setStatusDefaults(ko)
return &resource{ko}, nil
}
// requiredFieldsMissingFromReadOneInput returns true if there are any fields
// for the ReadOne Input shape that are required but not present in the
// resource's Spec or Status
func (rm *resourceManager) requiredFieldsMissingFromReadOneInput(
r *resource,
) bool {
return r.ko.Status.APIID == nil
}
// newDescribeRequestPayload returns SDK-specific struct for the HTTP request
// payload of the Describe API call for the resource
func (rm *resourceManager) newDescribeRequestPayload(
r *resource,
) (*svcsdk.GetApiInput, error) {
res := &svcsdk.GetApiInput{}
if r.ko.Status.APIID != nil {
res.SetApiId(*r.ko.Status.APIID)
}
return res, nil
}
// sdkCreate creates the supplied resource in the backend AWS service API and
// returns a copy of the resource with resource fields (in both Spec and
// Status) filled in with values from the CREATE API operation's Output shape.
func (rm *resourceManager) sdkCreate(
ctx context.Context,
desired *resource,
) (created *resource, err error) {
rlog := ackrtlog.FromContext(ctx)
exit := rlog.Trace("rm.sdkCreate")
defer exit(err)
created, err = rm.customCreateApi(ctx, desired)
if created != nil || err != nil {
return created, err
}
input, err := rm.newCreateRequestPayload(ctx, desired)
if err != nil {
return nil, err
}
var resp *svcsdk.CreateApiOutput
_ = resp
resp, err = rm.sdkapi.CreateApiWithContext(ctx, input)
rm.metrics.RecordAPICall("CREATE", "CreateApi", 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 resp.ApiEndpoint != nil {
ko.Status.APIEndpoint = resp.ApiEndpoint
} else {
ko.Status.APIEndpoint = nil
}
if resp.ApiGatewayManaged != nil {
ko.Status.APIGatewayManaged = resp.ApiGatewayManaged
} else {
ko.Status.APIGatewayManaged = nil
}
if resp.ApiId != nil {
ko.Status.APIID = resp.ApiId
} else {
ko.Status.APIID = nil
}
if resp.ApiKeySelectionExpression != nil {
ko.Spec.APIKeySelectionExpression = resp.ApiKeySelectionExpression
} else {
ko.Spec.APIKeySelectionExpression = nil
}
if resp.CorsConfiguration != nil {
f4 := &svcapitypes.CORS{}
if resp.CorsConfiguration.AllowCredentials != nil {
f4.AllowCredentials = resp.CorsConfiguration.AllowCredentials
}
if resp.CorsConfiguration.AllowHeaders != nil {
f4f1 := []*string{}
for _, f4f1iter := range resp.CorsConfiguration.AllowHeaders {
var f4f1elem string
f4f1elem = *f4f1iter
f4f1 = append(f4f1, &f4f1elem)
}
f4.AllowHeaders = f4f1
}
if resp.CorsConfiguration.AllowMethods != nil {
f4f2 := []*string{}
for _, f4f2iter := range resp.CorsConfiguration.AllowMethods {
var f4f2elem string
f4f2elem = *f4f2iter
f4f2 = append(f4f2, &f4f2elem)
}
f4.AllowMethods = f4f2
}
if resp.CorsConfiguration.AllowOrigins != nil {
f4f3 := []*string{}
for _, f4f3iter := range resp.CorsConfiguration.AllowOrigins {
var f4f3elem string
f4f3elem = *f4f3iter
f4f3 = append(f4f3, &f4f3elem)
}
f4.AllowOrigins = f4f3
}
if resp.CorsConfiguration.ExposeHeaders != nil {
f4f4 := []*string{}
for _, f4f4iter := range resp.CorsConfiguration.ExposeHeaders {
var f4f4elem string
f4f4elem = *f4f4iter
f4f4 = append(f4f4, &f4f4elem)
}
f4.ExposeHeaders = f4f4
}
if resp.CorsConfiguration.MaxAge != nil {
f4.MaxAge = resp.CorsConfiguration.MaxAge
}
ko.Spec.CORSConfiguration = f4
} else {
ko.Spec.CORSConfiguration = nil
}
if resp.CreatedDate != nil {
ko.Status.CreatedDate = &metav1.Time{*resp.CreatedDate}
} else {
ko.Status.CreatedDate = nil
}
if resp.Description != nil {
ko.Spec.Description = resp.Description
} else {
ko.Spec.Description = nil
}
if resp.DisableExecuteApiEndpoint != nil {
ko.Spec.DisableExecuteAPIEndpoint = resp.DisableExecuteApiEndpoint
} else {
ko.Spec.DisableExecuteAPIEndpoint = nil
}
if resp.DisableSchemaValidation != nil {
ko.Spec.DisableSchemaValidation = resp.DisableSchemaValidation
} else {
ko.Spec.DisableSchemaValidation = nil
}
if resp.ImportInfo != nil {
f9 := []*string{}
for _, f9iter := range resp.ImportInfo {
var f9elem string
f9elem = *f9iter
f9 = append(f9, &f9elem)
}
ko.Status.ImportInfo = f9
} else {
ko.Status.ImportInfo = nil
}
if resp.Name != nil {
ko.Spec.Name = resp.Name
} else {
ko.Spec.Name = nil
}
if resp.ProtocolType != nil {
ko.Spec.ProtocolType = resp.ProtocolType
} else {
ko.Spec.ProtocolType = nil
}
if resp.RouteSelectionExpression != nil {
ko.Spec.RouteSelectionExpression = resp.RouteSelectionExpression
} else {
ko.Spec.RouteSelectionExpression = nil
}
if resp.Tags != nil {
f13 := map[string]*string{}
for f13key, f13valiter := range resp.Tags {
var f13val string
f13val = *f13valiter
f13[f13key] = &f13val
}
ko.Spec.Tags = f13
} else {
ko.Spec.Tags = nil
}
if resp.Version != nil {
ko.Spec.Version = resp.Version
} else {
ko.Spec.Version = nil
}
if resp.Warnings != nil {
f15 := []*string{}
for _, f15iter := range resp.Warnings {
var f15elem string
f15elem = *f15iter
f15 = append(f15, &f15elem)
}
ko.Status.Warnings = f15
} else {
ko.Status.Warnings = nil
}
rm.setStatusDefaults(ko)
return &resource{ko}, nil
}
// newCreateRequestPayload returns an SDK-specific struct for the HTTP request
// payload of the Create API call for the resource
func (rm *resourceManager) newCreateRequestPayload(
ctx context.Context,
r *resource,
) (*svcsdk.CreateApiInput, error) {
res := &svcsdk.CreateApiInput{}
if r.ko.Spec.APIKeySelectionExpression != nil {
res.SetApiKeySelectionExpression(*r.ko.Spec.APIKeySelectionExpression)
}
if r.ko.Spec.CORSConfiguration != nil {
f1 := &svcsdk.Cors{}
if r.ko.Spec.CORSConfiguration.AllowCredentials != nil {
f1.SetAllowCredentials(*r.ko.Spec.CORSConfiguration.AllowCredentials)
}
if r.ko.Spec.CORSConfiguration.AllowHeaders != nil {
f1f1 := []*string{}
for _, f1f1iter := range r.ko.Spec.CORSConfiguration.AllowHeaders {
var f1f1elem string
f1f1elem = *f1f1iter
f1f1 = append(f1f1, &f1f1elem)
}
f1.SetAllowHeaders(f1f1)
}
if r.ko.Spec.CORSConfiguration.AllowMethods != nil {
f1f2 := []*string{}
for _, f1f2iter := range r.ko.Spec.CORSConfiguration.AllowMethods {
var f1f2elem string
f1f2elem = *f1f2iter
f1f2 = append(f1f2, &f1f2elem)
}
f1.SetAllowMethods(f1f2)
}
if r.ko.Spec.CORSConfiguration.AllowOrigins != nil {
f1f3 := []*string{}
for _, f1f3iter := range r.ko.Spec.CORSConfiguration.AllowOrigins {
var f1f3elem string
f1f3elem = *f1f3iter
f1f3 = append(f1f3, &f1f3elem)
}
f1.SetAllowOrigins(f1f3)
}
if r.ko.Spec.CORSConfiguration.ExposeHeaders != nil {
f1f4 := []*string{}
for _, f1f4iter := range r.ko.Spec.CORSConfiguration.ExposeHeaders {
var f1f4elem string
f1f4elem = *f1f4iter
f1f4 = append(f1f4, &f1f4elem)
}
f1.SetExposeHeaders(f1f4)
}
if r.ko.Spec.CORSConfiguration.MaxAge != nil {
f1.SetMaxAge(*r.ko.Spec.CORSConfiguration.MaxAge)
}
res.SetCorsConfiguration(f1)
}
if r.ko.Spec.CredentialsARN != nil {
res.SetCredentialsArn(*r.ko.Spec.CredentialsARN)
}
if r.ko.Spec.Description != nil {
res.SetDescription(*r.ko.Spec.Description)
}
if r.ko.Spec.DisableExecuteAPIEndpoint != nil {
res.SetDisableExecuteApiEndpoint(*r.ko.Spec.DisableExecuteAPIEndpoint)
}
if r.ko.Spec.DisableSchemaValidation != nil {
res.SetDisableSchemaValidation(*r.ko.Spec.DisableSchemaValidation)
}
if r.ko.Spec.Name != nil {
res.SetName(*r.ko.Spec.Name)
}
if r.ko.Spec.ProtocolType != nil {
res.SetProtocolType(*r.ko.Spec.ProtocolType)
}
if r.ko.Spec.RouteKey != nil {
res.SetRouteKey(*r.ko.Spec.RouteKey)
}
if r.ko.Spec.RouteSelectionExpression != nil {
res.SetRouteSelectionExpression(*r.ko.Spec.RouteSelectionExpression)
}
if r.ko.Spec.Tags != nil {
f10 := map[string]*string{}
for f10key, f10valiter := range r.ko.Spec.Tags {
var f10val string
f10val = *f10valiter
f10[f10key] = &f10val
}
res.SetTags(f10)
}
if r.ko.Spec.Target != nil {
res.SetTarget(*r.ko.Spec.Target)
}
if r.ko.Spec.Version != nil {
res.SetVersion(*r.ko.Spec.Version)
}
return res, nil
}
// sdkUpdate patches the supplied resource in the backend AWS service API and
// returns a new resource with updated fields.
func (rm *resourceManager) sdkUpdate(
ctx context.Context,
desired *resource,
latest *resource,
delta *ackcompare.Delta,
) (*resource, error) {
return rm.customUpdateApi(ctx, desired, latest, delta)
}
// sdkDelete deletes the supplied resource in the backend AWS service API
func (rm *resourceManager) sdkDelete(
ctx context.Context,
r *resource,
) (latest *resource, err error) {
rlog := ackrtlog.FromContext(ctx)
exit := rlog.Trace("rm.sdkDelete")
defer exit(err)
input, err := rm.newDeleteRequestPayload(r)
if err != nil {
return nil, err
}
var resp *svcsdk.DeleteApiOutput
_ = resp
resp, err = rm.sdkapi.DeleteApiWithContext(ctx, input)
rm.metrics.RecordAPICall("DELETE", "DeleteApi", err)
return nil, err
}
// newDeleteRequestPayload returns an SDK-specific struct for the HTTP request
// payload of the Delete API call for the resource
func (rm *resourceManager) newDeleteRequestPayload(
r *resource,
) (*svcsdk.DeleteApiInput, error) {
res := &svcsdk.DeleteApiInput{}
if r.ko.Status.APIID != nil {
res.SetApiId(*r.ko.Status.APIID)
}
return res, nil
}
// setStatusDefaults sets default properties into supplied custom resource
func (rm *resourceManager) setStatusDefaults(
ko *svcapitypes.API,
) {
if ko.Status.ACKResourceMetadata == nil {
ko.Status.ACKResourceMetadata = &ackv1alpha1.ResourceMetadata{}
}
if ko.Status.ACKResourceMetadata.Region == nil {
ko.Status.ACKResourceMetadata.Region = &rm.awsRegion
}
if ko.Status.ACKResourceMetadata.OwnerAccountID == nil {
ko.Status.ACKResourceMetadata.OwnerAccountID = &rm.awsAccountID
}
if ko.Status.Conditions == nil {
ko.Status.Conditions = []*ackv1alpha1.Condition{}
}
}
// updateConditions returns updated resource, true; if conditions were updated
// else it returns nil, false
func (rm *resourceManager) updateConditions(
r *resource,
onSuccess bool,
err error,
) (*resource, bool) {
ko := r.ko.DeepCopy()
rm.setStatusDefaults(ko)
// Terminal condition
var terminalCondition *ackv1alpha1.Condition = nil
var recoverableCondition *ackv1alpha1.Condition = nil
var syncCondition *ackv1alpha1.Condition = nil
for _, condition := range ko.Status.Conditions {
if condition.Type == ackv1alpha1.ConditionTypeTerminal {
terminalCondition = condition
}
if condition.Type == ackv1alpha1.ConditionTypeRecoverable {
recoverableCondition = condition
}
if condition.Type == ackv1alpha1.ConditionTypeResourceSynced {
syncCondition = condition
}
}
var termError *ackerr.TerminalError
if rm.terminalAWSError(err) || err == ackerr.SecretTypeNotSupported || err == ackerr.SecretNotFound || errors.As(err, &termError) {
if terminalCondition == nil {
terminalCondition = &ackv1alpha1.Condition{
Type: ackv1alpha1.ConditionTypeTerminal,
}
ko.Status.Conditions = append(ko.Status.Conditions, terminalCondition)
}
var errorMessage = ""
if err == ackerr.SecretTypeNotSupported || err == ackerr.SecretNotFound || errors.As(err, &termError) {
errorMessage = err.Error()
} else {
awsErr, _ := ackerr.AWSError(err)
errorMessage = awsErr.Error()
}
terminalCondition.Status = corev1.ConditionTrue
terminalCondition.Message = &errorMessage
} else {
// Clear the terminal condition if no longer present
if terminalCondition != nil {
terminalCondition.Status = corev1.ConditionFalse
terminalCondition.Message = nil
}
// Handling Recoverable Conditions
if err != nil {
if recoverableCondition == nil {
// Add a new Condition containing a non-terminal error
recoverableCondition = &ackv1alpha1.Condition{
Type: ackv1alpha1.ConditionTypeRecoverable,
}
ko.Status.Conditions = append(ko.Status.Conditions, recoverableCondition)
}
recoverableCondition.Status = corev1.ConditionTrue
awsErr, _ := ackerr.AWSError(err)
errorMessage := err.Error()
if awsErr != nil {
errorMessage = awsErr.Error()
}
recoverableCondition.Message = &errorMessage
} else if recoverableCondition != nil {
recoverableCondition.Status = corev1.ConditionFalse
recoverableCondition.Message = nil
}
}
// Required to avoid the "declared but not used" error in the default case
_ = syncCondition
if terminalCondition != nil || recoverableCondition != nil || syncCondition != nil {
return &resource{ko}, true // updated
}
return nil, false // not updated
}
// terminalAWSError returns awserr, true; if the supplied error is an aws Error type
// and if the exception indicates that it is a Terminal exception
// 'Terminal' exception are specified in generator configuration
func (rm *resourceManager) terminalAWSError(err error) bool {
// No terminal_errors specified for this resource in generator config
return false
}