Skip to content

Commit

Permalink
Merge pull request #23886 from r-vasquez/rpk-misc-ovt
Browse files Browse the repository at this point in the history
rpk: small improvements prior v24.2
  • Loading branch information
r-vasquez authored Oct 24, 2024
2 parents aa74fcb + 064e3fc commit 646071b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/go/rpk/pkg/cli/cloud/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 4 additions & 8 deletions src/go/rpk/pkg/cli/connect/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 3 additions & 5 deletions src/go/rpk/pkg/cli/registry/schema/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions src/go/rpk/pkg/cli/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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=<host address>`)
rpk version -X admin.hosts=<host address>
To get only the rpk version, use 'rpk --version'.`)
return
}
for _, v := range *rpv {
Expand Down
19 changes: 17 additions & 2 deletions src/go/rpk/pkg/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
)

Expand All @@ -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)
}
Expand All @@ -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
}

0 comments on commit 646071b

Please sign in to comment.