Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Allow specifying client config fully from envvars#504

Merged
mangelajo merged 1 commit intojumpstarter-dev:mainfrom
NickCao:env-settings
May 28, 2025
Merged

Allow specifying client config fully from envvars#504
mangelajo merged 1 commit intojumpstarter-dev:mainfrom
NickCao:env-settings

Conversation

@NickCao
Copy link
Copy Markdown
Collaborator

@NickCao NickCao commented May 27, 2025

Close-Issue: #502

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Configuration can now be managed via environment variables, improving flexibility for different deployment scenarios.
  • Refactor

    • Configuration classes have been updated to use enhanced settings management, streamlining environment variable support and validation.
    • Internal logic for loading and handling configuration has been simplified and modernized.
  • Chores

    • Dependency on pydantic-settings has been added for improved configuration handling.
  • Tests

    • Tests have been updated to reflect changes in configuration class structure and naming.

@netlify
Copy link
Copy Markdown

netlify Bot commented May 27, 2025

Deploy Preview for jumpstarter-docs ready!

Name Link
🔨 Latest commit 3362918
🔍 Latest deploy log https://app.netlify.com/projects/jumpstarter-docs/deploys/683723ac9ca83f000843a02b
😎 Deploy Preview https://deploy-preview-504--jumpstarter-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 27, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The changes refactor client configuration management to use pydantic_settings.BaseSettings for environment variable support, update related test code to match new class names and structure, and adjust utility functions and dependencies accordingly. Manual environment variable parsing is removed in favor of pydantic's built-in features, and test imports are updated.

Changes

Files/Paths Change Summary
packages/jumpstarter/jumpstarter/config/client.py,
.../common.py
Refactor config classes to use BaseSettings, add environment variable support, new metadata class, update drivers logic, remove manual env parsing.
packages/jumpstarter/jumpstarter/config/client_config_test.py,
.../user_config_test.py
Update tests to fix imports and attribute usage (name to alias), adjust mocked config instances accordingly.
packages/jumpstarter/jumpstarter/utils/env.py Replace manual env parsing with ClientConfigV1Alpha1Drivers instantiation, update logic to match new config.
packages/jumpstarter-cli-common/jumpstarter_cli_common/config.py Update default config loading logic to use new instantiation and error handling approach.
packages/jumpstarter/pyproject.toml Add pydantic-settings>=2.9.1 as a dependency.

Sequence Diagram(s)

sequenceDiagram
    participant Env as Environment Variables
    participant Settings as ClientConfigV1Alpha1 (BaseSettings)
    participant Drivers as ClientConfigV1Alpha1Drivers
    participant App as Application

    App->>Settings: Instantiate (loads config from env)
    Settings->>Drivers: Instantiate (loads drivers from env)
    Drivers->>Env: Read JMP_DRIVERS_ALLOW, JMP_DRIVERS_UNSAFE, etc.
    Drivers-->>Settings: Return drivers config
    Settings-->>App: Return full client config
Loading

Possibly related PRs

Suggested reviewers

  • bennyz

Poem

In the warren, configs bloom anew,
With settings from Pydantic's view.
No more manual env to parse,
Just classes, clean and up to par.
Tests now hop with names that fit,
This rabbit's proud—it's quite a hit!
🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bae7fe6 and 3362918.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (7)
  • packages/jumpstarter-cli-common/jumpstarter_cli_common/config.py (2 hunks)
  • packages/jumpstarter/jumpstarter/config/client.py (4 hunks)
  • packages/jumpstarter/jumpstarter/config/client_config_test.py (0 hunks)
  • packages/jumpstarter/jumpstarter/config/common.py (2 hunks)
  • packages/jumpstarter/jumpstarter/config/user_config_test.py (3 hunks)
  • packages/jumpstarter/jumpstarter/utils/env.py (2 hunks)
  • packages/jumpstarter/pyproject.toml (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0df30b1 and a422cf7.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (7)
  • packages/jumpstarter-cli-common/jumpstarter_cli_common/config.py (2 hunks)
  • packages/jumpstarter/jumpstarter/config/client.py (5 hunks)
  • packages/jumpstarter/jumpstarter/config/client_config_test.py (0 hunks)
  • packages/jumpstarter/jumpstarter/config/env.py (1 hunks)
  • packages/jumpstarter/jumpstarter/config/user_config_test.py (2 hunks)
  • packages/jumpstarter/jumpstarter/utils/env.py (2 hunks)
  • packages/jumpstarter/pyproject.toml (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/jumpstarter/jumpstarter/config/client_config_test.py
🧰 Additional context used
🧬 Code Graph Analysis (1)
packages/jumpstarter/jumpstarter/utils/env.py (2)
packages/jumpstarter/jumpstarter/config/client.py (1)
  • ClientConfigV1Alpha1Drivers (37-54)
packages/jumpstarter/jumpstarter/client/client.py (1)
  • client_from_path (16-20)
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: Redirect rules - jumpstarter-docs
  • GitHub Check: Header rules - jumpstarter-docs
  • GitHub Check: Pages changed - jumpstarter-docs
  • GitHub Check: pytest-matrix (macos-15, 3.13)
  • GitHub Check: pytest-matrix (macos-15, 3.12)
  • GitHub Check: pytest-matrix (ubuntu-24.04, 3.12)
  • GitHub Check: pytest-matrix (macos-15, 3.11)
  • GitHub Check: pytest-matrix (ubuntu-24.04, 3.13)
  • GitHub Check: pytest-matrix (ubuntu-24.04, 3.11)
  • GitHub Check: e2e
🔇 Additional comments (11)
packages/jumpstarter/pyproject.toml (1)

21-21: LGTM! Dependency addition supports the BaseSettings refactoring.

The addition of pydantic-settings>=2.9.1 is necessary to support the migration from pydantic.BaseModel to pydantic_settings.BaseSettings for enhanced environment variable configuration support.

packages/jumpstarter/jumpstarter/config/user_config_test.py (1)

63-63: LGTM! Test updates align with model field renaming.

The changes from name="testclient" to alias="testclient" correctly update the test mocks to match the field renaming in the refactored ClientConfigV1Alpha1 model.

Also applies to: 90-90

packages/jumpstarter/jumpstarter/utils/env.py (2)

7-7: LGTM! Import updated to use the new settings model.

The import change from _allow_from_env to ClientConfigV1Alpha1Drivers aligns with the refactoring to use pydantic settings for environment variable handling.


24-32: LGTM! Improved environment variable handling with pydantic settings.

The replacement of manual environment parsing with ClientConfigV1Alpha1Drivers() instantiation leverages the robust validation and parsing capabilities of pydantic settings. The ClientConfigV1Alpha1Drivers class handles comma-separated string parsing and automatic unsafe flag detection, providing better error handling and validation than the previous manual approach.

packages/jumpstarter/jumpstarter/config/env.py (1)

4-8:

Details

✅ Verification successful

Environment variable renaming looks good and aligns with the new settings approach.

The updated environment variable names with the JMP_CLIENT_ prefix are consistent with the BaseSettings configuration in client.py and provide better clarity about their purpose.

However, please ensure that any existing documentation, deployment scripts, or user configurations that reference the old environment variable names are updated accordingly, as this is a breaking change.


🏁 Script executed:

#!/bin/bash
# Description: Check for any remaining references to the old environment variable names in the codebase
# Expected: No references to old names like JMP_NAMESPACE, JMP_NAME, etc. (excluding this env.py file)

echo "Searching for old environment variable names..."
rg -g '!*/config/env.py' '\b(JMP_NAMESPACE|JMP_NAME|JMP_ENDPOINT|JMP_TOKEN|JMP_DRIVERS_ALLOW)\b' --type py

Length of output: 4122


Environment variable renaming approved – no code changes required

  • All internal code (tests, utilities, etc.) imports and uses the updated constants (JMP_NAMESPACE, JMP_NAME, JMP_ENDPOINT, JMP_TOKEN, JMP_DRIVERS_ALLOW), so nothing else needs updating in the repo.
  • No stray references to the old environment‐variable literals remain in the codebase.
  • Reminder: you’ll still need to update any external documentation, deployment scripts or user configurations that hard-code the old names to use the new JMP_CLIENT_* keys.
packages/jumpstarter/jumpstarter/config/client.py (6)

7-7: Import changes look appropriate for the BaseSettings migration.

The addition of pydantic_settings imports and the updated pydantic imports are correctly aligned with the refactoring to use BaseSettings.

Also applies to: 12-13


37-55: Excellent implementation of environment variable parsing with validation.

The ClientConfigV1Alpha1Drivers class properly extends BaseSettings and includes well-designed validators:

  • decode_allow correctly parses comma-separated strings into lists
  • decode_unsafe properly detects the "UNSAFE" flag from the allow list
  • The use of NoDecode annotation prevents automatic decoding before custom validation

60-63: Model configuration is well-designed for environment variable support.

The SettingsConfigDict with env_prefix="JMP_CLIENT_" and env_nested_delimiter="_" properly aligns with the updated environment variable names and enables automatic parsing of nested configuration from environment variables.


71-71: Good use of default factories for mutable defaults.

Using Field(default_factory=...) for metadata and drivers fields is the correct approach to avoid shared mutable defaults across instances.

Also applies to: 78-78


214-214: Simplified from_env() method is appropriate.

The simplified implementation that just returns cls() is correct because BaseSettings automatically handles environment variable loading during instantiation.


279-279: BaseSettings migration for ClientConfigListV1Alpha1 is consistent.

The update to extend BaseSettings instead of BaseModel is consistent with the overall refactoring approach and maintains the existing model configuration.

Also applies to: 291-291

Comment thread packages/jumpstarter-cli-common/jumpstarter_cli_common/config.py Outdated
Comment thread packages/jumpstarter/jumpstarter/config/client.py
Comment thread packages/jumpstarter/jumpstarter/config/env.py Outdated
Copy link
Copy Markdown
Member

@mangelajo mangelajo left a comment

Choose a reason for hiding this comment

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

Is there a way to use explicit env var names for fields?

@NickCao
Copy link
Copy Markdown
Collaborator Author

NickCao commented May 28, 2025

Is there a way to use explicit env var names for fields?

There is validation_alias, I'll try those.

@NickCao
Copy link
Copy Markdown
Collaborator Author

NickCao commented May 28, 2025

Is there a way to use explicit env var names for fields?

There is, but it does work as what we would expect, e.g. I can set validation_alias to JMP_TOKEN, and make environment variables work, however this breaks loading from yaml, since it's now expecting JMP_TOKEN: foo too, while I can again, modify validation_alias to AliasChoice("token", JMP_TOKEN), but then it also takes the environment variable TOKEN (without the JMP_) prefix as an input, still not something we want.

@NickCao NickCao force-pushed the env-settings branch 2 times, most recently from 07f5e77 to e9db9b2 Compare May 28, 2025 14:51
assert config.metadata.name == "testclient"
assert config.token == "dGhpc2lzYXRva2VuLTEyMzQxMjM0MTIzNEyMzQtc2Rxd3Jxd2VycXdlcnF3ZXJxd2VyLTEyMzQxMjM0MTIz"
assert config.endpoint == "jumpstarter.my-lab.com:1443"
assert config.drivers.allow == []
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why was this necessary?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Since it would now be ["UNSAFE"], but it's effectively ignored later on (as long as unsafe is True), so we don't really care about it's value.

@mangelajo mangelajo merged commit 9a72726 into jumpstarter-dev:main May 28, 2025
18 checks passed
@mangelajo mangelajo added the backport release-0.6 Backport PR to release-0.6 branch label Jun 4, 2025
@jumpstarter-backport-bot
Copy link
Copy Markdown

Backport failed for release-0.6, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin release-0.6
git worktree add -d .worktree/backport-504-to-release-0.6 origin/release-0.6
cd .worktree/backport-504-to-release-0.6
git switch --create backport-504-to-release-0.6
git cherry-pick -x 336291891d40b6b88be6530dfecf0f7865ea5b76

@NickCao NickCao deleted the env-settings branch June 5, 2025 13:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

backport release-0.6 Backport PR to release-0.6 branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants