feat: Add privileged_client support to VirtualMachineInstance#2648
feat: Add privileged_client support to VirtualMachineInstance#2648
Conversation
Introduce explicit privileged_client parameter across VirtualMachineInstance methods to support proper RBAC-aware client usage. New public methods replacing deprecated properties: - get_virt_launcher_pod, get_virt_handler_pod, get_node, get_xml_dict Modified methods with privileged_client parameter: - pause, unpause, reset, get_xml, execute_virsh_command - get_dommemstat, get_domstate, wait_until_running, api_request New private helpers: - _get_pod_user_uid, _is_pod_root - _get_hypervisor_connection_uri, _build_virsh_cmd - _resolve_privileged_client, _get_subresource_api_url Warning strategy: - FutureWarning when privileged_client is omitted - DeprecationWarning on old property-based access
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughRefactored Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes 🚥 Pre-merge checks | ✅ 3 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
…nto vm_priv_property
|
Report bugs in Issues Welcome! 🎉This pull request will be automatically processed with the following features: 🔄 Automatic Actions
📋 Available CommandsPR Status Management
Review & Approval
Testing & Validation
Cherry-pick Operations
Label Management
✅ Merge RequirementsThis PR will be automatically approved when the following conditions are met:
📊 Review ProcessApprovers and ReviewersApprovers:
Reviewers:
Available Labels
💡 Tips
For more information, please refer to the project documentation or contact the maintainers. |
|
/verified |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@ocp_resources/virtual_machine_instance.py`:
- Around line 574-596: _get_pod_user_uid is annotated as returning int but can
be None when spec.securityContext.runAsUser is unset, causing _is_pod_root to
misidentify pods as root; change _get_pod_user_uid's type hint to Optional[int]
(or at least allow None) and update _is_pod_root to explicitly check for UID ==
0 (return True only when _get_pod_user_uid(pod) == 0) and otherwise return
False, so absent runAsUser is treated as non-root; refer to
VirtualMachineInstance._get_pod_user_uid, VirtualMachineInstance._is_pod_root,
and Pod.instance.spec.securityContext.runAsUser when making the change.
- Around line 333-363: The current calls to api_request in pause/unpause/reset
always pass the resolved _client, causing api_request to always take the
privileged path; change those calls to pass the original privileged_client
parameter (not _client) so api_request can choose the non-privileged code path
when privileged_client is omitted (i.e., use privileged_client=privileged_client
in the api_request call inside pause, unpause, and reset). Optionally add a
one-line method comment on pause/unpause/reset documenting this deprecation
transition if you want to clarify intent.
🧹 Nitpick comments (1)
ocp_resources/virtual_machine_instance.py (1)
476-484: Considerself.logger.exception()for the error-path diagnostics (Ruff TRY400).Lines 477-479 use
self.logger.error()inside anexceptblock. While the exception is re-raised, usingself.logger.exception()(at least for the first call) would automatically attach the traceback to the log output, aiding debugging.
- Pass original privileged_client (not resolved _client) to api_request in pause/unpause/reset - Handle unset runAsUser in _get_pod_user_uid (return int | None) and _is_pod_root (explicit uid == 0 check) - Use self.logger.exception() for error-path diagnostics in wait_until_running
…nto vm_priv_property
|
/verifierd |
|
/verified |
…nto vm_priv_property
…nto vm_priv_property
…nto vm_priv_property
|
/verified |
…nto vm_priv_property
|
/verified |
…nto vm_priv_property
|
/verified |
|
/lgtm |
Summary
Add explicit
privileged_clientparameter support acrossVirtualMachineInstancemethods to enable proper RBAC-aware client usage, replacing implicit reliance onself.clientfor privileged operations.New public methods (replacing deprecated properties)
get_virt_launcher_pod(privileged_client=...)— replacesvirt_launcher_podget_virt_handler_pod(privileged_client=...)— replacesvirt_handler_podget_node(privileged_client=...)— replacesnodeget_xml_dict(privileged_client=...)— replacesxml_dictModified methods with
privileged_clientparameterpause,unpause,resetget_xml,execute_virsh_commandget_dommemstat,get_domstatewait_until_runningapi_requestNew private helpers
_get_pod_user_uid— extract runAsUser UID from pod security context_is_pod_root— check if pod runs as root_get_hypervisor_connection_uri— build hypervisor socket URI_build_virsh_cmd— construct virsh command list_resolve_privileged_client— resolve client with FutureWarning fallback_get_subresource_api_url— build subresource API URL with optional clientDeprecation strategy
privileged_clientis omitted (falls back toself.client)virt_launcher_pod,virt_handler_pod,node,xml_dict, etc.)Consumer PR
Summary by CodeRabbit
New Features
Bug Fixes
Deprecations
get_*methods.