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

Add controlplane create and delete commands #14

Merged
merged 11 commits into from
Apr 27, 2021

Conversation

hasheddan
Copy link
Contributor

Also adds a common cloud.Context that we populate and pass to subcommands so that it can be progressively modified as argument tree is traversed.

Fixes #13

Updates method to get default cloud profile to also return id of the
profile.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
Introduces an internal cloud package with common functions that are used
across mutltiple subgroups. Also introduces a cloud context which can be
received by any command in the cloud group.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
Refactors cloud and login commands to build config at the cloud level
and pass it to any subcommands. This reduces the number of parameters
that commands can receieve and also allows for progressive building of
the config if applicable.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
up cloud controlplane create allows a user to create a new hosted
control plane on Upbound cloud.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
up cloud controlplane delete allows a user to delete a control plane on
Upbound Cloud.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
Adds the controlplane commands subgroup to cloud commands and constructs
a common client that can be received by all controlplane subcommands.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
Overrides control-plane to controlplane and also support alias to xp.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
Changes up cloud controlplane alias to up cloud xp.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
Adds comments to exported functions in the cloud package.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
Comment on lines +14 to +15
// TODO(hasheddan): consider using name instead of ID
ID uuid.UUID `arg:"" required:"" help:"ID of control plane."`
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that we are currently using the control plane ID. We may opt to do this by name in the future, but I am sticking with this implementation for the time being pending implementing a new API endpoint for deleting by name. If we do not end up adding that endpoint, we would need to list control planes for the user and match id to provided name before calling delete.

Updates the extraction performed at the cloud config level to only fetch
the config itself, but not attempt to identify the profile. This is more
accommodating for allowing both commands that require the profile and
those which create a profile (i.e. login) to consume this functionality.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
}
cloudCtx.ID = id
} else {
profile, err = cloudCtx.Cfg.GetCloudProfile(cloudCtx.ID)
Copy link
Member

Choose a reason for hiding this comment

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

It looks like we identify profiles per id (username, email or token ID). This sounds a bit limited/confusing to me, since profile also keeps org name as well. So, as hasan@upbound.io, I may want to have two profiles, one for my user org (or namespace) and one for hasan-testorg and this seems not to be possible. I thought we have ability to name profiles independently similar to aws cli: https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We do restrict the default org for a given ID, but you can always override for any command by passing -o myorg so I don't feel like this is super restrictive. To me it feels a bit more confusing how AWS does it where your profile name may be somewhat arbitrary. I like that we say "when you are authenticated with this user you will use this default account", but you can always override at command invocation time.

Copy link
Member

Choose a reason for hiding this comment

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

yeah, but there is no one-to-one mapping between a user and a profile (which includes org).
as mentioned, users might want to define multiple profiles for 1 user for different orgs. Of course, one can always override default org with the flag but this is a bit confusing UX-wise since it does not provide expected functionality especially since we support multiple profiles.

Maybe, I am expecting something different than the intended functionality of "profiles" but gcloud also allows giving arbitrary names to configurations: https://cloud.google.com/sdk/gcloud/reference/config/configurations/create

Copy link
Member

@turkenh turkenh Apr 26, 2021

Choose a reason for hiding this comment

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

I would prefer to key profiles as something constant (for now?) like default and leave the possibility to extend with adding/removing/updating new (named) profiles through cli.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, I personally don't prefer this pattern as it requires passing something like -p my-profile rather than -u hasheddan, but I do agree that it is more flexible for future changes. That being said, we don't currently have as complex of an auth model as GCP and AWS (I was looking more at how Docker stores configuration as reference here). How would you feel about me following up with a revision to how we store credentials after this PR as it will deviate from the agreed upon design so we will likely need more folks to weigh in?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that sounds good to me.
I think I am mostly confused since we seem to support multiple profiles but still want to keep things simple :)

