@@ -86,7 +86,7 @@ func (rm *resourceManager) customUpdateFunction(
86
86
}
87
87
}
88
88
if delta .DifferentAt ("Spec.FunctionEventInvokeConfig" ) {
89
- err = rm .updateFunctionEventInvokeConfig (ctx , desired )
89
+ err = rm .syncFunctionEventInvokeConfig (ctx , desired )
90
90
if err != nil {
91
91
return nil , err
92
92
}
@@ -491,7 +491,9 @@ func (rm *resourceManager) updateFunctionConcurrency(
491
491
return nil
492
492
}
493
493
494
- func (rm * resourceManager ) updateFunctionEventInvokeConfig (
494
+ // syncFunctionEventInvokeConfig calls `PutFunctionEventInvokeConfig` to update the fields
495
+ // or `DeleteFunctionEventInvokeConfig` is users removes the fields
496
+ func (rm * resourceManager ) syncFunctionEventInvokeConfig (
495
497
ctx context.Context ,
496
498
desired * resource ,
497
499
) error {
@@ -551,7 +553,7 @@ func (rm *resourceManager) updateFunctionEventInvokeConfig(
551
553
}
552
554
553
555
// updateFunctionCodeSigningConfig calls PutFunctionCodeSigningConfig to update
554
- // it code signing configuration
556
+ // the code signing configuration
555
557
func (rm * resourceManager ) updateFunctionCodeSigningConfig (
556
558
ctx context.Context ,
557
559
desired * resource ,
@@ -580,7 +582,7 @@ func (rm *resourceManager) updateFunctionCodeSigningConfig(
580
582
}
581
583
582
584
// deleteFunctionCodeSigningConfig calls deleteFunctionCodeSigningConfig to update
583
- // it code signing configuration
585
+ // the code signing configuration
584
586
func (rm * resourceManager ) deleteFunctionCodeSigningConfig (
585
587
ctx context.Context ,
586
588
desired * resource ,
@@ -603,11 +605,16 @@ func (rm *resourceManager) deleteFunctionCodeSigningConfig(
603
605
return nil
604
606
}
605
607
606
- // getFunctionConcurrency will describe the fields that are not return by GetFunctionConcurrency calls
607
- func (rm * resourceManager ) getFunctionConcurrency (
608
+ // setFunctionConcurrency sets the concurrency fields
609
+ // for the Function resource
610
+ func (rm * resourceManager ) setFunctionConcurrency (
608
611
ctx context.Context ,
609
612
ko * svcapitypes.Function ,
610
613
) (err error ) {
614
+ rlog := ackrtlog .FromContext (ctx )
615
+ exit := rlog .Trace ("rm.setFunctionConcurrency" )
616
+ defer exit (err )
617
+
611
618
var getFunctionConcurrencyOutput * svcsdk.GetFunctionConcurrencyOutput
612
619
getFunctionConcurrencyOutput , err = rm .sdkapi .GetFunctionConcurrencyWithContext (
613
620
ctx ,
@@ -624,12 +631,16 @@ func (rm *resourceManager) getFunctionConcurrency(
624
631
return nil
625
632
}
626
633
627
- // getFunctionCodeSigningConfig will describe the code signing
634
+ // setFunctionCodeSigningConfig sets the code signing
628
635
// fields for the Function resource
629
- func (rm * resourceManager ) getFunctionCodeSigningConfig (
636
+ func (rm * resourceManager ) setFunctionCodeSigningConfig (
630
637
ctx context.Context ,
631
638
ko * svcapitypes.Function ,
632
639
) (err error ) {
640
+ rlog := ackrtlog .FromContext (ctx )
641
+ exit := rlog .Trace ("rm.setFunctionCodeSigningConfig" )
642
+ defer exit (err )
643
+
633
644
var getFunctionCodeSigningConfigOutput * svcsdk.GetFunctionCodeSigningConfigOutput
634
645
getFunctionCodeSigningConfigOutput , err = rm .sdkapi .GetFunctionCodeSigningConfigWithContext (
635
646
ctx ,
@@ -649,62 +660,30 @@ func (rm *resourceManager) getFunctionCodeSigningConfig(
649
660
func (rm * resourceManager ) setFunctionEventInvokeConfigFromResponse (
650
661
ko * svcapitypes.Function ,
651
662
getFunctionEventInvokeConfigOutput * svcsdk.GetFunctionEventInvokeConfigOutput ,
652
- apiError error ,
653
- ) (err error ) {
663
+ ) {
664
+ // creating FunctionEventInvokeConfig object to store the values returned from `Get` call
665
+ cloudFunctionEventInvokeConfig := & svcapitypes.PutFunctionEventInvokeConfigInput {}
666
+ cloudFunctionEventInvokeConfig .DestinationConfig = & svcapitypes.DestinationConfig {}
667
+ cloudFunctionEventInvokeConfig .DestinationConfig .OnFailure = & svcapitypes.OnFailure {}
668
+ cloudFunctionEventInvokeConfig .DestinationConfig .OnSuccess = & svcapitypes.OnSuccess {}
669
+ cloudFunctionEventInvokeConfig .DestinationConfig .OnFailure .Destination = getFunctionEventInvokeConfigOutput .DestinationConfig .OnFailure .Destination
670
+ cloudFunctionEventInvokeConfig .DestinationConfig .OnSuccess .Destination = getFunctionEventInvokeConfigOutput .DestinationConfig .OnSuccess .Destination
671
+ cloudFunctionEventInvokeConfig .MaximumEventAgeInSeconds = getFunctionEventInvokeConfigOutput .MaximumEventAgeInSeconds
672
+ cloudFunctionEventInvokeConfig .MaximumRetryAttempts = getFunctionEventInvokeConfigOutput .MaximumRetryAttempts
673
+ ko .Spec .FunctionEventInvokeConfig = cloudFunctionEventInvokeConfig
654
674
655
- if apiError != nil {
656
- if awserr , ok := ackerr .AWSError (apiError ); ok && (awserr .Code () == "EventInvokeConfigNotFoundException" || awserr .Code () == "ResourceNotFoundException" ) {
657
- ko .Spec .FunctionEventInvokeConfig = nil
658
- } else {
659
- return apiError
660
- }
661
- } else {
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
- }
668
- }
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
- }
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
686
- }
687
- } else {
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
697
- }
698
- }
699
- return nil
700
675
}
701
676
702
- // getFunctionEventInvokeConfig will describe the fields that are
703
- // custom to the Function resource
704
- func (rm * resourceManager ) getFunctionEventInvokeConfig (
677
+ // setFunctionEventInvokeConfig sets the fields to set asynchronous invocation
678
+ // for Function resource
679
+ func (rm * resourceManager ) setFunctionEventInvokeConfig (
705
680
ctx context.Context ,
706
681
ko * svcapitypes.Function ,
707
682
) (err error ) {
683
+ rlog := ackrtlog .FromContext (ctx )
684
+ exit := rlog .Trace ("rm.setFunctionEventInvokeConfig" )
685
+ defer exit (err )
686
+
708
687
var getFunctionEventInvokeConfigOutput * svcsdk.GetFunctionEventInvokeConfigOutput
709
688
getFunctionEventInvokeConfigOutput , err = rm .sdkapi .GetFunctionEventInvokeConfigWithContext (
710
689
ctx ,
@@ -714,9 +693,14 @@ func (rm *resourceManager) getFunctionEventInvokeConfig(
714
693
)
715
694
rm .metrics .RecordAPICall ("GET" , "GetFunctionEventInvokeConfig" , err )
716
695
717
- err = rm .setFunctionEventInvokeConfigFromResponse (ko , getFunctionEventInvokeConfigOutput , err )
718
696
if err != nil {
719
- return err
697
+ if awserr , ok := ackerr .AWSError (err ); ok && (awserr .Code () == "EventInvokeConfigNotFoundException" || awserr .Code () == "ResourceNotFoundException" ) {
698
+ ko .Spec .FunctionEventInvokeConfig = nil
699
+ } else {
700
+ return err
701
+ }
702
+ } else {
703
+ rm .setFunctionEventInvokeConfigFromResponse (ko , getFunctionEventInvokeConfigOutput )
720
704
}
721
705
722
706
return nil
@@ -733,20 +717,20 @@ func (rm *resourceManager) setResourceAdditionalFields(
733
717
defer exit (err )
734
718
735
719
// To set Function Concurrency for the function
736
- err = rm .getFunctionConcurrency (ctx , ko )
720
+ err = rm .setFunctionConcurrency (ctx , ko )
737
721
if err != nil {
738
722
return err
739
723
}
740
724
741
725
// To set Asynchronous Invocations for the function
742
- err = rm .getFunctionEventInvokeConfig (ctx , ko )
726
+ err = rm .setFunctionEventInvokeConfig (ctx , ko )
743
727
if err != nil {
744
728
return err
745
729
}
746
730
747
731
// To set Code Signing Config based on the PackageType for the function
748
732
if ko .Spec .PackageType != nil && * ko .Spec .PackageType == "Zip" {
749
- err = rm .getFunctionCodeSigningConfig (ctx , ko )
733
+ err = rm .setFunctionCodeSigningConfig (ctx , ko )
750
734
if err != nil {
751
735
return err
752
736
}
0 commit comments