Skip to content

Conversation

@gfdsa
Copy link

@gfdsa gfdsa commented Nov 5, 2025

No description provided.

@gemini-code-assist
Copy link

Summary of Changes

Hello @gfdsa, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the restart-operator's ability to handle more sophisticated cron expressions. By updating the validation logic and schema, users can now define restart schedules using advanced cron syntax such as step values, ranges, lists, and timezone specifications, providing greater flexibility and control over scheduled restarts. The changes include updates to the CRD, API types, sample configurations, and comprehensive test coverage to ensure the robustness of the new validation.

Highlights

  • Expanded Cron Expression Support: The validation for cron schedules has been significantly enhanced to support a broader range of syntax, including step values (e.g., */5), ranges (e.g., 9-17), lists (e.g., 9,12,15,18), and timezone prefixes (e.g., TZ=, CRON_TZ=).
  • Updated CRD and API Validation: The pattern for the schedule field in crd.yaml and pkg/apis/v1alpha1/types.go has been updated to reflect these new capabilities, ensuring proper validation of the more flexible cron expressions.
  • Comprehensive Test Coverage: New test cases have been added in pkg/controller/controller_test.go to thoroughly validate the updated cron expression regex, covering various valid and invalid scenarios, including timezone-prefixed expressions.
  • Improved Sample Configuration: The restartschedule_sample.yaml has been updated with a new example and detailed comments to illustrate the newly supported cron formats, making it easier for users to understand and utilize the enhanced functionality.
  • Helm Chart Version Bump: The Helm chart version for restart-operator has been incremented from 0.1.1-alpha1 to 0.1.1-alpha2.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request significantly improves cron expression support by updating the validation regex, adding more comprehensive examples, and including new tests. The changes are a solid step forward. I've provided a few suggestions to further enhance the code. My main feedback points relate to the new regex pattern, which is a bit too permissive, and a minor formatting issue in a Go file. I've also suggested adding more test cases to explicitly document the regex's known limitations.

type: string
description: "Schedule in Cron format"
pattern: "^(\\d+|\\*)(/\\d+)?(\\s+(\\d+|\\*)(/\\d+)?){4}$"
pattern: "^((TZ=|CRON_TZ=)[A-Za-z/_]+(\\s+))?(([0-9]+|\\*)([-,/]([0-9]+|\\*))*\\s+){4}([0-9]+|\\*)([-,/]([0-9]+|\\*))*$"

Choose a reason for hiding this comment

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

medium

The new regex pattern is a great improvement and covers many more valid cron expressions. However, it's a bit too permissive and may accept some invalid formats that the underlying robfig/cron parser will reject. For example, a field like 1-2-3 would be accepted by this regex, but is not a valid cron field part. While the controller will eventually reject this, tightening the regex would provide users with earlier feedback from kubectl apply. The part ([-,/]([0-9]+|\*))* allows for repeated separators like - or / in a single field.

Comment on lines +24 to +27
type RestartScheduleSpec struct {
// +kubebuilder:validation:Required
// +kubebuilder:validation:Pattern=`^((TZ=|CRON_TZ=)[A-Za-z/_]+(\s+))?(([0-9]+|\*)([-,/]([0-9]+|\*))*\s+){4}([0-9]+|\*)([-,/]([0-9]+|\*))*$`
Schedule string `json:"schedule"`

Choose a reason for hiding this comment

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

medium

There are a couple of issues on these lines:

  1. Formatting: Line 24 is indented with a tab, which is inconsistent with Go's standard formatting (gofmt). The type keyword should not be indented, and fields within the struct should be indented consistently.
  2. Regex Permissiveness: The regex on line 26, while a good improvement, is a bit too permissive. It will accept some invalid cron strings (e.g., 1-2-3 in a field), which the controller's cron parser will later reject. This is the same issue as in the CRD definition.
Suggested change
type RestartScheduleSpec struct {
// +kubebuilder:validation:Required
// +kubebuilder:validation:Pattern=`^((TZ=|CRON_TZ=)[A-Za-z/_]+(\s+))?(([0-9]+|\*)([-,/]([0-9]+|\*))*\s+){4}([0-9]+|\*)([-,/]([0-9]+|\*))*$`
Schedule string `json:"schedule"`
type RestartScheduleSpec struct {
// +kubebuilder:validation:Required
// +kubebuilder:validation:Pattern=`^((TZ=|CRON_TZ=)[A-Za-z/_]+(\s+))?(([0-9]+|\*)([-,/]([0-9]+|\*))* \s+){4}([0-9]+|\*)([-,/]([0-9]+|\*))*$`
Schedule string `json:"schedule"`

Comment on lines +156 to +171
// Invalid expressions
{
name: "Missing fields",
input: "0 * * *",
should: false,
},
{
name: "Too many fields",
input: "0 * * * * *",
should: false,
},
{
name: "Invalid text",
input: "invalid cron expression",
should: false,
},

Choose a reason for hiding this comment

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

medium

It's great that you've added tests for the new regex. To make this test suite even more robust and to document the known limitations of the regex, consider adding test cases for cron strings that are structurally invalid but are currently passed by the regex. This will make it clear what the CRD validation allows vs. what the controller's parser will ultimately reject.

For example:

// ... inside tests slice
{
    name:   "Structurally invalid: multiple hyphens in one field",
    input:  "0 1-2-3 * * *",
    should: true, // The regex currently accepts this, though cron parsers will not.
},
{
    name:   "Structurally invalid: multiple slashes in one field",
    input:  "*/2/3 * * * *",
    should: true, // The regex currently accepts this, though cron parsers will not.
},

These tests would pass with the current regex, correctly demonstrating its permissiveness and serving as documentation.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant