Skip to content

Conversation

kvaps
Copy link
Member

@kvaps kvaps commented Sep 1, 2025

Signed-off-by: Andrei Kvapil kvapss@gmail.com

What this PR does

Fix regression introduced by #1169, now we have correct singular names for virtualmachines which are conflictiing with KubeVirt ones.

Solution: explicitly specify apiversion

Release note

[virtual-machine] Fix vm update hook

Summary by CodeRabbit

  • Bug Fixes

    • Improved reliability of VM update hooks by targeting the correct API resource, preventing occasional patch failures when updating instancetype and preference.
    • Ensures VM updates apply consistently across environments without changing existing behavior.
  • Chores

    • Aligned resource references with fully qualified API names to enhance compatibility with current cluster configurations.

Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
Copy link
Contributor

coderabbitai bot commented Sep 1, 2025

Walkthrough

Updated kubectl patch targets in two vm-update-hook.yaml templates to use the fully qualified KubeVirt resource name virtualmachines.kubevirt.io for instancetype and preference patches. Patch payloads, conditions, PVC resize logic, and overall hook structure remain unchanged.

Changes

Cohort / File(s) Summary
Hook patch target updates
packages/apps/virtual-machine/templates/vm-update-hook.yaml, packages/apps/vm-instance/templates/vm-update-hook.yaml
Switch kubectl patch resource from virtualmachine to virtualmachines.kubevirt.io for instancetype and preference patches; no changes to payloads, conditions, or other logic.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I hop through hooks with nimble cheer,
From short names to FQDNs clear.
A gentle nudge, no grand parade—
Just tidy patches, neatly laid.
My whiskers twitch; the build feels right,
Carrots committed, green as night. 🥕✨

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-vm

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

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

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit 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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @kvaps, 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 an issue in the VirtualMachine update hooks by correcting the kubectl patch commands. The change ensures that when a VirtualMachine's instancetype or preference needs to be updated, the patch operation correctly targets the Kubernetes API resource, leading to reliable application of these configuration changes.

Highlights

  • Kubectl Patch Command Fix: The kubectl patch commands within the vm-update-hook.yaml templates have been updated to correctly reference VirtualMachine resources using their fully qualified name, virtualmachines.kubevirt.io, instead of the shorthand virtualmachine.
  • VirtualMachine Instancetype and Preference Updates: This fix ensures that updates to a VirtualMachine's instancetype and preference are applied successfully by addressing an issue where the kubectl patch command might not have correctly identified the resource.
Using Gemini Code Assist

The 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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly fixes the VM update hook by using the fully qualified resource name virtualmachines.kubevirt.io instead of a short name. This improves the robustness of the hook. I've identified a separate potential issue where template variables in the patch payload are not safely escaped, which could cause the hook to fail with certain input values. My review includes suggestions to use the toJson function to address this.

Comment on lines +67 to 69
kubectl patch virtualmachines.kubevirt.io {{ $vmName }} -n {{ $namespace }} \
--type merge \
-p '{"spec":{"instancetype":{"name": "{{ $instanceType }}", "revisionName": null}}}'

Choose a reason for hiding this comment

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

high

While using the fully qualified resource name is a good fix, the patch payload itself is not robust. The $instanceType variable is directly injected into the JSON string. If it contains characters that need JSON escaping (e.g., a double quote), this will produce invalid JSON and cause the patch to fail. To prevent this, you should use Helm's toJson function, which will correctly format the value as a JSON string.

              kubectl patch virtualmachines.kubevirt.io {{ $vmName }} -n {{ $namespace }} \
                --type merge \
                -p '{"spec":{"instancetype":{"name": {{ $instanceType | toJson }}, "revisionName": null}}}'

Comment on lines +74 to 76
kubectl patch virtualmachines.kubevirt.io {{ $vmName }} -n {{ $namespace }} \
--type merge \
-p '{"spec":{"preference":{"name": "{{ $instanceProfile }}", "revisionName": null}}}'

Choose a reason for hiding this comment

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

high

Similar to the instancetype patch, the $instanceProfile variable is directly injected into the JSON string. This can lead to invalid JSON if the value contains special characters. Please use the toJson function to ensure the value is correctly JSON-encoded.

              kubectl patch virtualmachines.kubevirt.io {{ $vmName }} -n {{ $namespace }} \
                --type merge \
                -p '{"spec":{"preference":{"name": {{ $instanceProfile | toJson }}, "revisionName": null}}}'

