@@ -497,41 +497,53 @@ func (rm *resourceManager) updateFunctionEventInvokeConfig(
497
497
) error {
498
498
var err error
499
499
rlog := ackrtlog .FromContext (ctx )
500
- exit := rlog .Trace ("rm.updateFunctionEventInvokeConfig " )
500
+ exit := rlog .Trace ("rm.syncEventInvokeConfig " )
501
501
defer exit (err )
502
502
503
+ // Check if the user deleted the 'FunctionEventInvokeConfig' configuration
504
+ // If yes, delete FunctionEventInvokeConfig
505
+ if desired .ko .Spec .FunctionEventInvokeConfig == nil {
506
+ input_delete := & svcsdk.DeleteFunctionEventInvokeConfigInput {
507
+ FunctionName : aws .String (* desired .ko .Spec .Name ),
508
+ }
509
+ _ , err = rm .sdkapi .DeleteFunctionEventInvokeConfigWithContext (ctx , input_delete )
510
+ rm .metrics .RecordAPICall ("DELETE" , "DeleteFunctionEventInvokeConfig" , err )
511
+ if err != nil {
512
+ return err
513
+ }
514
+ return nil
515
+ }
516
+
503
517
dspec := desired .ko .Spec
504
518
input := & svcsdk.PutFunctionEventInvokeConfigInput {
505
519
FunctionName : aws .String (* dspec .Name ),
506
520
}
507
521
508
- if desired .ko .Spec .FunctionEventInvokeConfig != nil {
509
- if desired .ko .Spec .FunctionEventInvokeConfig .MaximumEventAgeInSeconds != nil {
510
- input .MaximumEventAgeInSeconds = aws .Int64 (* desired .ko .Spec .FunctionEventInvokeConfig .MaximumEventAgeInSeconds )
511
- }
512
- if desired .ko .Spec .FunctionEventInvokeConfig .MaximumRetryAttempts != nil {
513
- input .MaximumRetryAttempts = aws .Int64 (* desired .ko .Spec .FunctionEventInvokeConfig .MaximumRetryAttempts )
514
- }
515
- if desired .ko .Spec .FunctionEventInvokeConfig .DestinationConfig != nil {
516
- destinations := & svcsdk.DestinationConfig {}
517
- if desired .ko .Spec .FunctionEventInvokeConfig .DestinationConfig .OnFailure != nil {
518
- destinations .OnFailure = & svcsdk.OnFailure {}
519
- if desired .ko .Spec .FunctionEventInvokeConfig .DestinationConfig .OnFailure .Destination != nil {
520
- destinations .OnFailure .Destination = aws .String (* desired .ko .Spec .FunctionEventInvokeConfig .DestinationConfig .OnFailure .Destination )
521
- }
522
+ if dspec .FunctionEventInvokeConfig .DestinationConfig != nil {
523
+ destinations := & svcsdk.DestinationConfig {}
524
+ if dspec .FunctionEventInvokeConfig .DestinationConfig .OnFailure != nil {
525
+ destinations .OnFailure = & svcsdk.OnFailure {}
526
+ if dspec .FunctionEventInvokeConfig .DestinationConfig .OnFailure .Destination != nil {
527
+ destinations .OnFailure .Destination = aws .String (* dspec .FunctionEventInvokeConfig .DestinationConfig .OnFailure .Destination )
522
528
}
523
- if desired . ko . Spec . FunctionEventInvokeConfig . DestinationConfig . OnSuccess != nil {
524
- destinations . OnSuccess = & svcsdk. OnSuccess {}
525
- if desired . ko . Spec . FunctionEventInvokeConfig . DestinationConfig . OnSuccess . Destination != nil {
526
- destinations . OnSuccess . Destination = aws . String ( * desired . ko . Spec . FunctionEventInvokeConfig .DestinationConfig .OnSuccess .Destination )
527
- }
529
+ }
530
+ if dspec . FunctionEventInvokeConfig . DestinationConfig . OnSuccess != nil {
531
+ destinations . OnSuccess = & svcsdk. OnSuccess {}
532
+ if dspec . FunctionEventInvokeConfig .DestinationConfig .OnSuccess .Destination != nil {
533
+ destinations . OnSuccess . Destination = aws . String ( * dspec . FunctionEventInvokeConfig . DestinationConfig . OnSuccess . Destination )
528
534
}
529
- input .DestinationConfig = destinations
530
535
}
536
+ input .DestinationConfig = destinations
537
+ }
538
+ if dspec .FunctionEventInvokeConfig .MaximumEventAgeInSeconds != nil {
539
+ input .MaximumEventAgeInSeconds = aws .Int64 (* dspec .FunctionEventInvokeConfig .MaximumEventAgeInSeconds )
540
+ }
541
+ if dspec .FunctionEventInvokeConfig .MaximumRetryAttempts != nil {
542
+ input .MaximumRetryAttempts = aws .Int64 (* dspec .FunctionEventInvokeConfig .MaximumRetryAttempts )
531
543
}
532
544
533
545
_ , err = rm .sdkapi .PutFunctionEventInvokeConfigWithContext (ctx , input )
534
- rm .metrics .RecordAPICall ("UPDATE" , "PutFunctionEventInvokeConfig " , err )
546
+ rm .metrics .RecordAPICall ("UPDATE" , "SyncEventInvokeConfig " , err )
535
547
if err != nil {
536
548
return err
537
549
}
@@ -591,16 +603,11 @@ func (rm *resourceManager) deleteFunctionCodeSigningConfig(
591
603
return nil
592
604
}
593
605
594
- // setResourceAdditionalFields will describe the fields that are not return by
595
- // GetFunctionConcurrency calls
596
- func (rm * resourceManager ) setResourceAdditionalFields (
606
+ // getFunctionConcurrency will describe the fields that are not return by GetFunctionConcurrency calls
607
+ func (rm * resourceManager ) getFunctionConcurrency (
597
608
ctx context.Context ,
598
609
ko * svcapitypes.Function ,
599
610
) (err error ) {
600
- rlog := ackrtlog .FromContext (ctx )
601
- exit := rlog .Trace ("rm.setResourceAdditionalFields" )
602
- defer exit (err )
603
-
604
611
var getFunctionConcurrencyOutput * svcsdk.GetFunctionConcurrencyOutput
605
612
getFunctionConcurrencyOutput , err = rm .sdkapi .GetFunctionConcurrencyWithContext (
606
613
ctx ,
@@ -614,63 +621,140 @@ func (rm *resourceManager) setResourceAdditionalFields(
614
621
}
615
622
ko .Spec .ReservedConcurrentExecutions = getFunctionConcurrencyOutput .ReservedConcurrentExecutions
616
623
617
- var getFunctionEventInvokeConfigOutput * svcsdk.GetFunctionEventInvokeConfigOutput
618
- getFunctionEventInvokeConfigOutput , err = rm .sdkapi .GetFunctionEventInvokeConfigWithContext (
624
+ return nil
625
+ }
626
+
627
+ // getFunctionCodeSigningConfig will describe the code signing
628
+ // fields for the Function resource
629
+ func (rm * resourceManager ) getFunctionCodeSigningConfig (
630
+ ctx context.Context ,
631
+ ko * svcapitypes.Function ,
632
+ ) (err error ) {
633
+ var getFunctionCodeSigningConfigOutput * svcsdk.GetFunctionCodeSigningConfigOutput
634
+ getFunctionCodeSigningConfigOutput , err = rm .sdkapi .GetFunctionCodeSigningConfigWithContext (
619
635
ctx ,
620
- & svcsdk.GetFunctionEventInvokeConfigInput {
636
+ & svcsdk.GetFunctionCodeSigningConfigInput {
621
637
FunctionName : ko .Spec .Name ,
622
638
},
623
639
)
624
- rm .metrics .RecordAPICall ("GET" , "GetFunctionEventInvokeConfig " , err )
640
+ rm .metrics .RecordAPICall ("GET" , "GetFunctionCodeSigningConfig " , err )
625
641
if err != nil {
626
- if awserr , ok := ackerr .AWSError (err ); ok && (awserr .Code () == "EventInvokeConfigNotFoundException" || awserr .Code () == "ResourceNotFoundException" ) {
642
+ return err
643
+ }
644
+ ko .Spec .CodeSigningConfigARN = getFunctionCodeSigningConfigOutput .CodeSigningConfigArn
645
+
646
+ return nil
647
+ }
648
+
649
+ func (rm * resourceManager ) setFunctionEventInvokeConfigFromResponse (
650
+ ko * svcapitypes.Function ,
651
+ getFunctionEventInvokeConfigOutput * svcsdk.GetFunctionEventInvokeConfigOutput ,
652
+ apiError error ,
653
+ ) (err error ) {
654
+
655
+ if apiError != nil {
656
+ if awserr , ok := ackerr .AWSError (apiError ); ok && (awserr .Code () == "EventInvokeConfigNotFoundException" || awserr .Code () == "ResourceNotFoundException" ) {
627
657
ko .Spec .FunctionEventInvokeConfig = nil
628
658
} else {
629
- return err
659
+ return apiError
630
660
}
631
661
} else {
632
- if getFunctionEventInvokeConfigOutput .DestinationConfig != nil {
633
- if getFunctionEventInvokeConfigOutput .DestinationConfig .OnFailure != nil {
634
- if getFunctionEventInvokeConfigOutput .DestinationConfig .OnFailure .Destination != nil {
635
- ko .Spec .FunctionEventInvokeConfig .DestinationConfig .OnFailure .Destination = getFunctionEventInvokeConfigOutput .DestinationConfig .OnFailure .Destination
662
+ if ko .Spec .FunctionEventInvokeConfig != nil {
663
+ if getFunctionEventInvokeConfigOutput .DestinationConfig != nil {
664
+ if getFunctionEventInvokeConfigOutput .DestinationConfig .OnFailure != nil {
665
+ if getFunctionEventInvokeConfigOutput .DestinationConfig .OnFailure .Destination != nil {
666
+ ko .Spec .FunctionEventInvokeConfig .DestinationConfig .OnFailure .Destination = getFunctionEventInvokeConfigOutput .DestinationConfig .OnFailure .Destination
667
+ }
636
668
}
637
- }
638
- if getFunctionEventInvokeConfigOutput .DestinationConfig .OnSuccess != nil {
639
- if getFunctionEventInvokeConfigOutput . DestinationConfig .OnSuccess .Destination != nil {
640
- ko . Spec . FunctionEventInvokeConfig . DestinationConfig . OnSuccess . Destination = getFunctionEventInvokeConfigOutput . DestinationConfig . OnSuccess . Destination
669
+ if getFunctionEventInvokeConfigOutput . DestinationConfig . OnSuccess != nil {
670
+ if getFunctionEventInvokeConfigOutput .DestinationConfig .OnSuccess . Destination != nil {
671
+ ko . Spec . FunctionEventInvokeConfig . DestinationConfig .OnSuccess .Destination = getFunctionEventInvokeConfigOutput . DestinationConfig . OnSuccess . Destination
672
+ }
641
673
}
674
+ } else {
675
+ ko .Spec .FunctionEventInvokeConfig .DestinationConfig = nil
676
+ }
677
+ if getFunctionEventInvokeConfigOutput .MaximumEventAgeInSeconds != nil {
678
+ ko .Spec .FunctionEventInvokeConfig .MaximumEventAgeInSeconds = getFunctionEventInvokeConfigOutput .MaximumEventAgeInSeconds
679
+ } else {
680
+ ko .Spec .FunctionEventInvokeConfig .MaximumEventAgeInSeconds = nil
681
+ }
682
+ if getFunctionEventInvokeConfigOutput .DestinationConfig != nil {
683
+ ko .Spec .FunctionEventInvokeConfig .MaximumRetryAttempts = getFunctionEventInvokeConfigOutput .MaximumRetryAttempts
684
+ } else {
685
+ ko .Spec .FunctionEventInvokeConfig .MaximumRetryAttempts = nil
642
686
}
643
687
} else {
644
- ko .Spec .FunctionEventInvokeConfig .DestinationConfig = nil
645
- }
646
- if getFunctionEventInvokeConfigOutput .MaximumEventAgeInSeconds != nil {
647
- ko .Spec .FunctionEventInvokeConfig .MaximumEventAgeInSeconds = getFunctionEventInvokeConfigOutput .MaximumEventAgeInSeconds
648
- } else {
649
- ko .Spec .FunctionEventInvokeConfig .MaximumEventAgeInSeconds = nil
650
- }
651
- if getFunctionEventInvokeConfigOutput .DestinationConfig != nil {
652
- ko .Spec .FunctionEventInvokeConfig .MaximumRetryAttempts = getFunctionEventInvokeConfigOutput .MaximumRetryAttempts
653
- } else {
654
- ko .Spec .FunctionEventInvokeConfig .MaximumRetryAttempts = nil
688
+ cloudFunctionEventInvokeConfig := & svcapitypes.PutFunctionEventInvokeConfigInput {}
689
+ cloudFunctionEventInvokeConfig .DestinationConfig = & svcapitypes.DestinationConfig {}
690
+ cloudFunctionEventInvokeConfig .DestinationConfig .OnFailure = & svcapitypes.OnFailure {}
691
+ cloudFunctionEventInvokeConfig .DestinationConfig .OnSuccess = & svcapitypes.OnSuccess {}
692
+ cloudFunctionEventInvokeConfig .DestinationConfig .OnFailure .Destination = getFunctionEventInvokeConfigOutput .DestinationConfig .OnFailure .Destination
693
+ cloudFunctionEventInvokeConfig .DestinationConfig .OnSuccess .Destination = getFunctionEventInvokeConfigOutput .DestinationConfig .OnSuccess .Destination
694
+ cloudFunctionEventInvokeConfig .MaximumEventAgeInSeconds = getFunctionEventInvokeConfigOutput .MaximumEventAgeInSeconds
695
+ cloudFunctionEventInvokeConfig .MaximumRetryAttempts = getFunctionEventInvokeConfigOutput .MaximumRetryAttempts
696
+ ko .Spec .FunctionEventInvokeConfig = cloudFunctionEventInvokeConfig
655
697
}
656
698
}
699
+ return nil
700
+ }
701
+
702
+ // getFunctionEventInvokeConfig will describe the fields that are
703
+ // custom to the Function resource
704
+ func (rm * resourceManager ) getFunctionEventInvokeConfig (
705
+ ctx context.Context ,
706
+ ko * svcapitypes.Function ,
707
+ ) (err error ) {
708
+ var getFunctionEventInvokeConfigOutput * svcsdk.GetFunctionEventInvokeConfigOutput
709
+ getFunctionEventInvokeConfigOutput , err = rm .sdkapi .GetFunctionEventInvokeConfigWithContext (
710
+ ctx ,
711
+ & svcsdk.GetFunctionEventInvokeConfigInput {
712
+ FunctionName : ko .Spec .Name ,
713
+ },
714
+ )
715
+ rm .metrics .RecordAPICall ("GET" , "GetFunctionEventInvokeConfig" , err )
716
+
717
+ err = rm .setFunctionEventInvokeConfigFromResponse (ko , getFunctionEventInvokeConfigOutput , err )
718
+ if err != nil {
719
+ return err
720
+ }
721
+
722
+ return nil
723
+ }
724
+
725
+ // setResourceAdditionalFields will describe the fields that are not return by
726
+ // API calls
727
+ func (rm * resourceManager ) setResourceAdditionalFields (
728
+ ctx context.Context ,
729
+ ko * svcapitypes.Function ,
730
+ ) (err error ) {
731
+ rlog := ackrtlog .FromContext (ctx )
732
+ exit := rlog .Trace ("rm.setResourceAdditionalFields" )
733
+ defer exit (err )
734
+
735
+ // To set Function Concurrency for the function
736
+ err = rm .getFunctionConcurrency (ctx , ko )
737
+ if err != nil {
738
+ return err
739
+ }
740
+
741
+ // To set Asynchronous Invocations for the function
742
+ err = rm .getFunctionEventInvokeConfig (ctx , ko )
743
+ if err != nil {
744
+ return err
745
+ }
746
+
747
+ // To set Code Signing Config based on the PackageType for the function
657
748
if ko .Spec .PackageType != nil && * ko .Spec .PackageType == "Zip" {
658
- var getFunctionCodeSigningConfigOutput * svcsdk.GetFunctionCodeSigningConfigOutput
659
- getFunctionCodeSigningConfigOutput , err = rm .sdkapi .GetFunctionCodeSigningConfigWithContext (
660
- ctx ,
661
- & svcsdk.GetFunctionCodeSigningConfigInput {
662
- FunctionName : ko .Spec .Name ,
663
- },
664
- )
665
- rm .metrics .RecordAPICall ("GET" , "GetFunctionCodeSigningConfig" , err )
749
+ err = rm .getFunctionCodeSigningConfig (ctx , ko )
666
750
if err != nil {
667
751
return err
668
752
}
669
- ko .Spec .CodeSigningConfigARN = getFunctionCodeSigningConfigOutput .CodeSigningConfigArn
670
753
}
671
754
if ko .Spec .PackageType != nil && * ko .Spec .PackageType == "Image" &&
672
755
ko .Spec .CodeSigningConfigARN != nil && * ko .Spec .CodeSigningConfigARN != "" {
673
756
return ackerr .NewTerminalError (ErrCannotSetFunctionCSC )
674
757
}
758
+
675
759
return nil
676
760
}
0 commit comments