Skip to content
This repository has been archived by the owner on Oct 25, 2023. It is now read-only.

feat: read func classname from the func.yaml file #86

Closed
wants to merge 8 commits into from

Conversation

dolfolife
Copy link
Contributor

fixes #85
Signed-off-by: Rodolfo Sanchez [email protected]

@vmwclabot
Copy link

@dolfolife, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <[email protected]> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

@dolfolife dolfolife marked this pull request as draft July 19, 2022 20:30
@dolfolife
Copy link
Contributor Author

I still do not know what could be the best path from config -> to build parameters, but I am happy to discuss

buildpacks/java/VERSION Outdated Show resolved Hide resolved
@@ -53,7 +53,7 @@ func (b Build) Build(context libcnb.BuildContext) (libcnb.BuildResult, error) {

functionLayer := NewFunction(context.Application.Path,
WithLogger(b.Logger),
WithFunctionClass(functionClass, isFuncDefDefault),
WithFunctionClass(functionClass, isFuncDefDefault, e.Metadata["func_yaml_function_name"].(string)),
Copy link
Contributor

@andrew-su andrew-su Jul 19, 2022

Choose a reason for hiding this comment

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

I think what you want here is to make func_yaml_function_name to be the default function if it's not empty and isDefaultFuncDefault is false.

Copy link
Contributor

Choose a reason for hiding this comment

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

I also noticed I mis-named those variables isFuncDefDefault and isDefaultFuncDefault.

They should have been isFuncDefDefined and isDefaultFuncDefined.
cr.resolve returns whether it was explicitly set or not. (false == user did not set the value)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well you want that variable if the ENV is not set, right? the order of precedence is environment -> config -> default

and roger to the isFuncDefault I got confused by the variable name and I did not understand what it was.

Comment on lines 137 to 147
func withModuleName(value string) func(*libcnb.DetectContext) {
return func(dc *libcnb.DetectContext) {
dc.Platform.Environment["MODULE_NAME"] = value
}
}

func withFunctionName(value string) func(*libcnb.DetectContext) {
return func(dc *libcnb.DetectContext) {
dc.Platform.Environment["FUNCTION_NAME"] = value
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

These are only relevant to Python

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, the only way in Java to set the function name is with BP_FUNCTION or the Spring property?

"func_yaml_options": funcYaml.Options,
"launch": true,
"func_yaml_envs": funcYaml.Envs,
"func_yaml_function_name": funcYaml.Name,
Copy link
Contributor

Choose a reason for hiding this comment

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

I think I would prefer it to just be func_yaml_name to match the other keys better, as you store it in the struct as Name and the getter is getName.

@@ -34,14 +35,33 @@ func ParseFuncYaml(filedir string, logger bard.Logger) FuncYaml {

options := optionsToMap(cfg.Options, logger)
envs := envsToMap(cfg.Envs, logger)

name := getName(cfg.Envs, cfg.Name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Would cfg.Name be cleaner to get the name instead of iterating through cfg.Envs? https://pkg.go.dev/knative.dev/kn-plugin-func#Function

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to just using cfg.Name

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was a confusion that I think I have :) where there is an env variable that can be set as the name of the function and that would take precedence over the cfg.Name

Copy link
Contributor

Choose a reason for hiding this comment

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

cfg pulls from func.yaml though, while that env variable is a Python thing


for _, e := range envs {
key := *e.Name
if key == "FUNCTION_NAME" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Java doesn't make use of this environment variable, only the python invoker does

Copy link
Contributor Author

Choose a reason for hiding this comment

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

is this framework-related logic? should we abstract it?

@vmwclabot
Copy link

@dolfolife, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <[email protected]> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

@vmwclabot
Copy link

@dolfolife, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <[email protected]> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

1 similar comment
@vmwclabot
Copy link

@dolfolife, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <[email protected]> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

Rodolfo Sanchez added 7 commits July 25, 2022 15:29
Signed-off-by: Rodolfo Sanchez <[email protected]>
Signed-off-by: Rodolfo Sanchez <[email protected]>
Signed-off-by: Rodolfo Sanchez <[email protected]>
Signed-off-by: Rodolfo Sanchez <[email protected]>
Signed-off-by: Rodolfo Sanchez <[email protected]>
Signed-off-by: Rodolfo Sanchez <[email protected]>
@vmwclabot
Copy link

@dolfolife, you must sign every commit in this pull request acknowledging our Developer Certificate of Origin before your changes are merged. This can be done by adding Signed-off-by: John Doe <[email protected]> to the last line of each Git commit message. The e-mail address used to sign must match the e-mail address of the Git author. Click here to view the Developer Certificate of Origin agreement.

@bbtong
Copy link
Contributor

bbtong commented Aug 26, 2022

@dolfolife Has this gone stale or should it be merged in still?

@dolfolife dolfolife closed this Aug 29, 2022
@dolfolife dolfolife deleted the feat-use-func-yaml-name branch August 29, 2022 18:35
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

When no default function is specified for Java but a function name exists in func.yaml use that.
4 participants