Comment on lines +57 to 59
kubectl patch virtualmachines.kubevirt.io {{ $vmName }} -n {{ $namespace }} \
--type merge \
-p '{"spec":{"instancetype":{"name": "{{ $instanceType }}", "revisionName": null}}}'

Choose a reason for hiding this comment

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

high

While using the fully qualified resource name is a good fix, the patch payload itself is not robust. The $instanceType variable is directly injected into the JSON string. If it contains characters that need JSON escaping (e.g., a double quote), this will produce invalid JSON and cause the patch to fail. To prevent this, you should use Helm's toJson function, which will correctly format the value as a JSON string.

              kubectl patch virtualmachines.kubevirt.io {{ $vmName }} -n {{ $namespace }} \
                --type merge \
                -p '{"spec":{"instancetype":{"name": {{ $instanceType | toJson }}, "revisionName": null}}}'

Comment on lines +64 to 66
kubectl patch virtualmachines.kubevirt.io {{ $vmName }} -n {{ $namespace }} \
--type merge \
-p '{"spec":{"preference":{"name": "{{ $instanceProfile }}", "revisionName": null}}}'

Choose a reason for hiding this comment

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

high

Similar to the instancetype patch, the $instanceProfile variable is directly injected into the JSON string. This can lead to invalid JSON if the value contains special characters. Please use the toJson function to ensure the value is correctly JSON-encoded.

              kubectl patch virtualmachines.kubevirt.io {{ $vmName }} -n {{ $namespace }} \
                --type merge \
                -p '{"spec":{"preference":{"name": {{ $instanceProfile | toJson }}, "revisionName": null}}}'

Copy link
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: 0

🧹 Nitpick comments (2)
packages/apps/vm-instance/templates/vm-update-hook.yaml (1)

61-61: Remove trailing whitespace (yamllint).

Line 61 contains trailing spaces flagged by YAMLlint. Strip them to satisfy linters.

-              
+
packages/apps/virtual-machine/templates/vm-update-hook.yaml (1)

71-71: Remove trailing whitespace (yamllint).

Line 71 has trailing spaces; clean up to appease YAMLlint.

-              
+
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 8ca8817 and 15b213b.

📒 Files selected for processing (2)
  • packages/apps/virtual-machine/templates/vm-update-hook.yaml (1 hunks)
  • packages/apps/vm-instance/templates/vm-update-hook.yaml (1 hunks)
🧰 Additional context used
🪛 YAMLlint (1.37.1)
packages/apps/virtual-machine/templates/vm-update-hook.yaml

[error] 71-71: trailing spaces

(trailing-spaces)

packages/apps/vm-instance/templates/vm-update-hook.yaml

[error] 61-61: trailing spaces

(trailing-spaces)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build
🔇 Additional comments (4)
packages/apps/vm-instance/templates/vm-update-hook.yaml (2)

57-60: Good fix: use fully-qualified KubeVirt resource.

Switching to virtualmachines.kubevirt.io avoids ambiguity and aligns with RBAC rules (resources: virtualmachines). Looks correct.


64-67: Good fix mirrored for preference patch.

Consistent with the instancetype change; targeting virtualmachines.kubevirt.io is correct.

packages/apps/virtual-machine/templates/vm-update-hook.yaml (2)

67-70: Good fix: patch against virtualmachines.kubevirt.io.

Fully-qualified resource is correct for KubeVirt CRDs and matches Role rules.


74-77: Consistent target for preference patch.

Using virtualmachines.kubevirt.io here as well is correct and consistent.

@kvaps kvaps changed the title Fix vm update hook [virtual-machine] Fix vm update hook Sep 1, 2025
@kvaps kvaps added the backport Should change be backported on previus release label Sep 1, 2025
@kvaps kvaps merged commit ce5fd9d into main Sep 1, 2025
20 checks passed
@kvaps kvaps deleted the fix-vm branch September 1, 2025 17:46
Copy link

github-actions bot commented Sep 1, 2025

Successfully created backport PR for release-0.35:

kvaps added a commit that referenced this pull request Sep 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport Should change be backported on previus release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant