Skip to content

Conversation

@ikarldasan
Copy link

Description of your changes

  • Adds Support for AWS SES Template

"Fixes a part of #414 "

I have:

  • Read and followed Crossplane's [contribution process].
  • Run make reviewable test to ensure this PR is ready for review.

How has this code been tested

Manually tested the creation, updation and deletion of Template

Copy link
Collaborator

@chlunde chlunde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! I'm not a maintainer and I haven't used code gen, but I think I found two small issues you should look at, hope this helps.

name: example
spec:
forProvider:
region: us-east-2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent this section under forProvider, and check that it works

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indented the section under forProvider .
Checked for Create, Update and Delete operations - Works successfully.


func preObserve(_ context.Context, cr *svcapitypes.Template, obj *svcsdk.GetTemplateInput) error {
obj.TemplateName = aws.String(meta.GetExternalName(cr))
cr.Spec.ForProvider.Template.TemplateName = obj.TemplateName
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

@ikarldasan ikarldasan Jul 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CreateTemplateInput struct contains a *Template which contains the TemplateName.

Do you suggest adding TemplateName to ignore field_paths like this?

ignore:
  field_paths:
    - CreateTemplateInput.Template.TemplateName

I tried adding the same. The resultant code generated after re running make generate does not have the Template Parameters in the ForProvider i.e the CRD does not accept the Template_SDK struct that contains HTMLPart, SubjectPart, TemplateName, TextPart

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there is a need to update the code-generator, it does not support three levels like Foo.Bar.Baz.

I made a (draft) PR here: aws-controllers-k8s/code-generator#119

Copy link
Collaborator

@chlunde chlunde Aug 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@muvaf points out that this can be achieved already using

ignore:
  field_paths:
    - Template.TemplateName

Again I would like to point out that I'm not 100% sure this is the correct approach as I've not used code gen. :)

subjectPart: "sample subject part"
textPart: "sample text part"
providerConfigRef:
name: example No newline at end of file
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick: if all other files have a final newline, it would be nice to add it to this file and generator-config.yaml too.

Copy link
Author

@ikarldasan ikarldasan Jul 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added newline to the example.

Copy link

@AaronME AaronME left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works well to create, delete.

Update works for changes to SubjectPart, TextPart, and HtmlPart.

I've included some thoughts on how to handle an update to TemplateName.

apiVersion: ses.aws.crossplane.io/v1alpha1
kind: Template
metadata:
name: example
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny nitpick:

Our other examples are using 2-space indents. Can we reformat this to match?

}

func isUpToDate(cr *svcapitypes.Template, obj *svcsdk.GetTemplateOutput) (bool, error) {
if !cmp.Equal(cr.Spec.ForProvider.Template.TemplateName, obj.Template.TemplateName) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we cannot update the templateName once the Template is created, we may want to...

  • Ignore Template.TemplateName in code generation and use PreObserve, PreCreate, PreUpdate, and PreDelete to always set it to cr.Name.
  • Return an informative error (eg, "Cannot update field TemplateName, ignoring.") and return true
  • Delete the Template and allow re-create with the new name.

forProvider:
region: us-east-2
template:
templateName: example
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested updating spec.forProvider.template.templateName on an existing Template resource and received the following error:

2021-07-23T15:24:19.702-0400    DEBUG   provider-aws    Cannot update external resource {"controller": "managed/template.ses.aws.crossplane.io", "request": "/example", "uid": "b15f8ce9-c765-4543-bf1c-435caaaa8bc6", "version": "50082", "external-name": "example"}
2021-07-23T15:24:19.702-0400    DEBUG   controller-runtime.manager.events       Warning {"object": {"kind":"Template","name":"example","uid":"b15f8ce9-c765-4543-bf1c-435caaaa8bc6","apiVersion":"ses.aws.crossplane.io/v1alpha1","resourceVersion":"50082"}, "reason": "CannotUpdateExternalResource", "message": "cannot update Template in AWS: TemplateDoesNotExist: Template example2 does not exist."}

@AaronME
Copy link

AaronME commented Oct 1, 2021

@ikarldasan are you still working on this PR?

@haarchri
Copy link
Member

@ikarldasan any chance to see this finalized ?

@MisterMX
Copy link
Collaborator

Closing as this was implemented in #791. Feel free to reopen if that is not the case.

@MisterMX MisterMX closed this Jul 28, 2023
tektondeploy pushed a commit to gtn3010/provider-aws that referenced this pull request Mar 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants