Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 22, 2025

Cherry-pick of #4731 to release-1.12. Scheduler panics with nil pointer dereference when started without --enable-metrics=true because Kubernetes scheduler framework plugins access k8smetrics.Goroutines unconditionally.

Changes:

  • Move metrics.InitKubeSchedulerRelatedMetrics() outside the metrics-enabled conditional in cmd/scheduler/app/server.go
  • Ensures metric registry initialization occurs regardless of --enable-metrics flag
// Before: initialization only when metrics enabled
if opt.EnableMetrics || opt.EnablePprof {
    metrics.InitKubeSchedulerRelatedMetrics()
    go startMetricsServer(opt)
}

// After: always initialize registry, conditionally start server
metrics.InitKubeSchedulerRelatedMetrics()

if opt.EnableMetrics || opt.EnablePprof {
    go startMetricsServer(opt)
}

The panic occurs in k8s.io/kubernetes/pkg/scheduler/framework/parallelize.Parallelizer.Until when it calls Goroutines.WithLabelValues() on a nil metric.

Original prompt

This section details on the original issue you should resolve

<issue_title>[release-1.12] Fix scheduler panic when metrics are disabled</issue_title>
<issue_description>Manual cherrypick required.

#4731 failed to apply on top of branch "release-1.12":

Patch is empty.
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@volcano-sh-bot volcano-sh-bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Dec 22, 2025
Move InitKubeSchedulerRelatedMetrics() outside conditional block to ensure
k8smetrics.Goroutines is always initialized before scheduler starts.

This is a manual cherry-pick of PR #4731 to the release-1.12 branch.

Co-authored-by: JesseStutler <38534065+JesseStutler@users.noreply.github.com>
@volcano-sh-bot
Copy link
Contributor

[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 kevin-wangzefeng for approval. 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

Copilot AI changed the title [WIP] Fix scheduler panic issue when metrics are disabled Fix scheduler panic when metrics are disabled Dec 22, 2025
Copilot AI requested a review from JesseStutler December 22, 2025 06:26
@JesseStutler JesseStutler marked this pull request as ready for review December 22, 2025 06:34
Copilot AI review requested due to automatic review settings December 22, 2025 06:34
@volcano-sh-bot volcano-sh-bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 22, 2025
@JesseStutler JesseStutler changed the title Fix scheduler panic when metrics are disabled [Cherry-pick release-1.12] Fix scheduler panic when metrics are disabled Dec 22, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a critical scheduler panic that occurs when the scheduler is started without the --enable-metrics=true flag. The panic was caused by a nil pointer dereference in k8smetrics.Goroutines, which is accessed by Kubernetes scheduler framework plugins regardless of the metrics flag setting.

Key changes:

  • Move metric registry initialization outside the conditional block to ensure it always occurs
  • Add explanatory comment documenting why this initialization is required unconditionally

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@JesseStutler
Copy link
Member

/retest

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

Labels

size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants