@@ -615,8 +615,16 @@ func customPreCompare(
615
615
// This will ensure controller does not act on this field
616
616
// if user is unaware of it.
617
617
if a .ko .Spec .ContributorInsights == nil {
618
- a . ko . Spec . ContributorInsights = b . ko . Spec . ContributorInsights
618
+ return
619
619
}
620
+ // latestInsight will always be either ENABLED or DISABLED, since we requeue at readOne if its not
621
+ // either
622
+ desiredInsight , _ := ensureContibutorInsight (a )
623
+ latestInsight , _ := ensureContibutorInsight (b )
624
+ if desiredInsight != latestInsight {
625
+ delta .Add ("Spec.ContributorInsights" , a .ko .Spec .ContributorInsights , b .ko .Spec .ContributorInsights )
626
+ }
627
+
620
628
}
621
629
622
630
// equalAttributeDefinitions return whether two AttributeDefinition arrays are equal or not.
@@ -775,19 +783,33 @@ func (rm *resourceManager) setContributorInsights(
775
783
return err
776
784
}
777
785
778
- switch resp .ContributorInsightsStatus {
779
- case svcsdktypes .ContributorInsightsStatusEnabled :
780
- ko .Spec .ContributorInsights = aws .String (string (svcsdktypes .ContributorInsightsActionEnable ))
781
- case svcsdktypes .ContributorInsightsStatusDisabled :
782
- ko .Spec .ContributorInsights = aws .String (string (svcsdktypes .ContributorInsightsActionDisable ))
783
- default :
786
+ // Only manage ContributorInsights if it is defined
787
+ if ko .Spec .ContributorInsights != nil {
784
788
ko .Spec .ContributorInsights = aws .String (string (resp .ContributorInsightsStatus ))
785
-
786
789
}
787
790
788
791
return nil
789
792
}
790
793
794
+ // ensureContibutorInsight ensures the controller understands ENABLE and ENABLED are the same.
795
+ // We choose to return ContributorInsightsAction because that is the enum used to update.
796
+ func ensureContibutorInsight (r * resource ) (svcsdktypes.ContributorInsightsAction , error ) {
797
+ insight := svcsdktypes .ContributorInsightsActionDisable
798
+ if r .ko .Spec .ContributorInsights != nil {
799
+ // We will allow users to provide values ENABLE, ENABLED, DISABLE, DISABLED
800
+ switch * r .ko .Spec .ContributorInsights {
801
+ case string (svcsdktypes .ContributorInsightsActionEnable ), string (svcsdktypes .ContributorInsightsStatusEnabled ):
802
+ insight = svcsdktypes .ContributorInsightsActionEnable
803
+ case string (svcsdktypes .ContributorInsightsActionDisable ), string (svcsdktypes .ContributorInsightsStatusDisabled ):
804
+ insight = svcsdktypes .ContributorInsightsActionDisable
805
+ default :
806
+ return "" , fmt .Errorf ("invalid ContributorInsights value: %s" , * r .ko .Spec .ContributorInsights )
807
+ }
808
+ }
809
+
810
+ return insight , nil
811
+ }
812
+
791
813
func (rm * resourceManager ) updateContributorInsights (
792
814
ctx context.Context ,
793
815
r * resource ,
@@ -797,9 +819,10 @@ func (rm *resourceManager) updateContributorInsights(
797
819
defer func () {
798
820
exit (err )
799
821
}()
800
- insight := svcsdktypes .ContributorInsightsActionDisable
801
- if r .ko .Spec .ContributorInsights != nil {
802
- insight = svcsdktypes .ContributorInsightsAction (* r .ko .Spec .ContributorInsights )
822
+
823
+ insight , err := ensureContibutorInsight (r )
824
+ if err != nil {
825
+ return fmt .Errorf ("failed preparing contributorInsight: %v" , err )
803
826
}
804
827
805
828
_ , err = rm .sdkapi .UpdateContributorInsights (
0 commit comments