Skip to content

Allow a default source path to be specified via envvar#397

Merged
bobh66 merged 4 commits intocrossplane-contrib:mainfrom
adamwg:awg/default-source
Mar 9, 2026
Merged

Allow a default source path to be specified via envvar#397
bobh66 merged 4 commits intocrossplane-contrib:mainfrom
adamwg:awg/default-source

Conversation

@adamwg
Copy link
Member

@adamwg adamwg commented Apr 22, 2025

Description of your changes

Enable function-go-templating to be used as a base image for custom functions with go templates included in the image by allowing the function input to be empty when a default source is set via environment variable. A user can build a custom function on top of function-go-templating by adding a directory containing go templates to the image and setting the environment variable FUNCTION_GO_TEMPLATING_DEFAULT_SOURCE to the template directory's path. The behavior of the function will be the same as if the templates were mounted into the function pod and the Filesystem input source used.

I have:

fn_test.go Outdated
for name, tc := range cases {
t.Run(name, func(t *testing.T) {
// NOTE: This means we can't run tests in parallel.
defaultSource = tc.args.defaultSource
Copy link
Member

@jbw976 jbw976 Apr 23, 2025

Choose a reason for hiding this comment

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

is there an alternative approach you were considering that doesn't rely on global variables?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure why I didn't do this initially, but we can read the envvar when we construct the Function and store it in a field. This is tidier than the global variable for sure. Updated to do things that way.

main.go Outdated
fsys: &osFS{},
log: log,
fsys: &osFS{},
defaultSource: os.Getenv("FUNCTION_GO_TEMPLATING_DEFAULT_SOURCE"),
Copy link
Member

Choose a reason for hiding this comment

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

awesome, i like this approach of resolving the value in main.go and passing it into the function more than a global var, thanks for that consideration!

now i'm also wondering if this should be exposed as a command line arg, in addition to the env var, similar to TLSCertsDir. i'm not sure if it should be exposed at that level also, but it's something else to consider here 🤔

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 it's probably cleaner to make it a command line argument with an env var like TLSCertsDir, since it needs to be rebased anyway?

Copy link
Member Author

Choose a reason for hiding this comment

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

Finally coming back to this - I agree, making it a flag is much better. Done (and rebased).

@adamwg adamwg force-pushed the awg/default-source branch from d1fa2e3 to e81a2f3 Compare November 4, 2025 17:45
@bobh66
Copy link
Collaborator

bobh66 commented Mar 4, 2026

Kick CI

@bobh66 bobh66 closed this Mar 4, 2026
@bobh66 bobh66 reopened this Mar 4, 2026
@bobh66 bobh66 requested a review from ulucinar as a code owner March 4, 2026 03:54
adamwg and others added 4 commits March 3, 2026 21:59
Signed-off-by: Adam Wolfe Gordon <awg@upbound.io>
Read the default source envvar as part of initialization in `main` and store it
in the `Function` struct rather than using a global variable. This is tidier and
lets us run our tests in parallel.

Signed-off-by: Adam Wolfe Gordon <awg@upbound.io>
Signed-off-by: Adam Wolfe Gordon <awg@upbound.io>
Signed-off-by: Bob Haddleton <bob.haddleton@nokia.com>
@bobh66 bobh66 force-pushed the awg/default-source branch from e81a2f3 to 437e94c Compare March 4, 2026 04:10
Copy link
Collaborator

@bobh66 bobh66 left a comment

Choose a reason for hiding this comment

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

LGTM

@bobh66 bobh66 merged commit 5ec0ef4 into crossplane-contrib:main Mar 9, 2026
6 checks passed
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.

3 participants