org = c.Organization
}
if org == "" {
org = id
Copy link
Member

Choose a reason for hiding this comment

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

This defaulting seems problematic:

  • If identifier is a token or email, this wouldn't work since no corresponding org (uuid or email)
  • Org, I set in my profile will always be overridden?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch -- the idea here was that we would do this defaulting at cloud level, then override in subgroups (like controlplane) when we actually extract the profile. However, this needs to be revised to:

  1. At cloud level we will set cloudCtx.Org to c.Organization.
  2. In controlplane we will extract profile and if cloudCtx.Org == "", we will set it to the default in the profile.
  3. If there is no default org in the profile, we try with the id (which will fail if not username).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@turkenh updated here 👍

// Run executes the create command.
func (c *CreateCmd) Run(kong *kong.Context, client *cp.Client, cloudCtx *cloud.Context) error {
_, err := client.Create(context.Background(), &cp.ControlPlaneCreateParameters{
Namespace: cloudCtx.Org,
Copy link
Member

Choose a reason for hiding this comment

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

Did we use org in profile anywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It should be extracted at controlplane level, but that was missed so will update 👍

_, err := client.Create(context.Background(), &cp.ControlPlaneCreateParameters{
Namespace: cloudCtx.Org,
Name: c.Name,
Description: c.Description,
Copy link
Member

Choose a reason for hiding this comment

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

Any reason not to support passing self-hosted flag as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

self-hosted will be encompassed by up cloud controlplane attach (see #4) because there was a desire to keep the hosted and self-hosted flows completely separate

Comment on lines +27 to +28
Cfg *config.Config
CfgSrc config.Source
Copy link
Member

Choose a reason for hiding this comment

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

Just wondering whether it would be cleaner if we could handle config/profile handling/defaulting before passing context down to individual commands and only have Session here instead of Cfg and CfgSrc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I actually did that initially, but that doesn't work for commands like up cloud login which need access to actually write / modify the config file. This will also be true for user and org commands that update defaults

Updates cloud hook to not default org to id and instead defer to after
profile extraction so that the default profile org will be used when
set.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
@hasheddan hasheddan requested a review from turkenh April 26, 2021 21:47
Copy link
Member

@turkenh turkenh left a comment

Choose a reason for hiding this comment

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

Thanks, @hasheddan, lgtm!
Although I have some comments around UX, I agree that this could be improved with follow-up PRs/discussions and should not be a blocker here.

}
// If no org is set in profile, use the ID.
if cloudCtx.Org == "" {
cloudCtx.Org = cloudCtx.ID
Copy link
Member

@turkenh turkenh Apr 26, 2021

Choose a reason for hiding this comment

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

I would prefer to fail explicitly (e.g. no org set) here if id is not a username. Otherwise, the error would be something like, no org named hasan@upbound.io or no org named 11501427-76ee-4da8-9147-4bf92abfe4be which might be hard to figure out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@turkenh that's fair 👍 That being said, I would like to default to the user account if no org is specified. We could move this to functionality to login though so that we actually set the default org in the config.json if logging in as user, then error if no default is set. I would like to also follow up with this in the potential changes to the profile because it will be affected by that behavior. I am going to be writing up an issue today for folks to weigh in on :)

}
cloudCtx.ID = id
} else {
profile, err = cloudCtx.Cfg.GetCloudProfile(cloudCtx.ID)
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that sounds good to me.
I think I am mostly confused since we seem to support multiple profiles but still want to keep things simple :)

@hasheddan hasheddan merged commit be2c26a into upbound:main Apr 27, 2021
sttts pushed a commit to sttts/upbound-up that referenced this pull request Sep 6, 2024
* fix(xpkg): func xpkg dep for functions

Signed-off-by: Christopher Haar <christopher.haar@upbound.io>

* fix(xpkg): func xpkg dep for functions

Signed-off-by: Christopher Haar <christopher.haar@upbound.io>

* feat(bump): update native list because of new resource-kinds after bump k8 versions

Signed-off-by: Christopher Haar <christopher.haar@upbound.io>

* feat(xpkg): dep tests adoption

Signed-off-by: Christopher Haar <christopher.haar@upbound.io>

* fix(xpkg): func xpkg dep for functions

Signed-off-by: Christopher Haar <christopher.haar@upbound.io>

---------

Signed-off-by: Christopher Haar <christopher.haar@upbound.io>
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.

Implement up cloud controlplane commands
2 participants