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

Rearrange the crossplane subcommands #4832

Merged
merged 25 commits into from
Oct 18, 2023
Merged

Conversation

negz
Copy link
Member

@negz negz commented Oct 17, 2023

Description of your changes

Fixes #4787
Fixes #4784
Fixes #4783

Here's what it looks like:

$ go run cmd/crank/main.go --help
Usage: crossplane <command>

A command line tool for interacting with Crossplane.

Commands:
  xpkg login        Login to the default package registry (xpkg.upbound.io).
  xpkg logout       Logout of the default package registry (xpkg.upbound.io).
  xpkg build        Build a package, by default from the current directory.
  xpkg push         Push a package, by default to xpkg.upbound.io.
  xpkg install      Install a package.
  xpkg update       Update an installed package.
  beta xpkg init    Initialize a package from a template.
  beta render       Render a claim or XR locally.

Flags:
  -h, --help       Show context-sensitive help.
  -v, --version    Print version and quit.
      --verbose    Print verbose logging statements.

Run "crossplane <command> --help" for more information on a command.

Notable changes in this PR:

  • Renamed marketplace login to xpkg login
  • Renamed xpkg build --controller flag to --embed-runtime-image.
  • Everything uses xpkg.upbound.io as the default registry
  • Store xpkg.upbound.io auth config in ~/.crossplane to avoid conflicts with ~/.up.
  • The kind of package to install (e.g. provider, function, etc) is now an argument to xpkg install, not a subcommand.
  • You can use xpkg init to initialize a provider now too (or really anything - for now it's a tiny wrapper on git clone).

I have:

  • Read and followed Crossplane's contribution process.
  • Added or updated unit tests.
  • Added or updated e2e tests, if necessary. (check with reviewers/maintainers if you're unsure whether E2E tests are necessary for the change).
  • Run make reviewable to ensure this PR is ready for review.
  • Added backport release-x.y labels to auto-backport this PR, if necessary.
  • Opened a PR updating the docs, if necessary.

@negz negz requested review from jbw976 and phisco October 17, 2023 22:56
@negz
Copy link
Member Author

negz commented Oct 17, 2023

Edit: updated the PR to use compact.

I personally found the tree view pretty ugly/hard to read with the new layout so I reverted that. Not sure if that will be controversial.

Some other options available to us are to skip expanding subcommands by default, which looks like:

Usage: crossplane <command>

A command line tool for interacting with Crossplane.

Commands:
  xpkg <command>
    Crossplane package management.

  beta <command>
    Beta features. WARN: May be changed or deprecated in a future release

Flags:
  -h, --help       Show context-sensitive help.
  -v, --version    Print version and quit.
      --verbose    Print verbose logging statements.

Run "crossplane <command> --help" for more information on a command.

Or to get compact help, which looks like:

$ go run cmd/crank/main.go --help
Usage: crossplane <command>

A command line tool for interacting with Crossplane.

Commands:
  xpkg login                    Login to the default package registry (xpkg.upbound.io).
  xpkg logout                   Logout of the default package registry (xpkg.upbound.io).
  xpkg build                    Build a package, by default from the current directory.
  xpkg push                     Push a package, by default to xpkg.upbound.io.
  xpkg install configuration    Install a Configuration package.
  xpkg install provider         Install a Provider package.
  xpkg update configuration     Update a Configuration package.
  xpkg update provider          Update a Provider package.
  beta xpkg init                Initialize a package from a template.
  beta xpkg install function    Install a Function package.
  beta xpkg update function     Update a Function package.
  beta render                   Render a claim or XR locally.

Flags:
  -h, --help       Show context-sensitive help.
  -v, --version    Print version and quit.
      --verbose    Print verbose logging statements.

@jbw976
Copy link
Member

jbw976 commented Oct 17, 2023

I like the compact view the best! I agree that the tree view is now too big and unwieldy and it will only get worse with more commands that we add. I do like having subcommands expanded so the user knows everything they can do up front without having to spelunk manually down through all the commands and get help for all of them.

Compact help seems to be a good balance of all that for now - we can always revisit if that gets too large in the future.

@jbw976
Copy link
Member

jbw976 commented Oct 17, 2023

Make update and install take the kind of package as an argument, not a subcommand.

So this means that these commands would go away, right?

  • beta xpkg install function
  • beta xpkg update function

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.

Thanks for taking this clean-up effort on @negz!! took a quick pass through now with a few comments, but no major objections to anything here 🙇

cmd/crank/main.go Show resolved Hide resolved
cmd/crank/beta/xpkg/xpkg.go Outdated Show resolved Hide resolved
cmd/crank/beta/xpkg/xpkg.go Outdated Show resolved Hide resolved
internal/xpkg/upbound/context.go Show resolved Hide resolved
@negz negz force-pushed the redecorating branch 3 times, most recently from 0d8d7f3 to 320fee9 Compare October 18, 2023 03:33
@negz negz marked this pull request as ready for review October 18, 2023 03:57
@negz negz requested review from a team and turkenh as code owners October 18, 2023 03:57
@negz negz requested a review from jbw976 October 18, 2023 04:37
}
return b.String()
Copy link
Member Author

Choose a reason for hiding this comment

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

FYI this renders like this:

remote:
$ go run cmd/crank/main.go beta xpkg init --help
Usage: crossplane beta xpkg init <name> <template>

Initialize a package from a template.

Crossplane initializes a package by using git to clone a template from a
repository. The template can be either a git repository URL, or a well-known
template name.

Crossplane supports the following well-known-template names:

  - provider-minimal (https://github.com/crossplane/provider-template)
  - provider-upjet (https://github.com/upbound/upjet-provider-template)
  - function-go (https://github.com/crossplane/function-template-go)

Arguments:
  <name>        Name of the package to initialize.
  <template>    Template to initialize the package from.

Flags:
  -h, --help             Show context-sensitive help.
  -v, --version          Print version and quit.
      --verbose          Print verbose logging statements.

  -d, --directory="."    Path of the directory to initialize.

Copy link
Contributor

@phisco phisco 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 feedbacks:

  • I preferred keeping the beta/alpha commands where they would be without the beta/alpha prefix, as that would mean promoting them would be a 1 line change instead of moving all the related files.
  • I like the direction of --embed-runtime-image, I think it conveys better how the image is being used by the build subcommands, however embed suggests it's a Boolean, I'd rather have it as --embedded-runtime-image probably.
  • I guess you switched the tree view off because it wasn't playing nicely with having a single top subcommands, is this the case? I prefer the tree view, but I also found the default visualization not to work so well in this case

Copy link
Contributor

@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.

The commands were modified in this PR but we should update cmd/crank/beta/render/cmd.go

type Cmd struct {
	CompositeResource string `arg:"" type:"existingfile" help:"A composite resource (XR) YAML file to render."`
	Composition       string `arg:"" type:"existingfile" help:"A Composition YAML file to use."`
	Functions         string `arg:"" help:"A stream or directory of YAML files containing the Composition Functions to use."`

	ContextValues map[string]string `placeholder:"KEY=JSON-VALUE;..." help:"Semicolon-separated JSON encoded context variables to pass to the Function pipeline. Takes precedence over --context-files."`
	ContextFiles  map[string]string `placeholder:"KEY=FILENAME;..." help:"Semicolon-separated JSON encoded context variables to pass to the Function pipeline."`

	IncludeResults    bool     `short:"r" default:"true" help:"Include the Function's Results output."`
	ObservedResources []string `short:"o" help:"A stream or directory of YAML files mocking the observed state of composed resources."`

	Timeout time.Duration `help:"Amount of time to wait for the function to complete." default:"1m"`
}

cmd/crank/xpkg/xpkg.go Show resolved Hide resolved
cmd/crank/beta/beta.go Show resolved Hide resolved
cmd/crank/xpkg/build.go Outdated Show resolved Hide resolved
cmd/crank/xpkg/build.go Show resolved Hide resolved
cmd/crank/xpkg/install.go Show resolved Hide resolved
Comment on lines +47 to 48
Tag string `arg:"" help:"Tag of the package to be pushed. Must be a valid OCI image tag. Unqualified tags will be pushed to xpkg.upbound.io."`
Package string `short:"f" help:"Path to package. If not specified and only one package exists in current directory it will be used."`
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Tag string `arg:"" help:"Tag of the package to be pushed. Must be a valid OCI image tag. Unqualified tags will be pushed to xpkg.upbound.io."`
Package string `short:"f" help:"Path to package. If not specified and only one package exists in current directory it will be used."`
Tag string `arg:"" help:"Package filename and version tag to use in the container registry."`
Package string `short:"f" help:"Path to the Crossplane xpkg file." default:"."`

What do you mean by "Unqualified tags"?

cmd/crank/xpkg/update.go Show resolved Hide resolved
Comment on lines +47 to +48
Ref string `arg:"" help:"The package's OCI image reference (e.g. tag)."`
Name string `arg:"" optional:"" help:"Name of the package to update. Will be derived from the ref if omitted."`
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Ref string `arg:"" help:"The package's OCI image reference (e.g. tag)."`
Name string `arg:"" optional:"" help:"Name of the package to update. Will be derived from the ref if omitted."`
Ref string `arg:"" help:"Package filename and version tag in the container registry."`
Name string `arg:"" optional:"" help:"Name of the package inside Crossplane. Derived from the package metadata name by default."`

cmd/crank/beta/xpkg/init.go Show resolved Hide resolved
cmd/crank/beta/xpkg/init.go Show resolved Hide resolved
Ditto logout.

Signed-off-by: Nic Cope <nicc@rk0n.org>
This isn't where Crossplane pulls from by default, but we think we'd
like it to be someday. It's the only Crossplane-aware OCI registry we're
aware of, in that packages can show up at marketplace.upbound.io
decorated with docs, examples, etc.

Signed-off-by: Nic Cope <nicc@rk0n.org>
I think this might have been done to avoid shadowing, but I'm not
getting any linter complaints after renaming back to config.

Signed-off-by: Nic Cope <nicc@rk0n.org>
Signed-off-by: Nic Cope <nicc@rk0n.org>
Signed-off-by: Nic Cope <nicc@rk0n.org>
This got copied from the up login implementation. We don't need or want
this functionality in Crossplane.

Signed-off-by: Nic Cope <nicc@rk0n.org>
This allows us to diverge from the .up config format without treading on
each other. The downside is that folks using up will need to login again
(even if they're using crossplane) and vice versa, but I think this is
worth it.

Signed-off-by: Nic Cope <nicc@rk0n.org>
Signed-off-by: Nic Cope <nicc@rk0n.org>
Unfortunately we need very copy-pasta subcommands here in order to know
what type of package to install.

Signed-off-by: Nic Cope <nicc@rk0n.org>
Signed-off-by: Nic Cope <nicc@rk0n.org>
Signed-off-by: Nic Cope <nicc@rk0n.org>
Signed-off-by: Nic Cope <nicc@rk0n.org>
Signed-off-by: Nic Cope <nicc@rk0n.org>
This was way less branchy to do using the controller-runtime client
rather than a generated clientset, so there's quite a lot of
refactoring here.

As part of this commit, I also made the beta install/update command
reuse the GA code. See commentary in the diff for reasoning.

Signed-off-by: Nic Cope <nicc@rk0n.org>
These were internal, and appeared to only be used by the Crossplane CLI
package install/update commands. Those commands now use the
controller-runtime client instead.

Signed-off-by: Nic Cope <nicc@rk0n.org>
I like having a little context, but prefer to keep the bulk of the
detail at a URL we can update over time more easily than the CLI help
strings.

Signed-off-by: Nic Cope <nicc@rk0n.org>
This hopefully better explains what the flag does, while using a more
generic name that is compatible with providers and functions.

Signed-off-by: Nic Cope <nicc@rk0n.org>
Signed-off-by: Nic Cope <nicc@rk0n.org>
I believe we added v2 as a temporary workaround for the fact that we had
two "package build" implementations. We now only have one, that's closer
to the v2 implementation.

Signed-off-by: Nic Cope <nicc@rk0n.org>
It felt strange to have beta install/update variants just to handle
Functions when the GA build and push commands support them.

Signed-off-by: Nic Cope <nicc@rk0n.org>
This matches the prefixes of the embedded upbound.Flags, and I think it
will be convenient to match the env vars used by the up CLI (where these
commands originated).

Signed-off-by: Nic Cope <nicc@rk0n.org>
Signed-off-by: Nic Cope <nicc@rk0n.org>
Signed-off-by: Nic Cope <nicc@rk0n.org>
@negz
Copy link
Member Author

negz commented Oct 18, 2023

@phisco

I preferred keeping the beta/alpha commands where they would be without the beta/alpha prefix, as that would mean promoting them would be a 1 line change instead of moving all the related files.

I somewhat strongly prefer keeping the beta and alpha commands in a subdirectory:

  • I feel it makes it more obvious whether code is beta or alpha when browsing the implementation. As opposed to where its called.
  • It means we can easily have multiple implementations of the same subcommand (GA, alpha, beta) without potentially awkward naming issues (e.g. xpkg.Cmd, xpkgBeta.Cmd, etc).
  • I'm not particularly worried about promoting commands requiring us to git mv some files.

I like the direction of --embed-runtime-image, I think it conveys better how the image is being used by the build subcommands, however embed suggests it's a Boolean, I'd rather have it as --embedded-runtime-image probably.

To me --embed-runtime-image reads more like an action: "embed this runtime image". I think the fact it takes a string argument should hopefully make this clear. I've added placeholder examples to clarify further.

I guess you switched the tree view off because it wasn't playing nicely with having a single top subcommands, is this the case? I prefer the tree view, but I also found the default visualization not to work so well in this case

I'll be honest, I really could not stand the tree view. It was especially bad when for a while this PR had added a few more commands. I don't think it will work very well when we have ~double the amount of commands we have now. My hope is that the compact view will be a good compromise. I think it gives you all the same information as the tree view, but:

  • More compact
  • Without arguments and flags showing up at top level (which I think we didn't want).

I also personally find it easier to see at a glance what the commands are when they're written as you'd copy and paste them to run - e.g. crossplane xpkg build rather than crossplane / xpkg / build all nested.

@negz
Copy link
Member Author

negz commented Oct 18, 2023

@plumbis I'd prefer to go in depth on documentation in a separate PR. If we get this merged today I can open a follow on to get started on some of the changes you suggested.

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.

I'm pretty good with this major refactor and major clean-up which puts us into good position for feature freeze to continue with polish and further CLI improvements.

Biggest question is on the removal of the generated clientset stuff, please help me understand that one! 🙇‍♂️

@@ -58,12 +58,6 @@ limitations under the License.
//go:generate go run -tags generate github.com/jmattheis/goverter/cmd/goverter -output ./apiextensions/v1/zz_generated.conversion.go -packageName v1 -packagePath=github.com/crossplane/crossplane/apis/apiextensions/v1 ./apiextensions/v1
//go:generate go run -tags generate github.com/jmattheis/goverter/cmd/goverter -output ./pkg/meta/v1alpha1/zz_generated.conversion.go -packageName v1alpha1 -packagePath=github.com/crossplane/crossplane/apis/pkg/meta/v1alpha1 ./pkg/meta/v1alpha1

// Generate clientset for types.
Copy link
Member

Choose a reason for hiding this comment

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

I see all the clientset files getting removed in this PR too - are they just stale code that aren't used anywhere so it's time for them to go, or is it related to the CLI in some way? 🤔

Is there any announcement about their removal that needs to be included in the release notes?

Copy link
Member Author

Choose a reason for hiding this comment

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

As far as I can tell they were only being used by the package install and update CLI commands, which now use the controller-runtime client instead. I don't think we need to announce anything. They were in the internal package, so no one would have been able to use them before.

// initCmd initializes a new package repository from a template repository.
type initCmd struct {
Name string `arg:"" help:"Name of the package to initialize."`
Template string `arg:"" help:"Template to initialize the package from."`
Copy link
Member

Choose a reason for hiding this comment

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

should this argument mention here that it can be a URL too? when reading the full help output i had forgotten that nuance by the time i got to this line 😅

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably yes. I tried a few times but it was tough to come up with a succinct way to do this. Mind if we add this to the list for a follow-up PR more focused on CLI help output?

Copy link
Member

Choose a reason for hiding this comment

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

yep! not a blocker for me :)

@@ -1,261 +0,0 @@
/*
Copy link
Member

Choose a reason for hiding this comment

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

very cool to already clean up the xpkg/v2 temp package also - you're getting a ton of things clean in this PR @negz!! 🧹 🗑️

@negz negz merged commit 96f8e7f into crossplane:master Oct 18, 2023
16 checks passed
@negz negz deleted the redecorating branch October 18, 2023 22:18
@negz negz mentioned this pull request Oct 18, 2023
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants