Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a guide to writing a composition function in Go #597

Merged
merged 14 commits into from
Nov 1, 2023

Conversation

negz
Copy link
Member

@negz negz commented Nov 1, 2023

Fixes #579

This is separate from the functions documentation under concepts because:

  1. I expect to have similar guides for other languages, such as Python.
  2. The guide will evolve outside of the Crossplane release cycle.

Copy link

netlify bot commented Nov 1, 2023

Deploy Preview for crossplane ready!

Name Link
🔨 Latest commit 5cda5e3
🔍 Latest deploy log https://app.netlify.com/sites/crossplane/deploys/65428f7b2c55190008310366
😎 Deploy Preview https://deploy-preview-597--crossplane.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance:
Accessibility:
Best Practices:
SEO:
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

template Crossplane resources. Crossplane calls composition functions to
determine what resources it should create when you create a composite resource
(XR). Read the
[concepts]({{<ref "../../master/concepts/composition-functions">}})
Copy link
Member Author

Choose a reason for hiding this comment

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

@plumbis I'd prefer to link to latest, or failing that v1.14 specifically.

I tried a regular [foo](/latest) style link, but HTML test didn't like it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You can add docs.crossplane.io/latest/* to the htmltest config, since this is a deploy-time path.

Copy link
Member

@jbw976 jbw976 left a comment

Choose a reason for hiding this comment

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

leaving a partial review for now because the commits being pushed to this PR while i'm reviewing caused github to force me to refresh and I lose a comment or two i think - checkpointing to not lose anything else

Copy link
Member

@jbw976 jbw976 left a comment

Choose a reason for hiding this comment

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

This is basically great @negz!!! a few questions, improvements, and some odd renderings, but basically resolve these as you see fit and ship it!! :shipit:

negz added a commit to negz/function-sdk-go that referenced this pull request Nov 1, 2023
Remove the big example, there's now something better in the docs.

The linked guide won't exist until the below PR is merged.

crossplane/docs#597

Signed-off-by: Nic Cope <[email protected]>
negz added a commit to negz/function-sdk-go that referenced this pull request Nov 1, 2023
Remove the big example, there's now something better in the docs.

The linked guide won't exist until the below PR is merged.

crossplane/docs#597

Signed-off-by: Nic Cope <[email protected]>
Copy link
Member

@ezgidemirel ezgidemirel left a comment

Choose a reason for hiding this comment

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

Thanks @negz for the guide, it looks great! I have two things to add:

  • I believe it's worth mentioning that functions need to be idempotent. It's an easy mistake to forget that (especially for an operation like create) and act like they're running only once.
  • We may add an examples folder to the function template and encourage function authors to add examples. Later, we can display them in the marketplace, just like we do with providers.

@negz
Copy link
Member Author

negz commented Nov 1, 2023

We may add an examples folder to the function template and encourage function authors to add examples. Later, we can display them in the marketplace, just like we do with providers.

@ezgidemirel I coincidentally actually did that last night - https://github.com/crossplane/function-template-go. 😄

Copy link
Collaborator

@plumbis plumbis left a comment

Choose a reason for hiding this comment

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

I think there is something wacky with how vale is building tokens from words and parsing. Testing locally adding the ticks around function-template-go on line 434 and xpkg.upbound.io on line 482 made the other spelling errors go away.

Can you try making those changes and see if vale stops grumping?

negz added 13 commits November 1, 2023 10:22
This is separate from the functions documentation under concepts
because:

1. I expect to have similar guides for other languages, such as Python.
2. The guide will evolve outside of the Crossplane release cycle.

Signed-off-by: Nic Cope <[email protected]>
Vale considers it a spelling mistake, and it's easy to rephrase around.

Signed-off-by: Nic Cope <[email protected]>
We don't have any docs specific to multi-platform _packages_ AFAIK.

Signed-off-by: Nic Cope <[email protected]>
To workaround spellchecker thinking "Go." (with period) is a spelling
mistake.

Signed-off-by: Nic Cope <[email protected]>
I do actually want latest, but HTML test complains when I try. There's
no v1.14 release directory to link to yet, so master will have to do.

Signed-off-by: Nic Cope <[email protected]>
@negz
Copy link
Member Author

negz commented Nov 1, 2023

Can you try making those changes and see if vale stops grumping?

@plumbis It worked, thank you!

@negz
Copy link
Member Author

negz commented Nov 1, 2023

I believe it's worth mentioning that functions need to be idempotent. It's an easy mistake to forget that (especially for an operation like create) and act like they're running only once.

@ezgidemirel Agreed - I'll do a pass to make sure this is really clear. I'd like to get this merged as-is though since we shipped today. Will do that in a follow-up.

This seems like the most future-proof option for this guide, which lives
outside of any version.

Signed-off-by: Nic Cope <[email protected]>
@negz negz merged commit 68a8cd9 into crossplane:master Nov 1, 2023
6 checks passed
@negz negz deleted the get-func-ey branch November 1, 2023 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document how to write a Composition Function
4 participants