Skip to content

CKS: find a project cluster by id for the cluster autoscaler - #14916

Open
bhouse-nexthop wants to merge 1 commit into
apache:4.22from
bhouse-nexthop:cks-autoscaler-project
Open

bhouse-nexthop wants to merge 1 commit into
apache:4.22from
bhouse-nexthop:cks-autoscaler-project

Conversation

@bhouse-nexthop

Copy link
Copy Markdown
Collaborator

Description

The cluster autoscaler never scales a CKS cluster owned by a project (#14915). Its CloudStack provider looks the
cluster up with listKubernetesClusters id=<id> and no projectid, using the key of the project's Kubernetes
service account. For a user account, a list without projectid only searches the caller's own account, so the
autoscaler gets an empty list and logs "Unable to fetch cluster with id".

When a user account lists by id alone, listKubernetesClusters now also finds a cluster of a project it may list,
as if projectid had been given. Whether it may list the cluster is decided by the usual entity access check
(checkAccess with ListEntry), so project membership and project roles apply as they do with projectid.

Unchanged: lists without an id; lists with projectid, account or domainid; admin and domain admin callers
(they already find a cluster by id).

The provider could also send the project-id it reads from the cloud-config. This change makes the autoscaler
images that are already deployed work without a new image.

Fixes: #14915

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)
  • Build/CI
  • Test (unit or integration test code)

Feature/Enhancement Scale or Bug Severity

Feature/Enhancement Scale

  • Major
  • Minor

Bug Severity

  • BLOCKER
  • Critical
  • Major
  • Minor
  • Trivial

Screenshots (if appropriate):

How Has This Been Tested?

Unit tests in KubernetesClusterManagerImplTest: the project is resolved for a cluster the caller may list, not
when the access check denies it, not for an account-owned or unknown cluster; the search is unchanged with
projectid, account or domainid, without an id, and for admin and domain admin callers.
mvn -pl plugins/integrations/kubernetes-service -am test: all tests pass.

A lab test on a KVM zone follows in a comment.

The cluster autoscaler looks its cluster up with listKubernetesClusters
and the id only, using the key of the Kubernetes service account. For a
cluster owned by a project that account is a project member, and a list
by id without projectid only searches the caller's own account, so the
autoscaler gets an empty list, logs "Unable to fetch cluster" and never
scales.

When a user account lists by id alone, a cluster of a project it may
list (the usual entity access check, project roles included) is now
found as if projectid were given. Other lists, admin callers and lists
with projectid, account or domainid are unchanged.

Signed-off-by: Brad House <bhouse@nexthop.ai>
@codecov

codecov Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.73684% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 18.34%. Comparing base (a8735b2) to head (1fcd4bd).

Files with missing lines Patch % Lines
...bernetes/cluster/KubernetesClusterManagerImpl.java 94.73% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff            @@
##               4.22   #14916   +/-   ##
=========================================
  Coverage     18.34%   18.34%           
- Complexity    16671    16682   +11     
=========================================
  Files          5939     5939           
  Lines        537817   537835   +18     
  Branches      65938    65942    +4     
=========================================
+ Hits          98640    98678   +38     
+ Misses       427954   427932   -22     
- Partials      11223    11225    +2     
Flag Coverage Δ
uitests 4.08% <ø> (ø)
unittests 19.44% <94.73%> (+<0.01%) ⬆️

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.

@bhouse-nexthop

Copy link
Copy Markdown
Collaborator Author

Tested on a KVM lab (nested, Ceph RBD primary storage), with the cluster autoscaler that the v1.33.1 CKS ISO deploys (apache/cloudstack-kubernetes-autoscaler:latest). Each cluster: 1 control node, 1 worker, autoscaling min 1, max 3, owned by a project unless noted. The load was a deployment of 2 pods, each asking for 60% of a worker's CPU.

On 4.22 (4.22.1.1 plus this change):

Build Check Result
without the change listKubernetesClusters id=<id> signed with the key from the cluster's cloudstack-secret 200, empty list (with projectid added: the cluster)
without the change load that needs a second worker no scale-up in 15 min; autoscaler log: Unable to fetch cluster with id
with the change the same call, id only 200, the cluster
with the change load scaled to 2 workers, both Ready, both pods Running; no fetch errors
with the change load removed back to 1 worker after the node was unneeded for 10 min (removed with nodeids)

On main the same steps pass, same results: the bug reproduced on one project cluster, then with the change the same cluster scaled up and back down. A cluster owned by an account (not a project) also scaled up and down with the change, and its id-only lookup still works.

Not tested: project roles that deny listKubernetesClusters (unit tests only), domain admin callers.

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.

1 participant