Skip to content

cks node groups - #14594

Open
argrinberg wants to merge 4 commits into
apache:mainfrom
Telecom-Cloud-UzCloud:cks-node-groups
Open

argrinberg wants to merge 4 commits into
apache:mainfrom
Telecom-Cloud-UzCloud:cks-node-groups

Conversation

@argrinberg

@argrinberg argrinberg commented Nov 6, 2026 •

Copy link
Copy Markdown

Description

Adds node groups (node pools) to CloudManaged CKS clusters. Every cluster gets a default node group holding the worker nodes of the cluster size; additional node groups have their own service offering, template, Kubernetes labels and taints, and autoscaling settings. Nodes can also have their own labels and taints on top of the ones of their node group.

  • New APIs: createKubernetesClusterNodeGroup, listKubernetesClusterNodeGroups, updateKubernetesClusterNodeGroup, scaleKubernetesClusterNodeGroup, deleteKubernetesClusterNodeGroup, updateKubernetesClusterNode
  • Existing clusters get their default node group on management server startup; scaleKubernetesCluster keeps working and applies to the default node group
  • Operations on different node groups of a cluster can run concurrently; failures only affect the node group
  • The cluster autoscaler is deployed with one --nodes argument per autoscaled node group. Node groups other than the default one need an autoscaler image supporting node groups, set by the new cloud.kubernetes.cluster.autoscaler.image global setting (the upstream image only supports the default node group)
  • UI: Node groups tab with expandable nodes, forms for node groups and node labels/taints; the cluster list shows the total number of worker nodes

Types of changes

  • Breaking change (fix or feature that would cause existing functionality to change)
  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (improves an existing feature and functionality)
  • Cleanup (Code refactoring and cleanup, that may add test cases)

Screenshots (if appropriate):

How Has This Been Tested?

  • Unit tests: all 174 tests of the kubernetes-service plugin pass
  • Manual testing on a single host KVM zone (Ubuntu 24.04, Kubernetes 1.33): cluster creation, default node group creation for an existing cluster, creating, scaling (including concurrent scaling of several node groups), updating and deleting node groups, node labels and taints applied to the Kubernetes nodes, autoscaling of the default node group

Documentation PR: apache/cloudstack-documentation#699

Node groups are pools of worker nodes of a CloudManaged Kubernetes
cluster with their own service offering, template, Kubernetes labels,
taints and autoscaling settings. Every cluster has a default node group
holding the worker nodes of the cluster size. The nodes of the node
groups are linked to them in the cluster VM map, along with their own
labels and taints.
- New APIs to create, list, update, scale and delete the node groups of
  a cluster, and to update the labels and taints of a node.
- Node group nodes are registered with the node group label, labels and
  taints through the kubelet; label and taint changes are applied to the
  existing nodes, merging the ones of the node group with the ones of
  each node.
- The default node group is created with the cluster, and on startup for
  the existing clusters. It can not be deleted, keeps at least one node
  and only allows PreferNoSchedule taints so that the system pods can
  run. The cluster scale API applies to it and keeps it in sync.
- Operations on different node groups of a cluster can run at the same
  time: the cluster stays Scaling while they are in progress, network
  rules and counters are updated under locks, failed scale ups only
  clean up their own nodes and failures move the node group to Error.
- The cluster autoscaler is deployed with one --nodes argument per node
  group with autoscaling enabled. Node groups other than the default one
  require an autoscaler image supporting node groups, set by
  cloud.kubernetes.cluster.autoscaler.image.
- The cluster response has the total number of worker nodes and the node
  groups of the cluster.
Adds a node groups tab to Kubernetes clusters to create, scale, update
and delete node groups with their labels, taints and autoscaling
settings, and to list the nodes of each node group and edit their own
labels and taints. The cluster list shows the total number of worker
nodes and the cluster scale dialog is labelled for the default node
group.
@boring-cyborg

boring-cyborg Bot commented Nov 6, 2026

Copy link
Copy Markdown

Congratulations on your first Pull Request and welcome to the Apache CloudStack community! If you have any issues or are unsure about any anything please check our Contribution Guide (https://github.com/apache/cloudstack/blob/main/CONTRIBUTING.md)
Here are some useful points:

@codecov

codecov Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 16.17807% with 1544 lines in your changes missing coverage. Please review.
✅ Project coverage is 20.75%. Comparing base (fb60564) to head (840e693).
⚠️ Report is 9 commits behind head on main.

Files with missing lines Patch % Lines
...bernetes/cluster/KubernetesClusterManagerImpl.java 7.99% 597 Missing and 13 partials ⚠️
...ctionworkers/KubernetesClusterNodeGroupWorker.java 9.12% 217 Missing and 2 partials ⚠️
...i/response/KubernetesClusterNodeGroupResponse.java 0.00% 103 Missing ⚠️
...KubernetesClusterResourceModifierActionWorker.java 9.30% 77 Missing and 1 partial ⚠️
...bernetes/cluster/KubernetesClusterNodeGroupVO.java 28.70% 76 Missing and 1 partial ⚠️
...nodegroup/CreateKubernetesClusterNodeGroupCmd.java 0.00% 57 Missing ⚠️
...nodegroup/UpdateKubernetesClusterNodeGroupCmd.java 0.00% 52 Missing ⚠️
...ck/api/response/KubernetesClusterNodeResponse.java 0.00% 43 Missing ⚠️
...etes/nodegroup/UpdateKubernetesClusterNodeCmd.java 0.00% 41 Missing ⚠️
...cluster/dao/KubernetesClusterNodeGroupDaoImpl.java 0.00% 40 Missing ⚠️
... and 14 more
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #14594      +/-   ##
============================================
- Coverage     20.78%   20.75%   -0.04%     
- Complexity    21931    22010      +79     
============================================
  Files          6496     6513      +17     
  Lines        591657   593781    +2124     
  Branches      72592    72909     +317     
============================================
+ Hits         122966   123227     +261     
- Misses       455346   457175    +1829     
- Partials      13345    13379      +34     
Flag Coverage Δ
uitests 3.85% <ø> (-0.03%) ⬇️
unittests 22.06% <16.17%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown

This pull request has merge conflicts. Dear author, please fix the conflicts and sync your branch with the base branch.

@nvazquez

Copy link
Copy Markdown
Contributor

Hi @argrinberg can you please address the conflicts?

@bhouse-nexthop bhouse-nexthop left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for this, @argrinberg. Node groups are something we want to use, so we'd like to help get this merged. I read the whole diff and checked it against how CKS behaves today. Line numbers are at 840e693.

Overall: the design fits CKS well. Each group has its own state, the cluster sits in Scaling while group operations run, the counters are updated under a row lock, cleanup on failure only touches the group's own nodes, and the default group keeps scaleKubernetesCluster working. Label and taint input is validated carefully (kubernetes.io/k8s.io keys are refused, and the regexes keep the kubelet arguments and kubectl commands safe). The schema change is in the right file for 24.0, and IDEMPOTENT_* is used.

I rebased the branch onto current main locally. The only conflicts are append-only, in schema-42300to2400.sql and PendingReleaseNotes. The kubernetes-service module builds and all 174 of its tests pass.

Before this can merge, I think the autoscaler interaction (1) and the startup backfill (2) need changes. The rest are smaller.

Paths below are relative to plugins/integrations/kubernetes-service/src/main/.

Findings

1. The upstream autoscaler mistakes node-group VMs for default-group nodes (major)

resources/script/autoscale-kube-cluster, java/.../actionworkers/KubernetesClusterResourceModifierActionWorker.java:1005, java/.../KubernetesClusterManagerImpl.java:1500

The upstream CloudStack provider in kubernetes/autoscaler reads only the first --nodes value (createClusterConfig uses opts.NodeGroups[0]). It then treats every VM in the cluster's virtualmachines as a member of that one group (asg.Nodes(), Belongs()). After this PR, virtualmachines also lists the nodes of the other groups.

Scenario: the default group has autoscaling on, using the stock image, and a non-autoscaled group db exists. The autoscaler sees the db nodes as part of the default group. When one of them is underused, it calls scaleKubernetesCluster nodeids=<db node>. Line 1500 rejects that call ("Some of the nodes belong to a node group"), so scale-down fails on every loop. Its view of the group size (size against the VM count) is also wrong.

There are two related points:

  • Autoscaling a non-default group needs a node-group-aware image (cloud.kubernetes.cluster.autoscaler.image), and there is no such image or kubernetes/autoscaler change yet.
  • For project clusters, the autoscaler uses the Kubernetes service user. That user's role (PROJECT_KUBERNETES_ACCOUNT_ROLE_ALLOWED_APIS, KubernetesClusterManagerImpl.java:282) allows only listKubernetesClusters and scaleKubernetesCluster. A node-group-aware image would also need listKubernetesClusterNodeGroups and scaleKubernetesClusterNodeGroup, and roles created before the upgrade would need them added too.

Suggestion: with the stock image, refuse to enable default-group autoscaling while other node groups exist, with an error that says why. Alternatively, link the kubernetes/autoscaler change this depends on. In either case, add the node-group APIs to the service-user role and to existing roles.

2. The default-group backfill runs on every management server without a lock (major)

java/.../KubernetesClusterManagerImpl.java:2902

createMissingDefaultNodeGroups() runs in start() on every management server. Nothing in the schema prevents a second default group for a cluster.

Scenario: two management servers start together after the upgrade, which is common when both are restarted on the new version. Both find no default group for cluster C, and both insert one. The second one is named default-pool (line 2885) and has 0 nodes, because the first already took the VMs. findDefaultByClusterId() uses findOneBy, which returns either row, so scaling, autoscaling and the response for C then depend on which row comes back.

Suggestion: create the default groups and set kubernetes_cluster_vm_map.node_group_id in schema-42300to2400.sql with INSERT ... SELECT and UPDATE. That runs once, under the upgrade lock. Keep only the node labelling at runtime. If it has to stay in Java, wrap it in a GlobalLock.

3. Label and taint updates are saved before they are applied, and not rolled back (medium)

java/.../KubernetesClusterManagerImpl.java:3483 and :3662

The new labels and taints are written to the database first, then applied over SSH. If kubectl fails on one node, the group goes to Error and the database already holds the new values.

Scenario: the group labels change from {a=1} to {b=2}, and kubectl fails on node 2. The retry computes its removals from the stored values, so oldLabels and newLabels are both b=2 and no a- is generated. Node 2 keeps a=1, and nothing in CloudStack shows it. Taints and per-node labels have the same problem.

Suggestion: restore the old values when the apply fails, as the autoscaling path already does at line 3490. Alternatively, compute the removals from the node's current labels.

4. External nodes register with the default group's label, labels and taints (minor)

java/.../actionworkers/KubernetesClusterActionWorker.java:1100, java/.../actionworkers/KubernetesClusterAddWorker.java:193

importNodeToCluster() renders k8s-node.yml through getKubernetesNodeConfig(), which always fills in the default group's kubelet arguments. An external node therefore joins with cloudstack.apache.org/nodegroup=default and the default group's labels and taints. Its vm_map row still has node_group_id NULL (line 460).

Pods that select nodegroup=default can then land on nodes that the default group's size, list and update calls never include.

Suggestion: leave the kubelet arguments empty for external nodes, for example by overriding getWorkerNodeKubeletExtraArgs() in the add worker.

5. A failed offering change leaves the group and cluster counters stale (minor)

java/.../actionworkers/KubernetesClusterNodeGroupWorker.java:286

scaleNodeGroupOffering() upgrades the VMs one at a time and calls syncNodeGroupEntry(serviceOffering) only after all of them succeed.

Scenario: a 5-node group moves from 2 to 4 vCPU and VM 3 fails. VMs 1 and 2 are on the new offering, while the group's offering and the cluster's cores and memory still show the old one. Until a retry completes, new nodes are deployed with the old offering.

The retry does skip the VMs that are already done, which is good. Syncing in a finally block, or computing cores and memory from the VMs' actual offerings, would keep the counters right in between.

6. Template launch permission is tracked per cluster but granted per account (minor)

java/.../KubernetesClusterManagerImpl.java:3016, :3026

Scenario: account X has clusters A and B, both on the default CKS template. A's scale-up grants the permission and records the detail on A. B's scale-up finds the permission already there and records nothing. A finishes and revokes the permission, and B's next node deploy fails.

The cluster-level workers have a similar overlap today, so this is not new. Keying the lock and the bookkeeping on account plus template would close the gap.

7. Size, limit and name checks run outside the lock (minor)

java/.../KubernetesClusterManagerImpl.java:3195, :3330, :3351

Operations on different groups can run at the same time, but validateNodeGroupClusterSize(), the resource-limit pre-check and the name check run before startNodeGroupOperation() takes the lock.

Scenario: the maximum size is 10 and the cluster has 8 nodes. Two groups are each scaled up by 2 at the same moment. Both checks pass, and the cluster ends up with 12 nodes. Two creates with the same name also both pass.

Suggestion: repeat these checks inside startNodeGroupOperation().

8. After a management server restart, the cluster stays in Scaling for over an hour (minor)

java/.../KubernetesClusterManagerImpl.java:3104

If the management server running a group operation restarts, the group stays busy. The cluster stays in Scaling until failStaleNodeGroupOperations() releases it, after the scale timeout plus 600 s, which is 70 minutes with the defaults. During that time the cluster can't be scaled, upgraded or deleted.

stopKubernetesCluster also has no state check. A stop issued while a group operation runs gets no Scaling -> Stopping transition, and it stops the VMs anyway.

Suggestion: record which management server owns each group operation and release that server's operations when it restarts. Also refuse a stop while any group is busy.

9. listKubernetesClusters builds the node lists twice (minor)

java/.../KubernetesClusterManagerImpl.java:935

Each cluster response now embeds a full group response for every group. Each group response reloads the group, cluster, offering, template and vm_map rows, plus a VM and NIC lookup per node. The virtualmachines loop already does the VM lookups. With many clusters this adds thousands of queries to every list call.

Suggestion: reuse nodeGroupById and the VM rows that are already loaded, or return only group summaries in the cluster response.

10. Nit: the image setting is inserted into a root shell command unchecked

java/.../KubernetesClusterService.java:155, resources/script/autoscale-kube-cluster:105

The value is passed inside single quotes to sudo and then used in a sed replacement that uses # as its delimiter. A value containing ', # or & breaks the command. Only an admin can set it, but checking it against an image reference pattern would give a clear error instead.

Tests

The new unit tests cover validation, the state helpers and the label and taint commands. These paths have no tests yet:

  • syncNodeGroupEntries() (the cores, memory and node count changes)
  • createMissingDefaultNodeGroups()
  • the change to listByClusterIdAndVmType(WORKER), which every caller now relies on to exclude group nodes
  • rollback in createKubernetesClusterNodeGroup when no node was provisioned
  • failStaleNodeGroupOperations()
  • the autoscaler specs and command (getClusterAutoscalerNodeGroupSpecs, getClusterAutoscalerCommand)
  • the capacity change in calculateNewClusterCountAndCapacity

A Marvin test that creates, scales and deletes a group would help reviewers who can't test by hand.

Questions

  1. Which autoscaler image did you use for non-default groups? Is there a kubernetes/autoscaler PR for it?
  2. Group nodes get the cluster's worker affinity groups (KubernetesClusterResourceModifierActionWorker.java:494) and its root disk size (:413). Would you consider per-group affinitygroupids and a root disk size? The schema isn't released yet, so adding them now costs no extra upgrade step. A group of large nodes under a strict host anti-affinity group shared with the default group runs out of hosts quickly.
  3. Is changing the template of an existing group out of scope? updateKubernetesClusterNodeGroup changes labels, taints and autoscaling; scaleKubernetesClusterNodeGroup changes the offering, but only upward and in place.
  4. The node group foreign keys to service_offering and vm_template use ON DELETE CASCADE, but the vm_map.node_group_id foreign key has no delete action. Is that intended? A hard delete of an offering row would then fail rather than cascade.
  5. Group labels and taints also stay in the node's kubelet --node-labels and --register-with-taints arguments. After the group's labels are updated, a node that registers again (for example after kubectl delete node) gets the old ones back. Should the kubelet arguments be rewritten on update, or should this be documented?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants