Skip to content

fix: define resources in FeatureFlagSource#809

Open
azdobylak wants to merge 1 commit intoopen-feature:mainfrom
azdobylak:fix-resources
Open

fix: define resources in FeatureFlagSource#809
azdobylak wants to merge 1 commit intoopen-feature:mainfrom
azdobylak:fix-resources

Conversation

@azdobylak
Copy link
Copy Markdown

This PR

Fixes a bug where sidecar resources (limits, requests) defined in the FeatureFlagSource CRD were ignored.

Related Issues

Fixes #780

Notes

Follow-up Tasks

How to test

Ovewrite default sidecar resources in FeatureFlagSource (example in #780).

@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 addresses a critical bug preventing the proper application of sidecar resource configurations specified in the FeatureFlagSource CRD. By introducing explicit merging logic for resource requests and limits, it ensures that these vital operational parameters are correctly inherited and applied, enhancing the reliability and configurability of feature flag sources. The changes include updates to the core API types and corresponding test cases to validate the fix.

Highlights

  • Bug Fix: Resolved an issue where sidecar resource requests and limits defined in the FeatureFlagSource Custom Resource Definition (CRD) were not being applied or merged correctly.
  • Resource Merging: Implemented logic within the FeatureFlagSourceSpec.Merge function to properly handle and merge Resources.Requests and Resources.Limits.
  • Test Coverage: Added new test cases and assertions to ensure the correct merging of resource requests and limits for FeatureFlagSource configurations.
Changelog
  • api/core/v1beta1/featureflagsource_types.go
    • Implemented logic within the FeatureFlagSourceSpec.Merge method to correctly merge Resources.Requests and Resources.Limits from a new spec into an existing one.
  • api/core/v1beta1/featureflagsource_types_test.go
    • Imported the k8s.io/apimachinery/pkg/api/resource package.
    • Added Resources definitions (requests and limits) to FeatureFlagSourceSpec objects within test cases.
    • Included assertions to verify that resource requests and limits are correctly merged during the Test_FLagSourceConfiguration_Merge execution.
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

@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 fixes a bug where resource limits and requests from FeatureFlagSource were not being applied. The changes correctly merge these resource definitions and include corresponding tests. My review includes a suggestion to refactor the merge logic to reduce code duplication and improve maintainability.

Comment on lines +211 to +226
if len(new.Resources.Requests) != 0 {
if fc.Resources.Requests == nil {
fc.Resources.Requests = corev1.ResourceList{}
}
for k, v := range new.Resources.Requests {
fc.Resources.Requests[k] = v
}
}
if len(new.Resources.Limits) != 0 {
if fc.Resources.Limits == nil {
fc.Resources.Limits = corev1.ResourceList{}
}
for k, v := range new.Resources.Limits {
fc.Resources.Limits[k] = v
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The logic for merging resource requests and limits is duplicated. To improve maintainability and reduce code duplication, consider extracting this logic into a helper function.

For example, you could define a helper:

func mergeResourceList(dst *corev1.ResourceList, src corev1.ResourceList) {
	if len(src) == 0 {
		return
	}
	if *dst == nil {
		*dst = corev1.ResourceList{}
	}
	for k, v := range src {
		(*dst)[k] = v
	}
}

And then simplify the Merge function by replacing the current implementation with:

mergeResourceList(&fc.Resources.Requests, new.Resources.Requests)
mergeResourceList(&fc.Resources.Limits, new.Resources.Limits)

This would make the code cleaner and easier to maintain.

handle resources in Merge

Signed-off-by: Adrian Zdobylak <adrian.zdobylak@tensquaregames.com>
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.

FeatureFlagSource resources are ignored

1 participant