Skip to content

fix(cronjob): replace panic on timezone load failure with graceful error skip#2907

Open
aryanputta wants to merge 2 commits intokubernetes:mainfrom
aryanputta:main
Open

fix(cronjob): replace panic on timezone load failure with graceful error skip#2907
aryanputta wants to merge 2 commits intokubernetes:mainfrom
aryanputta:main

Conversation

@aryanputta
Copy link
Copy Markdown

What this PR does / why we need it:

When a CronJob has spec.timeZone set to a named timezone (e.g. Asia/Singapore) and the kube-state-metrics container image does not include tzdata, cron.ParseStandard cannot resolve the location. The error was passed directly to panic(err) in the kube_cronjob_next_schedule_time generator, crashing the process and taking down all cluster metrics collection.

This change replaces panic(err) with klog.Errorf so the failure is logged at error level and the kube_cronjob_next_schedule_time metric is silently skipped for the affected CronJob. All other CronJobs and resource types continue serving metrics normally. Also adds "k8s.io/klog/v2" to the import block, which was previously absent from this file.

How does this change affect the cardinality of KSM: Does not change cardinality. The affected metric is omitted for CronJobs whose timezone cannot be resolved; it was previously not emittable at all because the process crashed.

Which issue(s) this PR fixes: Fixes #2898

Special notes for your reviewer: The fix is two lines in internal/store/cronjob.go. No new tests needed beyond running existing tests with a CronJob that has a named timezone -- the process no longer panics.

…graceful skip

When getNextScheduledTime fails because cron.ParseStandard cannot resolve a named timezone (e.g. Asia/Singapore without tzdata), the error was passed directly to panic(), crashing the process and taking down all cluster metrics collection.

Replace panic(err) with klog.Errorf so the failure is logged at error level and the metric is skipped for that CronJob. All other CronJobs and resource types continue serving metrics normally.

Also add "k8s.io/klog/v2" to the import block, which was the missing dependency for structured error logging in this file.
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: aryanputta
Once this PR has been reviewed and has the lgtm label, please assign dgrisonnet for approval. For more information see the 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

@k8s-ci-robot k8s-ci-robot requested a review from bhope March 25, 2026 16:00
@k8s-ci-robot k8s-ci-robot added the needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. label Mar 25, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

This issue is currently awaiting triage.

If kube-state-metrics contributors determine this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Welcome @aryanputta!

It looks like this is your first PR to kubernetes/kube-state-metrics 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kube-state-metrics has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Mar 25, 2026

CLA Not Signed

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Mar 25, 2026
@mrueg
Copy link
Copy Markdown
Member

mrueg commented Apr 7, 2026

@aryanputta can you ensure the CLA is signed? Thanks!

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Apr 7, 2026
@aryanputta
Copy link
Copy Markdown
Author

I think I did it, sorry for thr trouble.

@mrueg mrueg requested a review from Copilot April 7, 2026 22:43
@mrueg mrueg changed the title cronjob: replace panic on timezone load failure with graceful error skip fix(cronjob): replace panic on timezone load failure with graceful error skip Apr 7, 2026
Copy link
Copy Markdown

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

Prevents kube-state-metrics from crashing when CronJob.spec.timeZone refers to a named timezone that can’t be resolved (e.g., missing tzdata), by logging the error and skipping kube_cronjob_next_schedule_time for the affected CronJob.

Changes:

  • Replaced panic(err) on schedule parsing failure with klog error logging and early return (skip metric for that CronJob).
  • Added k8s.io/klog/v2 import to support the new logging.

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

Comment thread internal/store/cronjob.go Outdated
Comment thread internal/store/cronjob.go
Comment thread internal/store/cronjob.go
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. and removed cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 15, 2026
@mrueg
Copy link
Copy Markdown
Member

mrueg commented Apr 18, 2026

/check-cla

Copy link
Copy Markdown

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

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.


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

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

Labels

cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

Status: Needs Triage

4 participants