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

[ENG-121] rpk: add rpk connect as a managed plugin #23117

Merged
merged 4 commits into from
Sep 11, 2024

Conversation

r-vasquez
Copy link
Contributor

@r-vasquez r-vasquez commented Aug 29, 2024

This PR introduces the required changes to have rpk connect as a managed plugin. The main behavior change is that from now on, rpk will try to download connect when running for the first time, similar to what we do with rpk cloud byoc.

It also introduces 3 new commands to rpk connect: install, uninstall, upgrade.

Fixes https://github.com/redpanda-data/devex/issues/45

Usage

Most common use case:

$ rpk connect run /config.yaml

^ That's it, it will download the connect plugin on the fly and then execute the command.
rpk won't update connect automatically unless you run rpk connect upgrade.

Manual Process

Install

# Install latest
$ rpk connect install
# Install specific version
$ rpk connect install --conect-version
# Install specific version if you already have connect installed
$ rpk connect uninstall
$ rpk connect install --connect-version  <version>
# or
$ rpk connect install --connect version <version> --force

Upgrade:

$ rpk connect upgrade

rpk only upgrades to latest, for specific versions use rpk connect install.

Uninstall:

$ rpk connect uninstall

Backports Required

  • none - not a bug fix
  • none - this is a backport
  • none - issue does not exist in previous branches
  • none - papercut/not impactful enough to backport
  • v24.2.x
  • v24.1.x
  • v23.3.x

Release Notes

Improvements

  • rpk connect will be downloaded on the first run.
  • rpk: introduce rpk connect install, rpk connect upgrade, and rpk connect uninstall, manual ways to manage rpk connect versioning.

@r-vasquez
Copy link
Contributor Author

/dt

twmb
twmb previously approved these changes Aug 30, 2024
src/go/rpk/pkg/cli/connect/client.go Outdated Show resolved Hide resolved
Comment on lines 46 to 76
out.MaybeDie(err, "unable to parse flags: %v", err)
connect, pluginExists := plugin.ListPlugins(fs, plugin.UserPaths()).Find("connect")
var pluginPath string
if !pluginExists {
path, err := installConnect(cmd.Context(), fs, "latest")
out.MaybeDie(err, "unable to install Redpanda Connect: %v", err)
pluginPath = path
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't we only want to install the plugin if a person uses rpk connect <something else>? As in, don't force install a plugin if a person just does rpk connect -h?

Also, if we do install, here we probably want to print some message like, "connect plugin not found, downloading" etcetc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Connect can be run without any subcommand.

If you run rpk connect it starts a service, that's the main difference with byoc and that's why I chose to install it even for a --help

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 @Jeffail added rpk connect run. Can we block rpk connect -c / hijack it to not start the service, and rely entirely on subcommands?

Copy link
Contributor Author

@r-vasquez r-vasquez Sep 6, 2024

Choose a reason for hiding this comment

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

Changed how it works, now:

When running without connect being installed:

$ rpk connect
<Help text of the rpk bits: install, uninstall and upgrade>

$ rpk connect --help
<same as above>

$ rpk connect --version
cannot get connect version: rpk connect is not installed; run 'rpk connect install'
<Help text>

$ rpk connect -c foo...
-c flag is not supported by this command; run 'rpk connect run' instead

If connect is installed, we will pass the flags to redpanda connect and they will work properly

src/go/rpk/pkg/cli/connect/uninstall.go Outdated Show resolved Hide resolved
@@ -106,6 +106,9 @@ func StripFlags(args []string, fs *pflag.FlagSet, long []string, short []string)
if f == nil || !strip {
inFlag = len(kv) == 1
keep = append(keep, arg) // either we are keeping this flag, or it is not in our flag set so we cannot strip it
if i+1 < len(args) && strings.HasPrefix(args[i+1], "-") {
inFlag = false
Copy link
Contributor

Choose a reason for hiding this comment

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

Why? I think this is trying to detect the case of a bool flag, --verbose --anotherthing=whatever.

However if the first flag is --foo -bar, can't -bar be the value for --foo?

I think the logic you want here is IF the flag exists, then check if the flag is a bool flag. If so, THEN we can do this logic.

Copy link
Contributor Author

@r-vasquez r-vasquez Sep 7, 2024

Choose a reason for hiding this comment

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

Why? I think this is trying to detect the case of a bool flag, --verbose --anotherthing=whatever.

Yes, that's correct. I've added a new comment.

However if the first flag is --foo -bar, can't -bar be the value for --foo?

Yes, it can be.

I think the logic you want here is IF the flag exists, then check if the flag is a bool flag. If so, THEN we can do this logic.

No, it can't be.

At this point, we know that the flag does not exist in rpk, we check this a couple of lines above. We cannot check if the flag is boolean because it's an unknown flag to rpk.

This flag is not used at the moment but it was
missing the shorthand parsing.
This commit fixes a bug where if we were parsing
a boolean long flag (let's say: --version), we
will end up keeping the next argument after the flag, even if it was not needed.
We supported JSON and XML, now we add YAML.
@vbotbuildovich
Copy link
Collaborator

vbotbuildovich commented Sep 7, 2024

new failures in https://buildkite.com/redpanda/redpanda/builds/54125#0191c9eb-0513-415b-8ea6-1ece0e09bea1:

"rptest.tests.rpk_connect_test.RpkConnectTest.test_upgrade"

new failures in https://buildkite.com/redpanda/redpanda/builds/54125#0191ca00-e812-425c-9639-0a07b0639654:

"rptest.tests.rpk_connect_test.RpkConnectTest.test_upgrade"

This change means that from now on, connect will
be managed by rpk, so, if a user tries to run
`rpk connect <...>` for the first time, rpk will
download, install and execute the plugin (connect).

It also introduces 3 new commands to `rpk conenct`
that live in rpk: install, uninstall, and upgrade.
@r-vasquez r-vasquez merged commit 35bbc27 into redpanda-data:dev Sep 11, 2024
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants