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

Allow creating new space profiles by name #400

Merged
merged 9 commits into from
Oct 31, 2023

Conversation

branden
Copy link
Contributor

@branden branden commented Oct 26, 2023

Description of your changes

This makes up profile set space accept a nonexistent --profile. It will create that profile.

Fixes #399.

I have:

  • Read and followed Upbound's contribution process.
  • Run make reviewable to ensure this PR is ready for review.
  • Added backport release-x.y labels to auto-backport this PR, as appropriate.

How has this code been tested

Added unit tests.

branden@crateria kind % up profile list
CURRENT   NAME      TYPE    ACCOUNT   KUBECONFIG   KUBECONTEXT
*         default   space                          kind-kind

branden@crateria kind % up profile set space --profile=new
Profile "new" updated to use context "kind-kind" from the default kubeconfig and selected as the default profile

branden@crateria kind % up profile list
CURRENT   NAME      TYPE    ACCOUNT   KUBECONFIG   KUBECONTEXT
          default   space                          kind-kind
*         new       space                          kind-kind

branden@crateria kind % up profile set space --profile=default
Profile "default" updated to use context "kind-kind" from the default kubeconfig and selected as the default profile

branden@crateria kind % up profile list
CURRENT   NAME      TYPE    ACCOUNT   KUBECONFIG   KUBECONTEXT
*         default   space                          kind-kind
          new       space                          kind-kind

branden@crateria kind %

@branden branden requested a review from a team October 26, 2023 03:39
@@ -37,7 +37,7 @@ type Cmd struct {
// AfterApply constructs and binds Upbound-specific context to any subcommands
// that have Run() methods that receive it.
func (c *Cmd) AfterApply(kongCtx *kong.Context) error {
upCtx, err := upbound.NewFromFlags(c.Flags)
upCtx, err := upbound.NewFromFlags(c.Flags, upbound.AllowMissingProfile())
Copy link
Contributor

Choose a reason for hiding this comment

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

please fix the command description 10 lines above. This is not what the command is doing.

Copy link
Contributor

Choose a reason for hiding this comment

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

And be very explicit that this overrides the current profile.

@@ -44,13 +44,10 @@ func (c *spaceCmd) AfterApply(kongCtx *kong.Context) error {
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please implement a proper one or two paragraph help text.

@sttts
Copy link
Contributor

sttts commented Oct 26, 2023

We should also choose a new profile name in space init. Either here or in another PR.

p.Print(" and selected as the default profile")
}
p.Printf(
"Profile %q updated to use context %q from the %s and selected as the default profile",
Copy link
Contributor

Choose a reason for hiding this comment

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

"context" is not a term. Maybe "talk to Spaces via the current Kubernetes context %q" ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we check that it actually is a Spaces installation? We should.

return nil
}

func TestSpaceRun(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

SpaceRun?

return errors.Wrap(err, errSetProfile)
}
if err := upCtx.Cfg.SetDefaultUpboundProfile(upCtx.ProfileName); err != nil {
return errors.Wrap(err, errSetProfile)
Copy link
Contributor

Choose a reason for hiding this comment

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

technically selecting a profile is more than a set command should do. We have profile use for that purpose.

Copy link
Contributor

Choose a reason for hiding this comment

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

No strong opinion here. Just be very clear in the command documentation that profile selection happens.

Kube: upbound.KubeFlags{
Kubeconfig: kubeconfig,
},
},
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: isn't the cmd always the same? Why not create it below in the loop?

@branden
Copy link
Contributor Author

branden commented Oct 26, 2023

@sttts

We should also choose a new profile name in space init. Either here or in another PR.

Do we check that it actually is a Spaces installation? We should.

I'd like to keep this PR scoped to addressing #399. Could you file issues for these so we don't lose track of them?

@branden
Copy link
Contributor Author

branden commented Oct 26, 2023

@sttts I pushed some changes to address your comments, lmk what you think. Notably I put things back so that profile set space only updates the default profile when there are no existing profiles, since like you pointed out we already have profile use.

@branden branden requested a review from sttts October 26, 2023 18:26
@sttts
Copy link
Contributor

sttts commented Oct 26, 2023

Created #404 for the space init part.

@@ -29,15 +29,15 @@ type Cmd struct {
Use useCmd `cmd:"" help:"Set the default Upbound Profile to the given Profile."`
View viewCmd `cmd:"" help:"View the Upbound Profile settings across profiles."`
Config config.Cmd `cmd:"" help:"Interact with the current Upbound Profile's config."`
Set setCmd `cmd:"" help:"Create an Upbound Profile."`
Set setCmd `cmd:"" help:"Create or update an Upbound Profile."`
Copy link
Contributor

Choose a reason for hiding this comment

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

Set a profile (the current by default) to talk to a Space? set alone is not usable today. I would be explicit here, until we have another set subcommand.

Comment on lines 1 to 5
A Space profile communicates with a Space using a Kubernetes context from a kubeconfig
file. The kubeconfig and context may be selected using the --kubeconfig and
--kubecontext flags. If --kubeconfig is not provided, then the profile will use
the default kubeconfig at ~/.kube/config. If --kubecontext is not provided, then
the profile will use the kubeconfig's current default context.
Copy link
Contributor

@sttts sttts Oct 26, 2023

Choose a reason for hiding this comment

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

Suggested change
A Space profile communicates with a Space using a Kubernetes context from a kubeconfig
file. The kubeconfig and context may be selected using the --kubeconfig and
--kubecontext flags. If --kubeconfig is not provided, then the profile will use
the default kubeconfig at ~/.kube/config. If --kubecontext is not provided, then
the profile will use the kubeconfig's current default context.
Set a profile to be a Space profile. Use --profile to create a new profile.
By default the current profile is overwritten.
A Space profile communicates with a Space using a Kubernetes context from a kubeconfig
file. The kubeconfig and context may be selected using the --kubeconfig and
--kubecontext flags. If --kubeconfig is not provided, then the profile will use
the default kubeconfig at ~/.kube/config. If --kubecontext is not provided, then
the profile will use the kubeconfig's current default context.

Copy link
Contributor

Choose a reason for hiding this comment

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

Haven't looked deeply. The context name is stored, right? So the context selection happens on set space, not when a Space profile is used. This is not very clear in the current text.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah that's correct. Good point, I'll clarify this.

@branden
Copy link
Contributor Author

branden commented Oct 26, 2023

@sttts Here's how help text looks after the latest push:

branden@crateria up % ./_output/bin/darwin_arm64/up profile set -h
Usage: up profile set <command>

Set an Upbound Profile for use with a Space.

Flags:
  -h, --help                Show context-sensitive help.
      --format="default"    Format for get/list commands. Can be: json, yaml,
                            default
  -v, --version             Print version and exit.
  -q, --quiet               Suppress all output.
      --pretty              Pretty print output.

      --domain=https://upbound.io
                            Root Upbound domain ($UP_DOMAIN).
      --profile=STRING      Profile used to execute command ($UP_PROFILE).
  -a, --account=STRING      Account used to execute command ($UP_ACCOUNT).
      --insecure-skip-tls-verify
                            [INSECURE] Skip verifying TLS certificates
                            ($UP_INSECURE_SKIP_TLS_VERIFY).
  -d, --debug=INT           [INSECURE] Run with debug logging. Repeat
                            to increase verbosity. Output might contain
                            confidential data like tokens ($UP_DEBUG).

Commands:
  profile set space    Set an Upbound Profile for use with a Space.
branden@crateria up % ./_output/bin/darwin_arm64/up profile set space -h
Usage: up profile set space

Set an Upbound Profile for use with a Space.

By default the default profile is overwritten. Use --profile to create or update
a different profile.

A Space profile communicates with a Space using a Kubernetes context from
a kubeconfig file. The kubeconfig and context may be selected using the
--kubeconfig and --kubecontext flags. If --kubeconfig is not provided, then the
profile will use the default kubeconfig at ~/.kube/config. If --kubecontext is
not provided, then the profile will use the kubeconfig's current default context
at the time this command is run. Changing the kubeconfig's default context
afterward will not change which context the profile uses.

Flags:
  -h, --help                  Show context-sensitive help.
      --format="default"      Format for get/list commands. Can be: json, yaml,
                              default
  -v, --version               Print version and exit.
  -q, --quiet                 Suppress all output.
      --pretty                Pretty print output.

      --domain=https://upbound.io
                              Root Upbound domain ($UP_DOMAIN).
      --profile=STRING        Profile used to execute command ($UP_PROFILE).
  -a, --account=STRING        Account used to execute command ($UP_ACCOUNT).
      --insecure-skip-tls-verify
                              [INSECURE] Skip verifying TLS certificates
                              ($UP_INSECURE_SKIP_TLS_VERIFY).
  -d, --debug=INT             [INSECURE] Run with debug logging. Repeat
                              to increase verbosity. Output might contain
                              confidential data like tokens ($UP_DEBUG).

      --kubeconfig=STRING     Override default kubeconfig path.
      --kubecontext=STRING    Override default kubeconfig context.
branden@crateria up %

@sttts
Copy link
Contributor

sttts commented Oct 26, 2023

@branden perfect help text. Thanks!

@sttts
Copy link
Contributor

sttts commented Oct 26, 2023

Only quesiton that is left is about checking that it is a Space kube context. Checking for e.g. the mxe-controller deployment in upbound-system. Would do.

Then we are ready to go.

@sttts
Copy link
Contributor

sttts commented Oct 31, 2023

The Spaces check is a little beyond scope technically. Approving.

@sttts sttts merged commit cc61c8c into upbound:main Oct 31, 2023
6 checks passed
@branden branden deleted the set-create-profile branch October 31, 2023 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

up profile set space --profile won't create a new profile
2 participants