Skip to content

Conversation

@anant-shipit
Copy link

Description:

Fixes #422

Problem

The PatchCRVersion function previously attempted to update the MeshSync CR version during startup without verifying if the CRD existed. This resulted in false positive errors when running in environments where MeshSync is not installed. Additionally, the update logic used custom retry loops rather than standard Kubernetes patterns.

Research & Proposed Fix

I have researched the Kubebuilder/Operator SDK patterns and updated the implementation plan as requested.

Findings:

  1. Standard Pattern: CRD version upgrades are typically handled via Conversion Webhooks or the main Reconcile loop.
  2. Current Context: Since PatchCRVersion runs during the imperative startup sequence (outside the reconcile loop), it requires self-contained resilience logic.

Proposed Fix:
I have updated the logic to use Controller Runtime patterns combined with MeshKit standards.

  1. Guard: Explicitly checks IsNotFound to fix Old MeshSync CRD not handled #422.
  2. Resilience: Uses RetryOnConflict (standard k8s utility) instead of a custom loop.
  3. Standards: Uses MeshKit for structured logging and error codes.

Implementation Details

  • Guard Logic: Added a check for IsNotFound to skip patching if the MeshSync CR is missing (clean state).
  • Concurrency Safety: Implemented controller-runtime client with MergeFrom to ensure idempotent updates.
  • Dependencies: Updated internal/config imports to align with the project-wide move to github.com/meshery/meshkit.

Signed-off-by:
[Anant Singh Rathore] <[[email protected]]>

Signed-off-by: Anant Singh Rathore <[email protected]>
@github-actions github-actions bot added the language/go Golang related label Dec 31, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @anant-shipit, 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 stability and reliability of MeshSync CR version updates during startup. By introducing a guard mechanism to prevent patching non-existent Custom Resources and adopting standard Kubernetes retry logic, the system avoids unnecessary errors in environments where MeshSync might not be fully deployed. The changes also align the CR patching process with modern controller-runtime patterns, promoting more robust and maintainable code.

Highlights

  • Robust CR Patching: The PatchCRVersion function has been refactored to prevent false positive errors by guarding against attempts to patch non-existent MeshSync Custom Resources (CRs). It now explicitly checks if the CR exists before proceeding with an update.
  • Standardized Retry Logic: Custom retry loops for CR updates have been replaced with the standard Kubernetes RetryOnConflict utility, ensuring more robust and idiomatic handling of concurrent updates and transient errors.
  • Controller Runtime Integration: The PatchCRVersion logic now leverages the controller-runtime client and MergeFrom patching strategy, aligning with Kubernetes operator development best practices for idempotent and concurrency-safe updates.
  • Dependency Updates: Key dependencies have been updated, including the removal of github.com/meshery/meshery-operator and the addition of sigs.k8s.io/controller-runtime as a direct dependency, along with other indirect dependency adjustments.
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
Contributor

@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 effectively addresses the issue of startup errors when the MeshSync CR is not present by making the PatchCRVersion function more resilient. The refactoring to use controller-runtime's RetryOnConflict and client is a great improvement that aligns with standard Kubernetes operator patterns. My review includes a couple of suggestions to further improve the code by removing a redundant API call and enhancing context propagation, which will improve efficiency and robustness.

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Anant Singh Rathore <[email protected]>
Copy link
Contributor

@n2h9 n2h9 left a comment

Choose a reason for hiding this comment

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

There is a compilation error

https://github.com/meshery/meshsync/actions/runs/20621952052/job/59606921695?pr=520

  pkg/lib/meshsync/meshsync.go:1: : # github.com/meshery/meshsync/pkg/lib/meshsync
  Error: pkg/lib/meshsync/meshsync.go:76:50: not enough arguments in call to config.PatchCRVersion
  	have (*rest.Config)
  	want ("context".Context, *rest.Config) (typecheck)

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

Labels

language/go Golang related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Old MeshSync CRD not handled

3 participants