Adds named profiles for kinetic CLI configuration#212
Adds named profiles for kinetic CLI configuration#212JyotinderSingh wants to merge 2 commits intomainfrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a named profiles feature to the Kinetic CLI, allowing users to manage and switch between different infrastructure configurations (project, zone, cluster, and namespace) without manually setting environment variables. It adds a new profile command group for CRUD operations, implements persistent storage in ~/.kinetic/profiles.json, and updates the root CLI to inject profile settings as defaults for all relevant subcommands. Feedback was provided regarding code organization, specifically suggesting moving a local import to the top-level module imports.
| from kinetic.cli.profiles import ( | ||
| Profile, | ||
| ProfileError, | ||
| get_profile, | ||
| list_profiles, | ||
| remove_profile, | ||
| set_current, | ||
| upsert_profile, | ||
| validate_name, | ||
| ) |
There was a problem hiding this comment.
Add load_store to the top-level imports from kinetic.cli.profiles to avoid the need for a local import inside profile_create.
| from kinetic.cli.profiles import ( | |
| Profile, | |
| ProfileError, | |
| get_profile, | |
| list_profiles, | |
| remove_profile, | |
| set_current, | |
| upsert_profile, | |
| validate_name, | |
| ) | |
| from kinetic.cli.profiles import ( | |
| Profile, | |
| ProfileError, | |
| get_profile, | |
| list_profiles, | |
| load_store, | |
| remove_profile, | |
| set_current, | |
| upsert_profile, | |
| validate_name, | |
| ) |
There was a problem hiding this comment.
Consider the auto-suggestion above (if valid)
jeffcarp
left a comment
There was a problem hiding this comment.
Thanks! This should provide the foundation for more easily searching for spot capacity across clusters. Left some nits/suggestions
| console.print(" export KINETIC_CLUSTER=kinetic-cluster") | ||
| console.print(" export KINETIC_NAMESPACE=my-namespace") | ||
| console.print( | ||
| "Precedence: CLI flag > KINETIC_* env var > active profile > default." |
There was a problem hiding this comment.
This is great to mention here, do you want to link to the docs where we elaborate on this behavior?
https://kinetic.readthedocs.io/en/latest/configuration.html#precedence
| from kinetic.cli.profiles import ( | ||
| Profile, | ||
| ProfileError, | ||
| get_profile, | ||
| list_profiles, | ||
| remove_profile, | ||
| set_current, | ||
| upsert_profile, | ||
| validate_name, | ||
| ) |
There was a problem hiding this comment.
Consider the auto-suggestion above (if valid)
|
|
||
| @click.group() | ||
| def profile(): | ||
| """Manage named kinetic profiles (project/zone/cluster/namespace bundles).""" |
There was a problem hiding this comment.
You don't need a ... or pass here?
There was a problem hiding this comment.
Interesting it seems to be a feature of @click.group(). Looks weird but as long as it works 👍
| CLI flag > KINETIC_* env var > active profile field > built-in default | ||
| """ | ||
|
|
||
| from __future__ import annotations |
There was a problem hiding this comment.
I don't think we need this in the project
Summary
Introduces
kinetic profile— a command group for managing named infrastructure-target bundles (project, zone, cluster, namespace) so users can switch between configurations without re-exportingKINETIC_*env vars for every shell.Profiles slot into the existing config precedence chain as a new low-priority layer:
No existing command bodies or option signatures change. Profiles are additive: if no profile is saved or selected, today's env-var + prompt flow is preserved exactly.
New commands
kinetic profile create [NAME]KINETIC_*env vars, prompts for anything still unset. First profile created becomes active.kinetic profile ls*marks the active one, with an(override; stored: X)hint when--profile/KINETIC_PROFILEpoints at a non-current profile.kinetic profile use NAMEkinetic profile show [NAME]--profile/KINETIC_PROFILE, falling back to the stored active profile.kinetic profile rm NAME [--yes]Global flag (root group):
--profile NAME/KINETIC_PROFILE=NAME— one-shot override that selects a profile for this invocation without changing the stored active profile. Must appear before the subcommand:kinetic --profile prod up.kinetic config shownow surfaces the resolved active profile and a per-setting source column (profile / env var / default), making precedence discoverable.Design notes
~/.kinetic/profiles.jsonwith{"current": ..., "profiles": {...}}. Atomic writes via tempfile +os.replace. Stdlib only (no PyYAML dep added).cligroup callback resolves the active profile once and injects its fields intoctx.default_mapfor every subcommand. Click's built-in precedence order means CLI flags andKINETIC_*env vars still win — no existing command had to change.profilegroup carve-out: the resolved profile is stashed onctx.obj["active_profile"]for every subcommand includingprofile show/ls, butdefault_mapis not injected intoprofile create— we don't want a new profile to auto-inherit values from the currently-active one.profile ls,profile validate(usekinetic doctor --profile foo),profile edit, and richer profile fields (accelerator family, output policy). These can layer on cleanly.User Flow