Skip to content

feat: metadata support in the kubernetes_sync#1905

Open
Nilushiya wants to merge 7 commits intoopen-feature:mainfrom
Nilushiya:metadata
Open

feat: metadata support in the kubernetes_sync#1905
Nilushiya wants to merge 7 commits intoopen-feature:mainfrom
Nilushiya:metadata

Conversation

@Nilushiya
Copy link
Copy Markdown

This PR

  • Preserve FeatureFlag metadata when syncing from Kubernetes by marshalling spec.flagSpec directly from unstructured objects.
  • Harden informer tombstone handling and watcher readiness for Kubernetes sync.
  • Add unit tests covering metadata preservation and tombstone unwrap.

Related Issues

Fixes # #754 (CRD definition is not following the latest flagD specifications) - in the open-feature-operator
already rased the pr for open-feature-operator CRD support for metaData - (open-feature/open-feature-operator#808 that alone is not enough, so in Flagd also want to change. This PR refers to that.

Notes

  • Architecture unchanged; only Kubernetes sync path touched.
  • No dependency/version changes.

Follow-up Tasks

  • None.
    This change keeps the Kubernetes sync path working with metadata by treating FeatureFlag resources as unstructured objects and marshaling spec.flagSpec directly. That avoids converting into typed CRDs (which can drop unknown fields like metadata) and ensures delete tombstones are handled safely, so the synced payload now preserves any metadata the CRD allows.

How to test

  1. From repo root:
    • cd core && GOPATH=/tmp/go GOCACHE=/tmp/go-build go test ./pkg/sync/kubernetes
  2. (Optional) Build and run your existing workflow to confirm metadata is present end-to-end.

@Nilushiya Nilushiya requested review from a team as code owners March 16, 2026 04:07
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 16, 2026

Deploy Preview for polite-licorice-3db33c canceled.

Name Link
🔨 Latest commit 12286f7
🔍 Latest deploy log https://app.netlify.com/projects/polite-licorice-3db33c/deploys/69bcae8e35ecb30008847f9e

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Mar 16, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

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 significantly enhances the Kubernetes synchronization mechanism by ensuring that FeatureFlag metadata is consistently preserved. It achieves this by directly processing spec.flagSpec from unstructured Kubernetes objects, which prevents the loss of unknown fields during conversion to typed CRDs. Additionally, the changes improve the robustness of informer tombstone handling and the readiness of the watcher, leading to a more reliable and complete synchronization of flag configurations.

Highlights

  • Metadata Preservation: Preserved FeatureFlag metadata when syncing from Kubernetes by marshalling spec.flagSpec directly from unstructured objects, avoiding data loss from typed CRD conversions.
  • Kubernetes Sync Hardening: Hardened informer tombstone handling and improved watcher readiness for the Kubernetes synchronization process.
  • Unit Test Coverage: Added comprehensive unit tests covering metadata preservation and the unwrapping of tombstone objects.
Changelog
  • core/pkg/sync/kubernetes/kubernetes_sync.go
    • Reordered import statements for consistency.
    • Modified the Sync function to buffer the notifies channel and reordered the startup of notify and watcher goroutines to improve readiness.
    • Updated the fetch function to utilize asUnstructured and marshalFlagSpec for processing Kubernetes objects.
    • Refactored commonHandler and updateFuncHandler to use asUnstructured and methods from unstructured.Unstructured for API version and name validation.
    • Renamed and refactored toFFCfg to asUnstructured, enhancing its capability to handle both unstructured.Unstructured and cache.DeletedFinalStateUnknown types.
    • Refactored marshallFeatureFlagSpec to marshalFlagSpec, which now directly extracts and marshals spec.flagSpec from an unstructured.Unstructured object.
  • core/pkg/sync/kubernetes/kubernetes_sync_test.go
    • Added stdsync import for improved concurrency control in tests.
    • Renamed Test_toFFCfg to Test_asUnstructured and updated its logic to thoroughly test the new asUnstructured function, including scenarios for tombstone unwrapping.
    • Modified TestSync_ReSync to incorporate context.WithCancel and stdsync.WaitGroup for better management of asynchronous test execution and added a timeout for data channel reads.
    • Updated the getCFG helper function to include a default flagSpec structure in the generated configuration.
    • Modified the toUnstructured helper to return a *unstructured.Unstructured type.
    • Updated TestMeasure to use the new marshalFlagSpec with an unstructured.Unstructured input and require.JSONEq for more precise JSON comparison.
Activity
  • No human activity (comments, reviews) has been recorded for 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

@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 adds metadata support for the Kubernetes sync provider by switching to unstructured objects, which prevents metadata from being dropped during marshalling. The changes also harden the sync logic by handling informer tombstones and improving watcher readiness with a buffered channel. The test suite has been significantly improved, with more robust asynchronous testing using proper context management. Overall, this is a solid enhancement. I have one suggestion to improve context handling in a test case for better consistency and correctness.

@Nilushiya Nilushiya changed the title Feature: Metadata support in the kubernetes_sync feat: metadata support in the kubernetes_sync Mar 16, 2026
Nilushiya.K and others added 5 commits March 16, 2026 13:03
Signed-off-by: Nilushiya.K <Nilushiya.K@cloudsolutions.com.sa>
Add docs about graceful defaulting.

---------

Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
Signed-off-by: Nilushiya.K <Nilushiya.K@cloudsolutions.com.sa>
Proposes a "rollout operator". Facilitates linear, progressive rollouts
as a fundamental feature flag use case: gradually shifting traffic from
one variant to another over time.

See ADR for justification and full proposal.

See also:
- draft implementation **WITH DEMO** in flagd:
open-feature#1868
  - run demo with: `make build-flagd && ./demo-rollout.sh`
- draft schema changes:
open-feature/flagd-schemas#205

![output](https://github.com/user-attachments/assets/7eaeafea-bc60-40db-a1ac-65d9c15f82a4)

---------

Signed-off-by: Todd Baert <todd.baert@dynatrace.com>
Signed-off-by: Nilushiya.K <Nilushiya.K@cloudsolutions.com.sa>
Update core/pkg/sync/kubernetes/kubernetes_sync_test.go

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Signed-off-by: Nilushiya Kaneshalingam <107831659+Nilushiya@users.noreply.github.com>
Signed-off-by: Nilushiya.K <Nilushiya.K@cloudsolutions.com.sa>
Signed-off-by: Nilushiya.K <Nilushiya.K@cloudsolutions.com.sa>
@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Mar 16, 2026
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels Mar 16, 2026
@Nilushiya
Copy link
Copy Markdown
Author

Hi @toddbaert, @justinabrahms, @beeme1mr, @oxddr, @lukas-reining, @odubajDT, @thisthat, @bacherfl

This PR fixes #754 (CRD definition not following the latest flagD specifications).

As part of this fix, made the following changes:


⚠️ FOSSA License Scan — 2 Flagged Issues

The automated FOSSA license scan on this PR is reporting 2 flagged license issues, but the details are behind a 🔒 Maintainer Access Required lock, so I'm unable to view or investigate them from my end.

Could a maintainer please:

  1. Check the FOSSA scan report for this PR
  2. Confirm whether the flagged issues are pre-existing or introduced by my changes
  3. Let me know if any action is needed on my side

Note: My changes in this PR do not introduce any new dependencies, so the flagged issues are likely pre-existing in the repo.


If the license scan looks good from your side, could you please go ahead and review this PR? I believe the changes are ready for review. Happy to make any adjustments based on your feedback!

Thanks.

@lukas-reining
Copy link
Copy Markdown
Member

I added ignore rules for the license issues as CairoSVG is only used as dev tooling and not shipped.

@sonarqubecloud
Copy link
Copy Markdown

@toddbaert
Copy link
Copy Markdown
Member

Thanks @Nilushiya ! I'll give this a look in the next couple days!

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

Labels

size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants