upbound / up

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

Add Spaces profiles #380

Closed branden closed 11 months ago

branden commented 11 months ago

Description of your changes

This adds support for profiles that work with a Space.

Fixes #373

I have:

How has this code been tested

branden@crateria kind % up profile list
No profiles found

branden@crateria kind % kubectl config current-context
kind-kind
branden@crateria kind % up space init --token-file="${SPACES_TOKEN_PATH}" "v${SPACES_VERSION}" \
  --set "ingress.host=${SPACES_ROUTER_HOST}" \
  --set "clusterType=${SPACES_CLUSTER_TYPE}" \
  --set "account=${UPBOUND_ACCOUNT}"
 INFO  Setting defaults for vanilla Kubernetes (type kind)
 WARNING  One or more required prerequisites are not installed:

❌ cert-manager
❌ universal-crossplane
❌ ingress-nginx
❌ provider-kubernetes
❌ provider-helm

Would you like to install them now? [y/N]: Yes

  √   [1/5]: Installing cert-manager
  √   [2/5]: Installing universal-crossplane
  √   [3/5]: Installing ingress-nginx
  √   [4/5]: Installing provider-kubernetes
  √   [5/5]: Installing provider-helm
 INFO  Required prerequisites met!
 INFO  Proceeding with Upbound Spaces installation...
  √   [1/3]: Creating pull secret upbound-pull-secret
  √   [2/3]: Initializing Space components
  √   [3/3]: Starting Space Components
  🙌  Your Upbound Space is Ready!

  👀  Next Steps 👇

👉 Check out Upbound Spaces docs @ https://docs.upbound.io/concepts/upbound-spaces
branden@crateria kind % up profile list
CURRENT   NAME      TYPE     ACCOUNT   KUBECONFIG   KUBECONTEXT
*         default   spaces                          kind-kind

branden@crateria kind % up profile view
{
    "default": {
        "type": "spaces",
        "kube_context": "kind-kind"
    }
}
branden@crateria kind % kubectl config use-context kind-kuttl-test # set default kubecontext to an old context for a nonexistent cluster to demonstrate that the profile doesn't depend on the default kubecontext
Switched to context "kind-kuttl-test".
branden@crateria kind % up space upgrade --token-file="${SPACES_TOKEN_PATH}" "v${SPACES_VERSION}"

  √   Upgrading Space from v1.0.1 to v1.0.1

branden@crateria kind % up ctp list
up: error: controlplane.listCmd.Run(): list is not supported for Spaces profile "default"
branden@crateria kind % up ctp get foo
up: error: controlplane.getCmd.Run(): get is not supported for Spaces profile "default"
branden@crateria kind % up ctp kubeconfig get --token=whatever foo
up: error: kubeconfig.getCmd.Run(): get is not supported for Spaces profile "default"
branden@crateria kind % up ctp connect foo bar
up: error: controlplane.connectCmd.Run(): connect is not supported for Spaces profile "default"
branden@crateria kind % up ctp create foo --configuration-name=foo
up: error: controlplane.createCmd.Run(): create is not supported for Spaces profile "default"
branden@crateria kind % up ctp pull-secret create
up: error: pullsecret.createCmd.AfterApply(): create is not supported for Spaces profile "default"
branden@crateria kind % up login --token=$UP_TOKEN
3122e6b9-78c3-4264-995f-068364b00051 logged in
branden@crateria kind % up profile list
CURRENT   NAME      TYPE    ACCOUNT   KUBECONFIG   KUBECONTEXT
*         default   token   branden

branden@crateria kind % up profile view
{
    "default": {
        "id": "3122e6b9-78c3-4264-995f-068364b00051",
        "type": "token",
        "session": "REDACTED",
        "account": "branden"
    }
}
branden@crateria kind % up ctp list
up: error: controlplane.listCmd.Run(): Forbidden: {"message":"branden is not an organization and only organizations can manage control planes"}{"controlPlanes":[],"count":0,"page":0,"size":100}
branden@crateria kind % up space upgrade --token-file="${SPACES_TOKEN_PATH}" "v${SPACES_VERSION}"

up: error: space.upgradeCmd.AfterApply(): upgrade is not supported for non-Spaces profile "default"
branden@crateria kind % up space destroy
up: error: space.destroyCmd.AfterApply(): destroy is not supported for non-Spaces profile "default"
branden@crateria kind % up profile set space --kubecontext kind-kind
branden@crateria kind % up profile list
CURRENT   NAME      TYPE     ACCOUNT   KUBECONFIG   KUBECONTEXT
*         default   spaces                          kind-kind

branden@crateria kind % up profile view
{
    "default": {
        "type": "spaces",
        "kube_context": "kind-kind"
    }
}
branden@crateria kind % up space destroy

******************** DESTRUCTIVE COMMAND ********************
********************* DATA-LOSS WARNING *********************

 WARNING  Destroying Spaces is a destructive command that will destroy data and orphan resources.
 WARNING  Before proceeding ensure that Managed Resources in Control Planes have been deleted.
 WARNING  All Spaces components including Control Planes will be destroyed.

 WARNING  If you want to retain data, abort and run 'up space destroy --orphan'

To proceed, type: "CONFIRMED": CONFIRMED
branden@crateria kind % echo $?
0
branden@crateria kind %