From a243704332a482ca2ca08162240d644bf6d51511 Mon Sep 17 00:00:00 2001 From: r-vasquez Date: Tue, 22 Oct 2024 11:28:44 -0700 Subject: [PATCH 1/4] rpk: add missing newline in login info --- src/go/rpk/pkg/cli/cloud/login.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/go/rpk/pkg/cli/cloud/login.go b/src/go/rpk/pkg/cli/cloud/login.go index bd30f27238b7c..9037434658774 100644 --- a/src/go/rpk/pkg/cli/cloud/login.go +++ b/src/go/rpk/pkg/cli/cloud/login.go @@ -135,7 +135,7 @@ rpk will talk to a localhost:9092 cluster until you swap to a different profile. if noProfile { // The current profile is seemingly pointing to a container cluster. if p.Name == common.ContainerProfileName { - fmt.Printf("You are talking to a localhost 'rpk container' cluster (rpk profile name: %q)", p.Name) + fmt.Printf("You are talking to a localhost 'rpk container' cluster (rpk profile name: %q)\n", p.Name) fmt.Println("To talk to a cloud cluster, use 'rpk cloud cluster select'.") return } From f8f0b5442d7ad6e0ab17278fad9627acde35b748 Mon Sep 17 00:00:00 2001 From: r-vasquez Date: Tue, 22 Oct 2024 12:03:15 -0700 Subject: [PATCH 2/4] rpk registry: fail if --format used with --print-schema Old behavior was to ignore --format, we better fail instead to avoid confusion --- src/go/rpk/pkg/cli/registry/schema/get.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/go/rpk/pkg/cli/registry/schema/get.go b/src/go/rpk/pkg/cli/registry/schema/get.go index a881b49d1ccde..5f4c98576ee71 100644 --- a/src/go/rpk/pkg/cli/registry/schema/get.go +++ b/src/go/rpk/pkg/cli/registry/schema/get.go @@ -50,12 +50,10 @@ To print the schema, use the '--print-schema' flag. Args: cobra.MaximumNArgs(1), Run: func(cmd *cobra.Command, args []string) { f := p.Formatter - var helpFormat any - helpFormat = []subjectSchema{} - if printSchema { - helpFormat = "" + if printSchema && f.Kind != "text" { + out.Die("--print-schema cannot be used along with --format %v", f.Kind) } - if h, ok := f.Help(helpFormat); ok { + if h, ok := f.Help([]subjectSchema{}); ok { out.Exit(h) } p, err := p.LoadVirtualProfile(fs) From dcfe7db5f0d42183cc04f46e89e1bfac6f56814c Mon Sep 17 00:00:00 2001 From: r-vasquez Date: Tue, 22 Oct 2024 12:16:41 -0700 Subject: [PATCH 3/4] rpk: improve help text of rpk version --- src/go/rpk/pkg/cli/version/version.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/go/rpk/pkg/cli/version/version.go b/src/go/rpk/pkg/cli/version/version.go index f2b466e901139..a543dd5231cee 100644 --- a/src/go/rpk/pkg/cli/version/version.go +++ b/src/go/rpk/pkg/cli/version/version.go @@ -60,7 +60,9 @@ This command prints the current rpk version and allows you to list the Redpanda version running on each node in your cluster. To list the Redpanda version of each node in your cluster you may pass the -Admin API hosts via flags, profile, or environment variables.`, +Admin API hosts using flags, profile, or environment variables. + +To get only the rpk version, use 'rpk --version'.`, Args: cobra.NoArgs, Run: func(cmd *cobra.Command, _ []string) { rv := rpkVersion{ @@ -131,7 +133,9 @@ func printClusterVersions(rpv *redpandaVersions) { if len(*rpv) == 0 { fmt.Println(` Unreachable, to debug, use the '-v' flag. To get the broker versions, pass the hosts via flags, profile, or environment variables: - rpk version -X admin.hosts=`) + rpk version -X admin.hosts= + + To get only the rpk version, use 'rpk --version'.`) return } for _, v := range *rpv { From 064e3fc2fe63632e98bbf95e0ea9e100235cb470 Mon Sep 17 00:00:00 2001 From: r-vasquez Date: Tue, 22 Oct 2024 13:10:17 -0700 Subject: [PATCH 4/4] rpk: increase plugin download timeout Also, add support for RPK_PLUGIN_DOWNLOAD_TIMEOUT in the plugin download path. It was previously used only for the connect repository client. --- src/go/rpk/pkg/cli/connect/client.go | 12 ++++-------- src/go/rpk/pkg/plugin/plugin.go | 19 +++++++++++++++++-- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/go/rpk/pkg/cli/connect/client.go b/src/go/rpk/pkg/cli/connect/client.go index e5c9098d77d9f..85dcc2fd6cb5d 100644 --- a/src/go/rpk/pkg/cli/connect/client.go +++ b/src/go/rpk/pkg/cli/connect/client.go @@ -16,9 +16,9 @@ import ( "net/http" "os" "runtime" - "time" "github.com/redpanda-data/redpanda/src/go/rpk/pkg/httpapi" + "github.com/redpanda-data/redpanda/src/go/rpk/pkg/plugin" ) const pluginBaseURL = "https://rpk-plugins.redpanda.com" @@ -75,13 +75,9 @@ type connectRepoClient struct { } func newRepoClient() (*connectRepoClient, error) { - timeout := 240 * time.Second - if t := os.Getenv("RPK_PLUGIN_DOWNLOAD_TIMEOUT"); t != "" { - duration, err := time.ParseDuration(t) - if err != nil { - return nil, fmt.Errorf("unable to parse RPK_PLUGIN_DOWNLOAD_TIMEOUT: %v", err) - } - timeout = duration + timeout, err := plugin.GetPluginDownloadTimeout() + if err != nil { + return nil, err } return &connectRepoClient{ cl: httpapi.NewClient( diff --git a/src/go/rpk/pkg/plugin/plugin.go b/src/go/rpk/pkg/plugin/plugin.go index e0bc82d9d88c8..883e0fcbc46b7 100644 --- a/src/go/rpk/pkg/plugin/plugin.go +++ b/src/go/rpk/pkg/plugin/plugin.go @@ -337,9 +337,13 @@ func WriteBinary(fs afero.Fs, name, dstDir string, contents []byte, autocomplete // If the url ends in ".gz", this unzips the binary before shasumming. If the // url ends in ".tar.gz", this unzips, then untars ONE file, then shasums. func Download(ctx context.Context, url string, isKnownCompressed bool, expShaPrefix string) ([]byte, error) { + timeout, err := GetPluginDownloadTimeout() + if err != nil { + return nil, err + } cl := httpapi.NewClient( httpapi.HTTPClient(&http.Client{ - Timeout: 100 * time.Second, + Timeout: timeout, }), ) @@ -366,7 +370,6 @@ func Download(ctx context.Context, url string, isKnownCompressed bool, expShaPre plugin = untar } - var err error if raw, err = io.ReadAll(plugin); err != nil { return nil, fmt.Errorf("unable to read plugin: %w", err) } @@ -381,3 +384,15 @@ func Download(ctx context.Context, url string, isKnownCompressed bool, expShaPre return raw, nil } + +func GetPluginDownloadTimeout() (time.Duration, error) { + timeout := 300 * time.Second + if t := os.Getenv("RPK_PLUGIN_DOWNLOAD_TIMEOUT"); t != "" { + duration, err := time.ParseDuration(t) + if err != nil { + return 0, fmt.Errorf("unable to parse RPK_PLUGIN_DOWNLOAD_TIMEOUT: %v", err) + } + timeout = duration + } + return timeout, nil +}