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

feat: decouple function name from function domain #127

Merged
merged 3 commits into from Sep 24, 2020

Conversation

zroubalik
Copy link
Contributor

@zroubalik zroubalik commented Sep 18, 2020

Signed-off-by: Zbynek Roubalik zroubali@redhat.com

Fixes: #123

faas create foo -l node

Creates a new directory foo and initialize/create the function inside.

A directory structure is created according to the specified name, eg. relative/path/to/foo, /absolute/path/to/foo, foo or empty value (in this case it uses current directory).

The 'last' directory name is used as function name.

@zroubalik zroubalik marked this pull request as draft September 18, 2020 12:23
Comment on lines +309 to +312

// Create project root directory, if it doesn't already exist
if err = os.MkdirAll(cfg.Root, 0755); err != nil {
return
}

Copy link
Member

Choose a reason for hiding this comment

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

I really like the idea of creating the directory in which a function will be deployed because it would ensure the function is in a clean fresh directory. However, one small question: what do we do when a user wants to start over, without also removing their git history (.git) or other ancillary config files (.direnv)? This is why the code exists to check if a directory is effectively empty: contains no visible files, and no .faas.yaml, before allowing a re-run of create or init.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I am not mistaken, this command is not doing anything if the directory already exists (and contains some hidden files).

In that case user would do mkdir my_dir_with_hidden_files && faas init my_dir_with_hidden_files

Comment on lines -124 to +125
Path: prompt.ForString("Project path", c.initConfig.Path),
Name: prompt.ForString("Project name", name, prompt.WithRequired(true)),
Name: derivedName,
Path: derivedPath,
Copy link
Member

Choose a reason for hiding this comment

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

It appears to me that perhaps this omits the prompting of name and path entirely, right?

I was actuall fond of the original idea: to prompt if the parameter were not provided as a flag. If that's not the plan anymore, no problem! But if we wanted to prompt the user when the parameters had not been provided, would we not instead leave things roughly as they were, and insteaed add here a conditional that only prompts if the flag does not exist (as provided by the CLI API)?

Copy link
Member

Choose a reason for hiding this comment

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

It appears to me that perhaps this omits the prompting of name and path entirely, right?

@lkingland I may be misreading your comment, so disregard if so (or correct me). The prompt occurs on line 121.

derivedName, derivedPath := deriveNameAndAbsolutePathFromPath(prompt.ForString("Project path", c.initConfig.Path, prompt.WithRequired(true)))

cmd/init.go Outdated Show resolved Hide resolved
cmd/init.go Outdated Show resolved Hide resolved
k8s/names.go Outdated Show resolved Hide resolved
@zroubalik
Copy link
Contributor Author

@lkingland thanks for all the comments! This is still a draft and I was about to refactor/rewrite some parts of it, based on the conversation on #125 and Slack etc.

@lance lance changed the title decouple function name from function domain feat!: decouple function name from function domain Sep 18, 2020
Signed-off-by: Zbynek Roubalik <zroubali@redhat.com>
@zroubalik zroubalik marked this pull request as ready for review September 22, 2020 14:15
@zroubalik zroubalik changed the title feat!: decouple function name from function domain feat: decouple function name from function domain Sep 22, 2020
@zroubalik
Copy link
Contributor Author

@boson-project/core PTAL

Copy link
Member

@lance lance left a comment

Choose a reason for hiding this comment

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

This generally LGTM aside from a couple of questions and nits.

client.go Outdated Show resolved Hide resolved
Comment on lines -124 to +125
Path: prompt.ForString("Project path", c.initConfig.Path),
Name: prompt.ForString("Project name", name, prompt.WithRequired(true)),
Name: derivedName,
Path: derivedPath,
Copy link
Member

Choose a reason for hiding this comment

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

It appears to me that perhaps this omits the prompting of name and path entirely, right?

@lkingland I may be misreading your comment, so disregard if so (or correct me). The prompt occurs on line 121.

derivedName, derivedPath := deriveNameAndAbsolutePathFromPath(prompt.ForString("Project path", c.initConfig.Path, prompt.WithRequired(true)))

cmd/create.go Show resolved Hide resolved
cmd/root.go Outdated Show resolved Hide resolved
@@ -165,21 +166,42 @@ func functionWithOverrides(root, namespace, image string) (f faas.Function, err

// deriveName returns the explicit value (if provided) or attempts to derive
// from the given path. Path is defaulted to current working directory, where
// a function configuration, if it exists and contains a name, is used. Lastly
// derivation using the path us used.
// a Function configuration, if it exists and contains a name, is used.
func deriveName(explicitName string, path string) string {
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if this function could be better named as it no longer really derives the name, but instead just pulls it from the configuration file or returns the passed 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.

Any suggestion?

Copy link
Member

@lance lance Sep 22, 2020

Choose a reason for hiding this comment

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

Any suggestion?

I've been sitting here for 5 minutes trying to come up with a good name. I see why you asked. The best I've come up with is providedOrConfiguredName(provided, path string) string. But meh.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hehe, yeah 😄 I don't like the name either, so I am happy to change it to anything else, that makes sense for everyone

k8s/names.go Show resolved Hide resolved
Signed-off-by: Zbynek Roubalik <zroubali@redhat.com>
Signed-off-by: Zbynek Roubalik <zroubali@redhat.com>
@lance lance merged commit 0258626 into knative:main Sep 24, 2020
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.

Proposal to decouple function name from function domain
3 participants