forked from redpanda-data/redpanda
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rpk: improve profile create, add cloud cluster use
- Loading branch information
Showing
8 changed files
with
411 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2023 Redpanda Data, Inc. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.md | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0 | ||
|
||
package cluster | ||
|
||
import ( | ||
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" | ||
"github.com/spf13/afero" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewCommand(fs afero.Fs, p *config.Params) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "cluster", | ||
Short: "Manage rpk cloud clusters", | ||
Long: `Manage rpk cloud clusters. | ||
This command allows you to manage cloud clusters, as well as easily switch | ||
between which cluster you are talking to. | ||
`, | ||
} | ||
|
||
cmd.AddCommand( | ||
newUseCommand(fs, p), | ||
) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2023 Redpanda Data, Inc. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.md | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0 | ||
|
||
package cluster | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
|
||
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/cli/profile" | ||
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/config" | ||
"github.com/redpanda-data/redpanda/src/go/rpk/pkg/out" | ||
"github.com/spf13/afero" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func newUseCommand(fs afero.Fs, p *config.Params) *cobra.Command { | ||
var profileName string | ||
|
||
cmd := &cobra.Command{ | ||
Use: "use [NAME]", | ||
Short: "Update your rpk profile to talk to the requested cluster", | ||
Long: `Update your rpk profile to talk to the requested cluster. | ||
This command is essentially an alias for the following command: | ||
rpk profile create --from-cloud=${NAME} | ||
If you want to name this profile rather than creating or updating values in | ||
the default cloud-dedicated profile, you can use the --profile flag. | ||
`, | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cfg, err := p.Load(fs) | ||
out.MaybeDie(err, "rpk unable to load config: %v", err) | ||
|
||
y, err := cfg.ActualRpkYamlOrEmpty() | ||
out.MaybeDie(err, "unable to load rpk.yaml: %v", err) | ||
|
||
err = profile.CreateFlow(cmd.Context(), fs, cfg, y, "", "", args[0], false, nil, profileName, "") | ||
if ee := (*profile.ProfileExistsError)(nil); errors.As(err, &ee) { | ||
fmt.Printf(`Unable to automatically create profile %q due to a name conflict with | ||
an existing self-hosted profile, please rename that profile or use the | ||
--profile flag to explicitly name your new profile. | ||
Either: | ||
rpk profile use %[1]q | ||
rpk profile rename-to $something_else | ||
rpk cloud cluster use %[2]q | ||
Or: | ||
rpk cloud cluster use %[2]q --profile $another_something | ||
`, ee.Name, args[0]) | ||
os.Exit(1) | ||
} | ||
out.MaybeDieErr(err) | ||
}, | ||
} | ||
|
||
cmd.Flags().StringVar(&profileName, "profile", "", fmt.Sprintf("Name of a profile to create or update (avoids updating %q)", profile.RpkCloudProfileName)) | ||
return cmd | ||
} |
Oops, something went wrong.