Skip to content

fix(kubernetes): make node group resources optional when instanceType is set - #3121

Merged
myasnikovdaniil merged 1 commit into
mainfrom
fix/kubernetes-nodegroup-resources-optional
Jun 30, 2026
Merged

fix(kubernetes): make node group resources optional when instanceType is set#3121
myasnikovdaniil merged 1 commit into
mainfrom
fix/kubernetes-nodegroup-resources-optional

Conversation

@lexfrei

@lexfrei Aleksei Sviridkin (lexfrei) commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

What this PR does

A tenant Kubernetes node group can be sized two ways: by instanceType or by an explicit resources block. The generated values schema, however, marked resources as required on every node group, so a node group sized purely by instanceType was rejected at install time:

at '/nodeGroups/<name>': missing property 'resources'

The same failure occurs through the typed Kubernetes CR: an empty resources: {} 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 by instanceType.

This marks resources optional in the node group definition and regenerates the dependent artifacts (values.schema.json, API types, README, and the ApplicationDefinition). No change is needed to emit the VM: the chart already renders domain.cpu/domain.memory only when resources is present and instancetype only when set, so a node group sized purely by instanceType now validates and installs. Node groups that specify resources are unaffected.

instanceType and resources are alternative, mutually exclusive sizing sources — KubeVirt rejects a VirtualMachine that references an instancetype and also sets explicit domain.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-empty instanceType and explicit resources.

Tests: helm-unittest coverage proves a node group with instanceType and no resources passes schema validation and renders without explicit domain.cpu/memory; a complementary case confirms explicit resources are still honoured; and a failedTemplate case 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

fix(kubernetes): allow a node group to omit `resources` when it is sized by `instanceType` (previously failed schema validation with "missing property 'resources'"); reject the unsupported combination of `instanceType` and explicit `resources` at render time

Summary by CodeRabbit

  • New Features
    • Worker node groups can optionally size CPU/memory via resources, and can omit resources when using instanceType.
  • Bug Fixes
    • Render now validates CPU/memory rules: instanceType with only one of resources.cpu/resources.memory fails, and instancetype is omitted when both resources.cpu and resources.memory are set (with instanceType ignored).
  • Documentation
    • Updated API/Helm docs and JSON schema to clarify resources vs instanceType precedence and the “set both CPU and memory (or neither)” requirement.
  • Tests
    • Added helm-unittest scenarios covering omission, precedence, and render-time failure cases.

@github-actions github-actions Bot added area/kubernetes Issues or PRs related to the tenant Kubernetes app kind/bug Categorizes issue or PR as related to a bug labels Jun 28, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 resources block was strictly required for Kubernetes node groups, preventing configurations that relied solely on instanceType for sizing. By marking resources as optional in the schema and API types, the change enables more flexible node group definitions. The fix ensures that explicit resource overrides remain functional while resolving the installation-time validation errors previously encountered.

Highlights

  • Schema Validation: Updated the Kubernetes node group schema to make the resources block optional, allowing node groups to be sized exclusively by instanceType.
  • Documentation: Updated README and values documentation to reflect that resources is now optional and that instanceType provides the default sizing when omitted.
  • Testing: Added helm-unittest coverage to verify that node groups without resources pass validation and that explicit resources are still correctly honored when provided.
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 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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 (@gemini-code-assist) Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .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 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

  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.

@github-actions github-actions Bot added the size/M This PR changes 30-99 lines, ignoring generated files label Jun 28, 2026
@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f1cb7bb1-3c02-42c7-b6f2-781f25d15f96

📥 Commits

Reviewing files that changed from the base of the PR and between 4e531b1 and a349c75.

📒 Files selected for processing (7)
  • api/apps/v1alpha1/kubernetes/types.go
  • packages/apps/kubernetes/README.md
  • packages/apps/kubernetes/templates/cluster.yaml
  • packages/apps/kubernetes/tests/cluster_test.yaml
  • packages/apps/kubernetes/values.schema.json
  • packages/apps/kubernetes/values.yaml
  • packages/system/kubernetes-rd/cozyrds/kubernetes.yaml
✅ Files skipped from review due to trivial changes (2)
  • packages/apps/kubernetes/values.yaml
  • packages/apps/kubernetes/README.md
