Skip to content

fix(role-instance): restart policy does not take effect#185

Merged
cheyang merged 2 commits intosgl-project:mainfrom
Syspretor:fix/restart-policy-in-instanceset
Mar 9, 2026
Merged

fix(role-instance): restart policy does not take effect#185
cheyang merged 2 commits intosgl-project:mainfrom
Syspretor:fix/restart-policy-in-instanceset

Conversation

@Syspretor
Copy link
Copy Markdown
Collaborator

Ⅰ. Motivation

Ⅱ. Modifications

Ⅲ. Does this pull request fix one issue?

fixes #165

Ⅳ. List the added test cases (unit test/integration test) if any, please explain if no tests are needed.

Ⅴ. Describe how to verify it

VI. Special notes for reviews

Checklist

  • Format your code make fmt.
  • Add unit tests or integration tests.
  • Update the documentation related to the change.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, 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 resolves an issue where the RecreateInstanceOnPodRestart policy was not effectively applied, leading to instances not being fully recreated when expected. The changes introduce robust logic to detect pod restarts or deletions within an instance and trigger a complete recreation of all associated pods, ensuring the specified restart policy is honored and the instance maintains its desired state.

Highlights

  • Restart Policy Enforcement: Implemented logic within the instance_scale.go reconciler to correctly handle the RecreateInstanceOnPodRestart policy. This ensures that if any pod within an instance restarts or is deleted, the entire instance is recreated as per the policy.
  • New Helper Functions: Introduced shouldRecreateInstance, wasInstanceReady, and getExpectedPodCount functions to encapsulate the complex logic for determining when an instance recreation is necessary, considering container restarts, pod deletions, and the instance's readiness state.
  • Utility Import: Added an import for sigs.k8s.io/rbgs/pkg/utils to leverage the ContainerRestarted helper function, simplifying the check for container restarts.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • pkg/reconciler/instance/sync/instance_scale.go
    • Imported the utils package to access container restart detection.
    • Integrated a check for the RecreateInstanceOnPodRestart policy within the calculateDiffsWithExpectation method.
    • Added shouldRecreateInstance to determine if an instance needs full recreation based on pod restarts or deletions and the instance's ready status.
    • Implemented wasInstanceReady to verify if an instance was previously in a ready state.
    • Included getExpectedPodCount to calculate the total number of pods expected for an instance.
Activity
  • No human activity has been recorded on this pull request yet.
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
Copy Markdown
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 bug (Issue #165) where setting RecreateInstanceOnPodRestart as the RestartPolicy on an Instance workload had no effect. The instance controller was not checking the restart policy, so when a pod failed or was deleted, the sibling pods in the same instance were not being recreated.

Changes:

  • Introduces shouldRecreateInstance to check whether the instance should be fully recreated based on RestartPolicy=RecreateInstanceOnPodRestart, triggered either by container restarts or by pod count falling below expected.
  • Adds helper functions wasInstanceReady (checks InstanceReady condition in status) and getExpectedPodCount (sums component sizes) to support the recreation decision.
  • Wires the shouldRecreateInstance check into calculateDiffsWithExpectation before the normal scale/update logic.

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

Comment thread pkg/reconciler/instance/sync/instance_scale.go
Copy link
Copy Markdown

@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 implements the RecreateInstanceOnPodRestart policy for Instance resources. The core logic correctly identifies conditions for instance recreation (pod restarts or deletions) and triggers it by marking all existing pods for deletion. The implementation includes necessary checks to prevent infinite recreation loops, such as verifying the instance was previously in a Ready state before acting on pod deletions. I've found a potential compilation issue and a suggestion for a performance improvement.

Comment thread pkg/reconciler/instance/sync/instance_scale.go
Comment thread pkg/reconciler/instance/sync/instance_scale.go
Comment thread pkg/reconciler/instance/sync/instance_scale.go Outdated
Comment thread pkg/reconciler/instance/sync/instance_scale.go
Copy link
Copy Markdown
Collaborator

@cheyang cheyang left a comment

Choose a reason for hiding this comment

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

/lgtm
/approve

@cheyang cheyang merged commit 88ed292 into sgl-project:main Mar 9, 2026
8 checks passed
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.

[Bug] instance restart policy not working

3 participants