upbound / up

The @upbound CLI
Apache License 2.0
51 stars 41 forks source link

Allow creating new space profiles by name #400

Closed branden closed 9 months ago

branden commented 9 months ago

Description of your changes

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

Fixes #399.

I have:

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 %
sttts commented 9 months ago

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

branden commented 9 months ago

@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 commented 9 months ago

@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.

sttts commented 9 months ago

Created https://github.com/upbound/up/issues/404 for the space init part.

branden commented 9 months ago

@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 commented 9 months ago

@branden perfect help text. Thanks!

sttts commented 9 months ago

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 commented 9 months ago

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