🚧 Files skipped from review as they are similar to previous changes (5)
  • api/apps/v1alpha1/kubernetes/types.go
  • packages/apps/kubernetes/values.schema.json
  • packages/system/kubernetes-rd/cozyrds/kubernetes.yaml
  • packages/apps/kubernetes/templates/cluster.yaml
  • packages/apps/kubernetes/tests/cluster_test.yaml

📝 Walkthrough

Walkthrough

The NodeGroup sizing configuration now makes resources optional across schema, type, and docs, and the Helm template omits instancetype for fully specified resources while rejecting partial resource settings with instanceType. Tests cover omitted, provided, precedence, and conflicting configurations.

Changes

NodeGroup sizing rules

Layer / File(s) Summary
Schema and docs updates
api/apps/v1alpha1/kubernetes/types.go, packages/apps/kubernetes/values.schema.json, packages/apps/kubernetes/values.yaml, packages/apps/kubernetes/README.md, packages/system/kubernetes-rd/cozyrds/kubernetes.yaml
NodeGroup.resources is tagged omitempty, removed from required schema entries, and described as optional sizing that relates to instanceType; the CRD schema also drops the storageClass immutability rule.
Render-time validation and tests
packages/apps/kubernetes/templates/cluster.yaml, packages/apps/kubernetes/tests/cluster_test.yaml
The cluster template omits instancetype for resource-sized node groups, skips instancetype lookup in that case, fails when instanceType is paired with only one of cpu or memory, and helm-unittest cases cover omission, rendered CPU/memory, precedence, and rejection paths.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Suggested labels

kind/api-change

Suggested reviewers

  • kvaps
  • lllamnyp
  • myasnikovdaniil

Poem

🐇 Hop, hop, the nodes align,
resources sleeps; instanceType shines.
Some get sized, some get spared,
The bunny grins: the rules are cleared.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: node group resources are now optional when instanceType is used.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/kubernetes-nodegroup-resources-optional

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

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

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

Copy link
Copy Markdown
Contributor

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 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.

@lexfrei
Aleksei Sviridkin (lexfrei) force-pushed the fix/kubernetes-nodegroup-resources-optional branch from 42d7a8d to 6e4a330 Compare June 28, 2026 00:41

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 42d7a8d and 6e4a330.

📒 Files selected for processing (6)
  • api/apps/v1alpha1/kubernetes/types.go
  • packages/apps/kubernetes/README.md
  • packages/apps/kubernetes/tests/cluster_test.yaml
  • packages/apps/kubernetes/values.schema.json
  • packages/apps/kubernetes/values.yaml
  • packages/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

Comment thread packages/apps/kubernetes/values.yaml Outdated
## @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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 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.

@lexfrei
Aleksei Sviridkin (lexfrei) force-pushed the fix/kubernetes-nodegroup-resources-optional branch from 6e4a330 to 6b4c7eb Compare June 28, 2026 00:51
@github-actions github-actions Bot added size/L This PR changes 100-499 lines, ignoring generated files and removed size/M This PR changes 30-99 lines, ignoring generated files labels Jun 28, 2026

@myasnikovdaniil myasnikovdaniil left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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:

  • resources is removed from required in both values.schema.json and the regenerated kubernetes-rd openAPISchema; 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 the and — it only rejects instanceType together with a non-empty resources.cpu/memory. main already 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 instanceType with no explicit resources).

Non-blocking:

  • The CodeRabbit note on the resources description is worth taking: the default node group ships instanceType: "u1.medium", so a user who adds explicit resources to it will now hit the render-time failure. One sentence stating that instanceType must be cleared (instanceType: "") when sizing by explicit resources would close the gap.
  • Cosmetic: omitempty on the non-pointer Resources struct is a no-op in encoding/json; harmless, since the schema change is what fixes #3046.

@myasnikovdaniil

Copy link
Copy Markdown
Contributor

Thanks for tackling this — making resources optional (the #3046 path) is clearly right. One flag on the fail-fast on "both set", plus a small alternative that also closes the dashboard side.

The gap fail-fast leaves open

instanceType is required and defaulted to u1.medium in values.schema.json, so a node group effectively always carries an instanceType. The moment a user fills in resources.cpu/resources.memory while that default is present, the render now hard-fails:

nodeGroup md0: set either instanceType or explicit resources (cpu/memory), not both …

To use explicit resources they must also set instanceType: "". That's non-obvious from the CR, and impossible from the dashboard: the instanceType field is a required dropdown (x-cozystack-options: {source: instancetype}) with no empty option, so a console user who sets CPU/memory can't clear instanceType and is stuck. So fail-fast turns a silent KubeVirt rejection into a clear error, but the resources-sizing path stays unreachable for the common case.

Proposal: resolve by precedence instead of failing

When a node group is sized by explicit resources (both cpu and memory), omit the instancetype from the rendered VM. KubeVirt then accepts the explicit domain.cpu/domain.memory (no instancetype to conflict with), instanceType can stay required+defaulted (no schema change), and the dashboard works unchanged — sending u1.medium + explicit resources just sizes by resources (no UI change).

This keeps the #3046 case working (instanceType-only → instancetype rendered, no domain.cpu/memory), keeps the kubelet-reservation partial-override tests green (partial resources are untouched), and additionally fixes the separate "Save ignored when explicit resources are set" dashboard report. Verified locally with helm unittest (all green).

Suggested change on top of this PR (keeps your schema change), in templates/cluster.yaml:

       {{- 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: domain.cpu.cores=2, domain.memory.guest=4Gi, spec.instancetype absent).

I've got this implemented and helm unittest-green on a branch based on this PR's head if it's useful — happy to push it to your branch or fold it in here, whichever you prefer. (Heads up: the PR currently shows conflicts with main, so a rebase is needed regardless.)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 6b4c7eb and 4e531b1.

📒 Files selected for processing (7)
  • api/apps/v1alpha1/kubernetes/types.go
  • packages/apps/kubernetes/README.md
  • packages/apps/kubernetes/templates/cluster.yaml
  • packages/apps/kubernetes/tests/cluster_test.yaml
  • packages/apps/kubernetes/values.schema.json
  • packages/apps/kubernetes/values.yaml
  • packages/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

Comment on lines +312 to +338
- 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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 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.yaml

Repository: 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.

@myasnikovdaniil

Copy link
Copy Markdown
Contributor

Aleksei Sviridkin (@lexfrei) please correct wording of PR and release note and resolve conflicts

@myasnikovdaniil myasnikovdaniil left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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:

  • omitempty on non-pointer Resources Resources in types.go is a no-op in encoding/json. Harmless — the schema change is what fixes #3046, not the tag.
  • The "omit resources" unit test uses instanceType: "" to bypass the live-cluster lookup(), so the instancetype: block in the VM spec is not exercised by unit tests. Inherent helm-unittest limitation; per the PR description, E2E covers the instanceType-only rendering path.
  • The partial-resources fail guard fires only when instanceType is non-empty. A group with instanceType: "" 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>
@lexfrei
Aleksei Sviridkin (lexfrei) force-pushed the fix/kubernetes-nodegroup-resources-optional branch from 4e531b1 to a349c75 Compare June 30, 2026 10:54
@myasnikovdaniil myasnikovdaniil added backport Should change be backported on previous release backport-previous Backport target — previous release line labels Jun 30, 2026
@myasnikovdaniil
myasnikovdaniil merged commit 3e20a0c into main Jun 30, 2026
44 checks passed
@myasnikovdaniil
myasnikovdaniil deleted the fix/kubernetes-nodegroup-resources-optional branch June 30, 2026 12:46
@github-actions

Copy link
Copy Markdown

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

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

@github-actions

Copy link
Copy Markdown

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

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

myasnikovdaniil added a commit that referenced this pull request Jul 3, 2026
…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 -->
myasnikovdaniil added a commit that referenced this pull request Jul 3, 2026
…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
```
myasnikovdaniil added a commit that referenced this pull request Jul 3, 2026
…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
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/kubernetes Issues or PRs related to the tenant Kubernetes app backport Should change be backported on previous release backport-previous Backport target — previous release line kind/bug Categorizes issue or PR as related to a bug size/L This PR changes 100-499 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants