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: add init/build/deploy commands and customizable namespace #65

Merged
merged 4 commits into from
Aug 12, 2020

Conversation

lance
Copy link
Member

@lance lance commented Aug 7, 2020

This commit comprises some fairly large changes in the codebase.
The 'create' command has been extracted into 'init', 'bulid' and
'deploy' commands. The 'create' command remains, but now delegates
most of its work to these other three. This also has resulted in
some rework of the various flags. One example is the removal of
the '--local' flag from create, since this can be achieved now by
just running 'faas init'.

There are still a number of changes needed for this to land.

  • I've removed some of the 'internal' stub code
  • The environment variables have been removed (for the most part)
    from --help text and should be returned
  • The progress meter is a little wonky now
  • The service address is incorrect when printed (EDIT: just confirmed that this was the case before the PR as well)
  • There are no tests, and I'm pretty sure I've broken what tests already existed

@lkingland @matejvasek I welcome any comments, suggestions, modifications, etc.

It's a start - a work in progress.

@lance lance self-assigned this Aug 7, 2020
@lance
Copy link
Member Author

lance commented Aug 7, 2020

Review requested - but note that it is still a WIP

@lance
Copy link
Member Author

lance commented Aug 7, 2020

One thing that seems a little inconsistent is how configuration parameters are dealt with. Specifically, I mean for example, something like Deployer. The struct is created with some values such as Namespace and Verbose. But the Deploy() method accepts name and image. I think either they should all be parameters to Deploy() or all a part of the struct.

Copy link
Member

@lkingland lkingland left a comment

Choose a reason for hiding this comment

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

A few things changed in this PR simultaneously, so yes it will be a little bit of a challenge to get everything working, but we can do it! Let's communicate via Slack and I can explain how those function mocks for tests work, and we can discuss any other gotchas too.

cmd/build.go Outdated Show resolved Hide resolved
cmd/build.go Outdated Show resolved Hide resolved
This commit comprises some fairly large changes in the codebase.
The 'create' command has been extracted into 'init', 'bulid' and
'deploy' commands. The 'create' command remains, but now delegates
most of its work to these other three. This also has resulted in
some rework of the various flags. One example is the removal of
the '--local' flag from create, since this can be achieved now by
just running 'faas init'.

There are still a number of changes needed for this to land.

* I've removed some of the 'internal' stub code
* The environment variables have been removed (for the most part)
  from --help text and should be returned
* The progress meter is a little wonky now
* The service address is incorrect when printed
* There are no tests, and I'm pretty sure I've broken what
  tests already existed

It's a start - a work in progress.
@lance lance force-pushed the lance/62-configurable-namespace branch from 83deabb to 5b84c59 Compare August 10, 2020 21:50
@lance
Copy link
Member Author

lance commented Aug 10, 2020

@lkingland all tests and lint checks are passing. PTAL

@lkingland
Copy link
Member

Looking great @lance, glad that snapped into place. Doing a bit more in depth looksee now...

Copy link
Member

@lkingland lkingland left a comment

Choose a reason for hiding this comment

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

This really did end up touching all sorts of things. Looks great so far!

I am pretty sure we will still have a few things to iron out when integration testing, such as upgrading to the knative.dev client such that we get the actual route echoed back, and ensuring that it actually pushes (the call to Push appears to still be a WIP). But this sure looks good enough for me to rubber-stamp an LGTM

client.go Outdated Show resolved Hide resolved
client.go Outdated Show resolved Hide resolved
client.go Outdated Show resolved Hide resolved
client_test.go Show resolved Hide resolved
client_test.go Outdated Show resolved Hide resolved
cmd/build.go Show resolved Hide resolved
cmd/build.go Outdated Show resolved Hide resolved
cmd/build.go Outdated
// uses this to load a faas.Function. If the config contains
// a value for the image tag, this will be used and
// subsequently written to the config file.
func FunctionConfigForBuild(config buildConfig) (f *faas.Function, err error) {
Copy link
Member

@lkingland lkingland Aug 10, 2020

Choose a reason for hiding this comment

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

There's some logic in here in FunctionConfigForBuild and Build that is not really CLI-specific

  • If Name and Runtime are not provided, generate an error
  • If a Tag is not provided, use the tag from the config file in the function root
  • Tags default to quay.io/%s:latest
  • Update the Function config file on disk at function root
  • Optionally push on Build

These logic bits are simple, yes, but they are applicable to a developer using the client library directly or the CLI. So perhaps this is a job for a future refactor, but it would be nice to see these moved into the Client Library, and the API used here in the CLI kept to a very simple "map in booleans and strings, then invoke Build". This would both remove the need to do a conditional instantiation of the client library (one with and one without a Pusher), as well as opens us up to writing tests that validate expected functionality such as:
"Test that Name and Runtime are required or error"
"Test that Tag defaults to DefaultTag (quay.io)"
"Test that a Builder respects the Push boolean configuration"
etc.

Copy link
Member Author

Choose a reason for hiding this comment

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

Excellent points. I have moved it in to function.go and renamed it to faas.FunctionConfiguration(). I think it might benefit from adding a name parameter as well in order to update the function name. But to be honest, it's a little clumsy right now and I'm not sure if this is the best way to approach it all in the long run.

Copy link
Member

Choose a reason for hiding this comment

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

We probably have several solid refactors ahead of us where we can make it less clumsy!

Based on review feedback, this function really should not be part
of the CLI itself, but rather in the client library. In this case,
I have moved it to function.go as part of the faas package.

Currently it provides the ability to override the image tag, but
probably should be modified to also allow for a change to the function
name as well.
@lance
Copy link
Member Author

lance commented Aug 11, 2020

@matejvasek @lkingland your comments are incorporated, and I've removed the WIP status. PTAL and if it looks ok, let's go ahead and merge so that Naina can start experimenting with it.

@lance lance marked this pull request as ready for review August 11, 2020 21:37
Copy link
Member

@lkingland lkingland left a comment

Choose a reason for hiding this comment

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

LGTM! Looking forward to testing it out to confirm, but the code looks good to me.

f.Tag = tag
}
if f.Tag == "" {
f.Tag = fmt.Sprintf("quay.io/%s:latest", f.Name)
Copy link
Contributor

Choose a reason for hiding this comment

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

Possible future improvement: I think we could pick better default by looking into docker config file like
the CompleteRegistryList function does.

@lance lance merged commit 5b4d97a into knative:develop Aug 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants