fix: improve run_as_user and run_as_group handling#7
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes the handling of run_as_user and run_as_group settings to allow explicitly setting these values to 0 (root user/group). The previous implementation using the or operator prevented setting user ID 0, as it would fall back to the workload default when the value was falsy.
Changes:
- Replaced
oroperator with explicitNonechecks forrun_as_userandrun_as_group - Applied the fix consistently to both Docker and Podman deployers
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| gpustack_runtime/deployer/podman.py | Updated user/group assignment logic to handle 0 values correctly |
| gpustack_runtime/deployer/docker.py | Applied identical fix to Docker deployer for consistency |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary of ChangesHello @yxf0314, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical bug in the container deployment logic for both Docker and Podman. It specifically targets the handling of Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request fixes a bug in how run_as_user and run_as_group are handled in both the Docker and Podman deployers. The previous implementation used or to fall back to workload-level settings, which incorrectly handled the valid case where run_as_user or run_as_group is 0. The fix correctly uses an is not None check to handle this. The logic is sound. I've added a couple of suggestions to improve the conciseness of the new code.
| run_as_user = ( | ||
| c.execution.run_as_user | ||
| if c.execution.run_as_user is not None | ||
| else workload.run_as_user | ||
| ) | ||
| run_as_group = ( | ||
| c.execution.run_as_group | ||
| if c.execution.run_as_group is not None | ||
| else workload.run_as_group | ||
| ) |
There was a problem hiding this comment.
While the logic is correct, these assignments can be written more concisely using single-line ternary operators. This improves readability by reducing the number of lines.
run_as_user = c.execution.run_as_user if c.execution.run_as_user is not None else workload.run_as_user
run_as_group = c.execution.run_as_group if c.execution.run_as_group is not None else workload.run_as_group| run_as_user = ( | ||
| c.execution.run_as_user | ||
| if c.execution.run_as_user is not None | ||
| else workload.run_as_user | ||
| ) | ||
| run_as_group = ( | ||
| c.execution.run_as_group | ||
| if c.execution.run_as_group is not None | ||
| else workload.run_as_group | ||
| ) |
There was a problem hiding this comment.
Similar to the change in docker.py, these assignments can be made more concise. Using single-line ternary operators would improve readability here.
run_as_user = c.execution.run_as_user if c.execution.run_as_user is not None else workload.run_as_user
run_as_group = c.execution.run_as_group if c.execution.run_as_group is not None else workload.run_as_group
gpustack/gpustack#3408
enable to set ContainerExecution.run_as_user=0