Skip to content

Add topology aware deletion priority example#313

Open
Nakshatra480 wants to merge 1 commit intoopenkruise:masterfrom
Nakshatra480:feature/topology-priority
Open

Add topology aware deletion priority example#313
Nakshatra480 wants to merge 1 commit intoopenkruise:masterfrom
Nakshatra480:feature/topology-priority

Conversation

@Nakshatra480
Copy link

Fixes #198

Description

This PR introduces a comprehensive example of how to implement Topology Aware Deletion Priority for GameServers.

In scenarios where game scale down is driven by infrastructure consolidation rather than purely by game session logic (e.g., games with no clear match boundaries or free join/leave), it is crucial to prioritize deleting GameServers from nodes that are easier to empty. This optimization helps cluster autoscalers scale down nodes more efficiently, reducing infrastructure costs.

This implementation leverages the existing ServiceQuality probe mechanism to dynamically calculate and set the DeletionPriority without requiring any changes to the core controller code.

Solution Overview

The solution uses a sidecar/inline probe approach to query node metadata and calculate a priority score.

  • Objective: Assign higher deletion priority to GameServers running on nodes with fewer pods and fewer pod owners.
  • Mechanism: A ServiceQuality exec probe runs a script that queries the Kubernetes API for pod metrics on the current node.
  • Integration: The probe result is passed to the DeletionPriority field using the ServiceQuality template variable {{.result}}.

Implementation Details

Two new example files are added in examples/topology-deletion-priority/:

  1. rbac.yaml:

    • Defines a ServiceAccount, Role, and RoleBinding.
    • Grants minimal necessary permissions (list pods) to the GameServer so it can query topology information from the API server.
  2. gameserverset.yaml:

    • Demonstrates a GameServerSet configuration.
    • Includes an inline script that:
      • Authenticates with the K8s API using the service account token.
      • Queries pods on the current node (spec.nodeName).
      • Calculates priority based on configurable weights.
    • Configures the ServiceQuality action to map the script output to deletionPriority.

Priority Calculation

The probe calculates the priority using the following logic:

# Weights (Configurable in script)
BASE_PRIORITY = 100
POD_WEIGHT = 10
OWNER_WEIGHT = 5

# Formula
DeletionPriority = BASE_PRIORITY - (PodCount * POD_WEIGHT) - (OwnerCount * OWNER_WEIGHT)

@kruise-bot kruise-bot requested review from FillZpp and zmberg January 27, 2026 09:43
@kruise-bot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign furykerry for approval by writing /assign @furykerry in a comment. For more information see:The Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@codecov
Copy link

codecov bot commented Jan 27, 2026

Codecov Report

❌ Patch coverage is 40.38462% with 31 lines in your changes missing coverage. Please review.
✅ Project coverage is 40.26%. Comparing base (25626ff) to head (dadc058).

Files with missing lines Patch % Lines
pkg/controllers/gameserver/gameserver_manager.go 0.00% 16 Missing and 1 partial ⚠️
pkg/controllers/gameserver/topology_rater.go 60.00% 7 Missing and 7 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #313      +/-   ##
==========================================
+ Coverage   40.25%   40.26%   +0.01%     
==========================================
  Files         112      113       +1     
  Lines       12510    12559      +49     
==========================================
+ Hits         5036     5057      +21     
- Misses       7067     7087      +20     
- Partials      407      415       +8     
Flag Coverage Δ
unittests 40.26% <40.38%> (+0.01%) ⬆️

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

☔ View full report in Codecov by Sentry.
📢 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.

@kruise-bot kruise-bot added size/S and removed size/M labels Jan 27, 2026
@Nakshatra480 Nakshatra480 force-pushed the feature/topology-priority branch from fab5b01 to b2c7252 Compare January 27, 2026 09:57
@kruise-bot kruise-bot added size/L and removed size/S labels Jan 27, 2026
@Nakshatra480 Nakshatra480 force-pushed the feature/topology-priority branch 8 times, most recently from 17074ee to beb9fbd Compare January 27, 2026 13:15
Implements automated deletion priority calculation based on node topology.

Changes:
- Added TopologyDeletionPriorityConfig to GameServerSetSpec API
- Created topology_rater.go with automatic calculation logic
- Integrated into gameserver_manager with ServiceQuality precedence
- Added automated example and tests

Fixes openkruise#198
@Nakshatra480 Nakshatra480 force-pushed the feature/topology-priority branch from 8b2d9b8 to dadc058 Compare January 27, 2026 14:06
@Nakshatra480
Copy link
Author

Hi @FillZpp @zmberg all the changes are done from my side. pls review this pr and let me know if anything comes up... thanks

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] DeletionPriority-Topology-Rater

2 participants

Comments