Skip to content

Commit

Permalink
chore: Enhance Update function to call only necessary API based on sp…
Browse files Browse the repository at this point in the history
…ecific ConfigurationSet changes

Signed-off-by: kelvinwijaya <[email protected]>
  • Loading branch information
kelvinwijaya committed Jul 25, 2023
1 parent e9af696 commit 7e8c19e
Showing 1 changed file with 13 additions and 22 deletions.
35 changes: 13 additions & 22 deletions pkg/controller/sesv2/configurationset/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func SetupConfigurationSet(mgr ctrl.Manager, o controller.Options) error {
h := &hooks{client: e.client, kube: e.kube}
e.isUpToDate = isUpToDate
e.preObserve = preObserve
e.postObserve = postObserve
e.postObserve = h.postObserve
e.preCreate = preCreate
e.preDelete = preDelete
e.update = h.update
Expand All @@ -77,8 +77,9 @@ func SetupConfigurationSet(mgr ctrl.Manager, o controller.Options) error {
}

type hooks struct {
client sesv2iface.SESV2API
kube client.Client
client sesv2iface.SESV2API
kube client.Client
ConfigurationSetObservation *svcsdk.GetConfigurationSetOutput
}

func isUpToDate(cr *svcapitypes.ConfigurationSet, resp *svcsdk.GetConfigurationSetOutput) (bool, error) {
Expand Down Expand Up @@ -188,7 +189,7 @@ func preObserve(_ context.Context, cr *svcapitypes.ConfigurationSet, obj *svcsdk
return nil
}

func postObserve(_ context.Context, cr *svcapitypes.ConfigurationSet, resp *svcsdk.GetConfigurationSetOutput, obs managed.ExternalObservation, err error) (managed.ExternalObservation, error) {
func (e *hooks) postObserve(_ context.Context, cr *svcapitypes.ConfigurationSet, resp *svcsdk.GetConfigurationSetOutput, obs managed.ExternalObservation, err error) (managed.ExternalObservation, error) {
if err != nil {
return managed.ExternalObservation{}, err
}
Expand All @@ -202,6 +203,9 @@ func postObserve(_ context.Context, cr *svcapitypes.ConfigurationSet, resp *svcs
cr.Status.SetConditions(xpv1.Creating())
}

// Passing ConfigurationSet object from Observation into hooks for Update function to access
e.ConfigurationSetObservation = resp

return obs, nil
}

Expand All @@ -227,7 +231,7 @@ func (e *hooks) update(ctx context.Context, mg resource.Managed) (managed.Extern
configurationSetName := awsclient.String(mg.GetAnnotations()[meta.AnnotationKeyExternalName])

// update DeliveryOptions (PutConfigurationSetDeliveryOptions)
if cr.Spec.ForProvider.DeliveryOptions != nil {
if !isUpToDateDeliveryOptions(cr, e.ConfigurationSetObservation) {
deliveryOptionsInput := &svcsdk.PutConfigurationSetDeliveryOptionsInput{
ConfigurationSetName: configurationSetName,
SendingPoolName: cr.Spec.ForProvider.DeliveryOptions.SendingPoolName,
Expand All @@ -239,7 +243,7 @@ func (e *hooks) update(ctx context.Context, mg resource.Managed) (managed.Extern
}

// update ReputationOptions (PutConfigurationSetReputationOptions)
if cr.Spec.ForProvider.ReputationOptions != nil {
if !isUpToDateReputationOptions(cr, e.ConfigurationSetObservation) {
reputationOptionsInput := &svcsdk.PutConfigurationSetReputationOptionsInput{
ConfigurationSetName: configurationSetName,
ReputationMetricsEnabled: cr.Spec.ForProvider.ReputationOptions.ReputationMetricsEnabled,
Expand All @@ -251,7 +255,7 @@ func (e *hooks) update(ctx context.Context, mg resource.Managed) (managed.Extern

// update SuppressionOptions (PutConfigurationSetSuppressionOptions)
var suppresssedReasons []*string
if cr.Spec.ForProvider.SuppressionOptions != nil {
if !isUpToDateSuppressionOptions(cr, e.ConfigurationSetObservation) {
suppresssedReasons = cr.Spec.ForProvider.SuppressionOptions.SuppressedReasons
supressOptionsInput := &svcsdk.PutConfigurationSetSuppressionOptionsInput{
ConfigurationSetName: configurationSetName,
Expand All @@ -263,7 +267,7 @@ func (e *hooks) update(ctx context.Context, mg resource.Managed) (managed.Extern
}

// update TrackingOptions (PutConfigurationSetTrackingOptions)
if cr.Spec.ForProvider.TrackingOptions != nil {
if !isUpToDateTrackingOptions(cr, e.ConfigurationSetObservation) {
trackingOptionInput := &svcsdk.PutConfigurationSetTrackingOptionsInput{
ConfigurationSetName: configurationSetName,
CustomRedirectDomain: cr.Spec.ForProvider.TrackingOptions.CustomRedirectDomain,
Expand All @@ -274,7 +278,7 @@ func (e *hooks) update(ctx context.Context, mg resource.Managed) (managed.Extern
}

// update SendingOptions (PutConfigurationSetSendingOptions)
if cr.Spec.ForProvider.SendingOptions != nil {
if !isUpToDateSendingOptions(cr, e.ConfigurationSetObservation) {
sendingOptionInput := &svcsdk.PutConfigurationSetSendingOptionsInput{
ConfigurationSetName: configurationSetName,
SendingEnabled: cr.Spec.ForProvider.SendingOptions.SendingEnabled,
Expand All @@ -284,19 +288,6 @@ func (e *hooks) update(ctx context.Context, mg resource.Managed) (managed.Extern
}
}

// TODO(kelvinwijaya): Updating Tags will be useful if we can determine the resourceArn
/*
cr, ok := mg.(*svcapitypes.ConfigurationSet)
if !ok {
return managed.ExternalUpdate{}, errors.New(errUnexpectedObject)
}
input := GenerateGetConfigurationSetInput(cr)
resp, err := e.client.GetConfigurationSetWithContext(ctx, input)
if err != nil {
return managed.ExternalUpdate{}, awsclient.Wrap(resource.Ignore(IsNotFound, err), errDescribe)
}
svcutils.UpdateTagsForResource(e.client, cr.Spec.ForProvider.Tags, resp.ConfigurationSetName)
*/
return managed.ExternalUpdate{}, nil
}

Expand Down

0 comments on commit 7e8c19e

Please sign in to comment.