fix(kubernetes): make node group resources optional when instanceType is set - #3121
Conversation
Summary of ChangesHello, 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 addresses a validation issue where the Highlights
New Features🧠 You can now enable Memory (public preview) 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. 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 the 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 counterproductive. You can react with 👍 and 👎 on Gemini (@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. Footnotes
|
|
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:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
✅ Files skipped from review due to trivial changes (2)
🚧 Files skipped from review as they are similar to previous changes (5)
📝 WalkthroughWalkthroughThe NodeGroup sizing configuration now makes ChangesNodeGroup sizing rules
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
There was a problem hiding this comment.
Code Review
This pull request makes the "resources" field optional for Kubernetes worker node groups when an "instanceType" is specified. It updates the Go API types, values schema, Helm values, README documentation, and the cozyrds OpenAPI schema to reflect this change. Additionally, unit tests have been added to verify that node groups omitting resources render correctly without explicit CPU/Memory, while still honoring them when provided. There are no review comments, so I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
42d7a8d to
6e4a330
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/apps/kubernetes/values.yaml`:
- Line 88: Clarify the resources-only configuration by updating the `resources`
field description in the values schema to explicitly state that using explicit
`resources` requires setting `instanceType: ""`, since the current default
`u1.medium` still causes KubeVirt to reject the VM. Keep the guidance anchored
to the `resources` field definition and its relationship with `instanceType`, so
users understand they must clear `instanceType` when sizing by `resources`
alone.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 32551417-90af-4f4e-89ff-5cf53391e250
📒 Files selected for processing (6)
api/apps/v1alpha1/kubernetes/types.gopackages/apps/kubernetes/README.mdpackages/apps/kubernetes/tests/cluster_test.yamlpackages/apps/kubernetes/values.schema.jsonpackages/apps/kubernetes/values.yamlpackages/system/kubernetes-rd/cozyrds/kubernetes.yaml
✅ Files skipped from review due to trivial changes (1)
- packages/apps/kubernetes/README.md
🚧 Files skipped from review as they are similar to previous changes (4)
- packages/apps/kubernetes/values.schema.json
- api/apps/v1alpha1/kubernetes/types.go
- packages/system/kubernetes-rd/cozyrds/kubernetes.yaml
- packages/apps/kubernetes/tests/cluster_test.yaml
| ## @x-cozystack-options {source: storageclass} | ||
| ## @field {[]string} roles - List of node roles. | ||
| ## @field {Resources} resources - CPU and memory resources for each worker node. | ||
| ## @field {Resources} [resources] - Explicit CPU and memory for each worker node, as an alternative to `instanceType` sizing. Optional: when omitted, the node is sized by `instanceType`. Use one or the other — a non-empty `instanceType` combined with explicit `resources` renders a VM that KubeVirt rejects, because instanceType CPU/memory cannot be overridden. |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Clarify the valid resources-only shape.
This description says “use one or the other,” but the schema still requires instanceType and the defaults keep it as "u1.medium". Please state here that a node group using explicit resources must set instanceType: "", otherwise users will keep the default and hit the KubeVirt rejection this comment warns about.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/apps/kubernetes/values.yaml` at line 88, Clarify the resources-only
configuration by updating the `resources` field description in the values schema
to explicitly state that using explicit `resources` requires setting
`instanceType: ""`, since the current default `u1.medium` still causes KubeVirt
to reject the VM. Keep the guidance anchored to the `resources` field definition
and its relationship with `instanceType`, so users understand they must clear
`instanceType` when sizing by `resources` alone.
6e4a330 to
6b4c7eb
Compare
myasnikovdaniil
left a comment
There was a problem hiding this comment.
LGTM — relaxes a schema over-constraint and adds a render-time guard for the genuinely-invalid both-set case, with no regression for previously-valid configs.
Verified:
resourcesis removed fromrequiredin bothvalues.schema.jsonand the regeneratedkubernetes-rdopenAPISchema; the generated-code check is green.- The new render-time guard does not trip on the default
md0(instanceType: u1.medium+resources: {}), because an empty map is falsy in theand— it only rejectsinstanceTypetogether with a non-emptyresources.cpu/memory.mainalready renders that combination into a VM that KubeVirt's instancetype webhook rejects, so this is an earlier, clearer failure rather than new breakage. - E2E exercises exactly this path (a node group sized by
instanceTypewith no explicitresources).
Non-blocking:
- The CodeRabbit note on the
resourcesdescription is worth taking: the default node group shipsinstanceType: "u1.medium", so a user who adds explicitresourcesto it will now hit the render-time failure. One sentence stating thatinstanceTypemust be cleared (instanceType: "") when sizing by explicitresourceswould close the gap. - Cosmetic:
omitemptyon the non-pointerResourcesstruct is a no-op inencoding/json; harmless, since the schema change is what fixes #3046.
|
Thanks for tackling this — making The gap fail-fast leaves open
To use explicit resources they must also set Proposal: resolve by precedence instead of failingWhen a node group is sized by explicit resources (both cpu and memory), omit the instancetype from the rendered VM. KubeVirt then accepts the explicit This keeps the #3046 case working (instanceType-only → instancetype rendered, no Suggested change on top of this PR (keeps your schema change), in {{- range .group.roles }}
node-role.kubernetes.io/{{ . }}: ""
{{- end }}
spec:
- {{- with .group.instanceType }}
+ {{- /* Explicit resources take precedence over instanceType. When a node
+ group is sized by resources (both cpu and memory set), the
+ instancetype is omitted from the VM: KubeVirt rejects a
+ VirtualMachine that references an instancetype and also overrides
+ both domain.cpu and domain.memory. */}}
+ {{- $sizedByResources := and .group.resources .group.resources.cpu .group.resources.memory }}
+ {{- if and .group.instanceType (not $sizedByResources) }}
instancetype:
kind: VirtualMachineClusterInstancetype
- name: {{ . }}
+ name: {{ .group.instanceType }}
{{- end }}and replace the fail-fast guard with the per-group resource flags (the lookup is also skipped when resources are the sizing source, so a stale instancetype can't fail an otherwise valid group): {{- range $groupName, $group := .Values.nodeGroups }}
-{{- if and $group.instanceType $group.resources (or $group.resources.cpu $group.resources.memory) }}
-{{- fail (printf "nodeGroup %s: set either instanceType or explicit resources (cpu/memory), not both — KubeVirt rejects a VM that overrides instanceType CPU/memory" $groupName) }}
-{{- end }}
+{{- $hasCpu := and $group.resources $group.resources.cpu }}
+{{- $hasMem := and $group.resources $group.resources.memory }}
{{- $instanceType := dict }}
-{{- if $group.instanceType }}
+{{- if and $group.instanceType (not (and $hasCpu $hasMem)) }}
{{- $instanceType = (lookup "instancetype.kubevirt.io/v1beta1" "VirtualMachineClusterInstancetype" "" $group.instanceType) }}
{{- if not $instanceType }}
{{- fail (printf "nodeGroup %s: specified instanceType %q not found in cluster" $groupName $group.instanceType) }}
{{- end }}
{{- end }}The existing "fails when both set" unittest then flips to assert the VM is sized by resources with no instancetype (documentIndex 4: I've got this implemented and |
4e531b1
6b4c7eb to
4e531b1
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/apps/kubernetes/tests/cluster_test.yaml`:
- Around line 312-338: The current cluster test only covers the “resources
omitted” case because it sets instanceType to an empty string, so it does not
exercise the real instanceType-only rendering path. Update the Kubernetes Helm
test in cluster_test.yaml by adding a case with a non-empty
nodeGroups.worker.instanceType and no resources, or reuse an existing test that
already hits the lookup()/instancetype branch. Keep the existing assertions for
KubevirtMachineTemplate and the absence of
spec.template.spec.virtualMachineTemplate.spec.template.spec.domain.cpu and
.memory, but ensure the new scenario actually validates instanceType-driven
rendering.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 87983d7d-8873-4104-9773-964801d520c5
📒 Files selected for processing (7)
api/apps/v1alpha1/kubernetes/types.gopackages/apps/kubernetes/README.mdpackages/apps/kubernetes/templates/cluster.yamlpackages/apps/kubernetes/tests/cluster_test.yamlpackages/apps/kubernetes/values.schema.jsonpackages/apps/kubernetes/values.yamlpackages/system/kubernetes-rd/cozyrds/kubernetes.yaml
✅ Files skipped from review due to trivial changes (1)
- packages/apps/kubernetes/values.yaml
🚧 Files skipped from review as they are similar to previous changes (4)
- api/apps/v1alpha1/kubernetes/types.go
- packages/apps/kubernetes/values.schema.json
- packages/system/kubernetes-rd/cozyrds/kubernetes.yaml
- packages/apps/kubernetes/README.md
| - it: accepts a node group that omits resources and renders no explicit cpu/memory | ||
| release: | ||
| name: test-k8s | ||
| namespace: tenant-test | ||
| set: | ||
| nodeGroups: | ||
| worker: | ||
| minReplicas: 1 | ||
| maxReplicas: 3 | ||
| instanceType: "" | ||
| diskSize: "20Gi" | ||
| roles: | ||
| - worker | ||
| asserts: | ||
| - isKind: | ||
| of: KubevirtMachineTemplate | ||
| documentIndex: 8 | ||
| - equal: | ||
| path: spec.template.spec.virtualMachineTemplate.spec.template.metadata.labels["cluster.x-k8s.io/deployment-name"] | ||
| value: test-k8s-worker | ||
| documentIndex: 8 | ||
| - notExists: | ||
| path: spec.template.spec.virtualMachineTemplate.spec.template.spec.domain.cpu | ||
| documentIndex: 8 | ||
| - notExists: | ||
| path: spec.template.spec.virtualMachineTemplate.spec.template.spec.domain.memory | ||
| documentIndex: 8 |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Look for any existing tests or fixtures that cover a non-empty instanceType
# without explicit nodeGroup resources.
fd -e yaml -e yml -e go -e sh . packages/apps/kubernetes packages/system \
| xargs rg -n -C2 'VirtualMachineClusterInstancetype|lookup "instancetype\.kubevirt\.io|instanceType:\s*"[^"]+"'Repository: cozystack/cozystack
Length of output: 46251
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Inspect the relevant test blocks around the suspected coverage.
sed -n '290,390p' packages/apps/kubernetes/tests/cluster_test.yaml
echo '---'
sed -n '390,445p' packages/apps/kubernetes/tests/cluster_test.yaml
echo '---'
# Show the cluster template branches around the referenced lines.
sed -n '70,90p' packages/apps/kubernetes/templates/cluster.yaml
echo '---'
sed -n '428,440p' packages/apps/kubernetes/templates/cluster.yamlRepository: cozystack/cozystack
Length of output: 7737
Add coverage for the real instanceType-only path
This case still sets instanceType: "", so it only proves resources may be omitted. Add a test that omits resources with a non-empty instanceType, or point to an existing test that exercises the lookup()/instancetype branch.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/apps/kubernetes/tests/cluster_test.yaml` around lines 312 - 338, The
current cluster test only covers the “resources omitted” case because it sets
instanceType to an empty string, so it does not exercise the real
instanceType-only rendering path. Update the Kubernetes Helm test in
cluster_test.yaml by adding a case with a non-empty
nodeGroups.worker.instanceType and no resources, or reuse an existing test that
already hits the lookup()/instancetype branch. Keep the existing assertions for
KubevirtMachineTemplate and the absence of
spec.template.spec.virtualMachineTemplate.spec.template.spec.domain.cpu and
.memory, but ensure the new scenario actually validates instanceType-driven
rendering.
|
Aleksei Sviridkin (@lexfrei) please correct wording of PR and release note and resolve conflicts |
myasnikovdaniil
left a comment
There was a problem hiding this comment.
LGTM — the key change since the dismissed review is the behavior flip on the both-set case: instead of failing hard when instanceType and explicit resources are both set, resources now silently win and the instancetype is omitted from the VM. This is the right call — the dashboard's required instanceType dropdown cannot be emptied, so the hard-fail path was unreachable from the UI.
Prior concerns from the dismissed review are addressed:
- The "add a note about clearing instanceType" suggestion is moot; users no longer need to clear it when sizing by resources.
- The render-time guard that was unreachable from the dashboard is replaced by silent resource precedence with a partial-resource fail guard (only-cpu or only-memory alongside a non-empty instanceType still fails fast).
Non-blocking observations:
omitemptyon non-pointerResources Resourcesintypes.gois a no-op inencoding/json. Harmless — the schema change is what fixes #3046, not the tag.- The "omit resources" unit test uses
instanceType: ""to bypass the live-clusterlookup(), so theinstancetype:block in the VM spec is not exercised by unit tests. Inherenthelm-unittestlimitation; per the PR description, E2E covers the instanceType-only rendering path. - The partial-resources fail guard fires only when
instanceTypeis non-empty. A group withinstanceType: ""and only one of cpu/memory set won't fail at render time and will emit an incomplete VM domain spec. Pre-existing behavior, not introduced here.
…ver instanceType A node group is sized either by instanceType or by explicit resources, but the generated values schema required resources on every node group. A node group with instanceType and no resources — or an empty resources dropped during typed-CR to HelmRelease translation — failed schema validation with "missing property 'resources'" even though sizing was fully specified. Mark resources optional in the node group definition and regenerate the schema, API types, README, and ApplicationDefinition. The chart template emits domain.cpu/memory only when resources is present, so a node group sized purely by instanceType now passes validation and installs. When a node group sets both instanceType and explicit resources, explicit resources take precedence: the instancetype is omitted from the rendered VM and the per-group instancetype lookup is skipped, so KubeVirt accepts the explicit domain.cpu/memory with no instancetype to conflict with. instanceType stays required and defaulted (no schema change), so the console's required instanceType dropdown keeps working — sending the default instanceType plus explicit resources simply sizes the VM by resources. This replaces an earlier render-time hard failure on the both-set case, which was unreachable to clear from the dashboard (the required dropdown cannot be emptied). Explicit resources are all-or-nothing alongside an instanceType: a partial spec (only cpu, or only memory) on a group that carries a non-empty instanceType would emit one domain override next to the instancetype — which KubeVirt rejects — so it now fails at render time with a clear error. Partial resources on a group without an instanceType (used to tune kubelet reservations) are unaffected. Assisted-By: Claude <noreply@anthropic.com> Signed-off-by: Aleksei Sviridkin <f@lex.la>
a349c75
4e531b1 to
a349c75
Compare
|
Backport failed for Please cherry-pick the changes locally and resolve any conflicts. git fetch origin release-1.5
git worktree add -d .worktree/backport-3121-to-release-1.5 origin/release-1.5
cd .worktree/backport-3121-to-release-1.5
git switch --create backport-3121-to-release-1.5
git cherry-pick -x a349c753ad16a68e309177562b18f54cf86ce4f9 |
|
Backport failed for Please cherry-pick the changes locally and resolve any conflicts. git fetch origin release-1.4
git worktree add -d .worktree/backport-3121-to-release-1.4 origin/release-1.4
cd .worktree/backport-3121-to-release-1.4
git switch --create backport-3121-to-release-1.4
git cherry-pick -x a349c753ad16a68e309177562b18f54cf86ce4f9 |
…3155) ## What this PR does The Automatic Backport workflow passed `conflict_resolution: draft_commit_conflicts` as a **top-level** input to `korthout/backport-action`, but the action only reads `conflict_resolution` from inside its `experimental` JSON input. Passed top-level it was silently ignored — the action run logs warn `Unexpected input(s) 'conflict_resolution'` — so it fell back to the `experimental` default of `fail`. On a cherry-pick conflict the action then created **no** pull request and only left a "Backport failed" comment on the source PR (this bit #3121 and #3119). This moves the key into the `experimental` input, so a conflicting backport instead opens a **draft PR with the first conflict committed** for maintainers to resolve in place. No version bump: the pinned `v3.2.1` already supports `draft_commit_conflicts` — the bug was purely the input placement. ### Release note ```release-note NONE ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Backport pull requests now handle conflicts more reliably and open as draft PRs when conflicts are detected. * Improved configuration handling so the expected conflict behavior is applied consistently during backport automation. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
…ional when instanceType is set (#3156) ## What this PR does Backport of #3121 to `release-1.5`. Makes node group `resources` optional, so a node group sized purely by `instanceType` (with `resources` omitted) passes `values.schema.json` validation and installs. When a group sets both `instanceType` and explicit `resources` (both `cpu` and `memory`), the explicit resources take precedence: the instancetype is omitted from the rendered VM and the per-group instancetype lookup is skipped, so KubeVirt does not reject a VM that references an instancetype while overriding `domain.cpu`/`memory`. A partial spec (only one of `cpu`/`memory`) alongside an `instanceType` fails fast at render time. Cherry-picked from `a349c753`; conflicts resolved against the `release-1.5` tree (the management-cluster Talos worker bootstrap stack present on `main` is not on this branch, so the schema/template/test layout differ). Generated files (`values.schema.json`, `README.md`, cozyrds, API types) regenerated with `make generate` to match. `helm unittest` passes (134 tests), including the four new node-group sizing cases adapted to this branch's document layout. ### Release note ```release-note fix(kubernetes): make node group resources optional when instanceType is set ```
…ional when instanceType is set (#3157) ## What this PR does Backport of #3121 to `release-1.4`. Makes node group `resources` optional, so a node group sized purely by `instanceType` (with `resources` omitted) passes `values.schema.json` validation and installs. When a group sets both `instanceType` and explicit `resources` (both `cpu` and `memory`), the explicit resources take precedence: the instancetype is omitted from the rendered VM and the per-group instancetype lookup is skipped, so KubeVirt does not reject a VM that references an instancetype while overriding `domain.cpu`/`memory`. A partial spec (only one of `cpu`/`memory`) alongside an `instanceType` fails fast at render time. Cherry-picked from `a349c753`; conflicts resolved against the `release-1.4` tree (the management-cluster Talos worker bootstrap stack present on `main` is not on this branch, so the schema/template/test layout differ). Generated files (`values.schema.json`, `README.md`, cozyrds, API types) regenerated with `make generate` to match. `helm unittest` passes (130 tests), including the four new node-group sizing cases adapted to this branch's document layout. ### Release note ```release-note fix(kubernetes): make node group resources optional when instanceType is set ```
What this PR does
A tenant Kubernetes node group can be sized two ways: by
instanceTypeor by an explicitresourcesblock. The generated values schema, however, markedresourcesas required on every node group, so a node group sized purely byinstanceTypewas rejected at install time:The same failure occurs through the typed
KubernetesCR: an emptyresources: {}is dropped during the CR-to-HelmRelease translation, so by validation time the key is absent and the required check fails — even though sizing was already fully specified byinstanceType.This marks
resourcesoptional in the node group definition and regenerates the dependent artifacts (values.schema.json, API types, README, and theApplicationDefinition). No change is needed to emit the VM: the chart already rendersdomain.cpu/domain.memoryonly whenresourcesis present andinstancetypeonly when set, so a node group sized purely byinstanceTypenow validates and installs. Node groups that specifyresourcesare unaffected.instanceTypeandresourcesare alternative, mutually exclusive sizing sources — KubeVirt rejects a VirtualMachine that references an instancetype and also sets explicitdomain.cpu/domain.memory, since instancetype CPU/memory cannot be overridden. To avoid emitting a VM that the instancetype admission webhook would later reject, the chart now fails fast at render time with a clear message when a node group sets both a non-emptyinstanceTypeand explicitresources.Tests: helm-unittest coverage proves a node group with
instanceTypeand noresourcespasses schema validation and renders without explicitdomain.cpu/memory; a complementary case confirms explicitresourcesare still honoured; and afailedTemplatecase pins the render-time rejection of the conflicting both-set combination. The omit-resources case fails against the pre-fix schema with the exact error above, so it is a real regression guard.Addresses #3046.
Screenshots
N/A — schema and chart change, no UI impact.
Release note
Summary by CodeRabbit
resources, and can omitresourceswhen usinginstanceType.instanceTypewith only one ofresources.cpu/resources.memoryfails, andinstancetypeis omitted when bothresources.cpuandresources.memoryare set (withinstanceTypeignored).resourcesvsinstanceTypeprecedence and the “set both CPU and memory (or neither)” requirement.