Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(operator): merge brokertopicconsumers of a same service into brokerconsumers #1368

Merged
merged 1 commit into from Apr 3, 2024

Conversation

gfyrag
Copy link
Contributor

@gfyrag gfyrag commented Mar 30, 2024

Summary by CodeRabbit

  • New Features

    • Introduced a new API definition for BrokerConsumer to manage broker consumers in a Kubernetes environment.
  • Enhancements

    • Updated controller-gen version from v0.13.0 to v0.14.0.
    • Simplified logic for reconciling broker consumers and topics, including creation, updating, and ownership management.
    • Modified deployment creation logic to utilize the new BrokerConsumer type.
  • Refactor

    • Renamed BrokerTopicConsumer to BrokerConsumer across various files, reflecting a shift in functionality and focus.
    • Consolidated references and variable names from consumers to consumer to align with new naming conventions.
  • Documentation

    • Added documentation for the new BrokerConsumer entity and its specifications in the API schema definitions.

@gfyrag gfyrag requested a review from a team as a code owner March 30, 2024 16:59
Copy link
Contributor

coderabbitai bot commented Mar 30, 2024

Walkthrough

The changes revolve around updating the controller-gen version and introducing the BrokerConsumer API in a Kubernetes operator framework. These updates enhance build configurations, API definitions, and internal resource management logic. The shift from BrokerTopicConsumer to BrokerConsumer signifies a refined approach to handling broker consumers, emphasizing streamlined management and deployment processes in a Kubernetes environment.

Changes

Files Summary
Earthfile, .../Makefile Updated controller-gen version from v0.13.0 to v0.14.0.
.../PROJECT, .../api/.../brokerconsumer_types.go, .../docs/crd.md, .../api/.../zz_generated.deepcopy.go Introduced BrokerConsumer API with definitions and deep copy functions.
.../internal/resources/.../controller.go, .../internal/resources/.../create.go, .../internal/resources/.../deployments.go, .../internal/resources/webhooks/controller.go, .../internal/resources/webhooks/deployment.go, .../internal/tests/..._controller_test.go, .../internal/tests/orchestration_controller_test.go Transitioned from BrokerTopicConsumer to BrokerConsumer, updating related logic and tests.
.../internal/resources/.../controller.go Simplified logic for managing broker topics and consumers.

🐇✨
In the realm of code, where logic does thrive,
A rabbit hopped in, making updates come alive.
From BrokerTopicConsumer to BrokerConsumer, a shift,
With versions updated, giving spirits a lift.
In Kubernetes' garden, under the digital sky,
The rabbit's work done, with a satisfied sigh.
🌟🐾

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 01c96c3 and d523350.
Files ignored due to path filters (72)
  • components/operator/config/crd/bases/auth.components.formance.com_clients.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/auth.components.formance.com_scopes.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/components.formance.com_auths.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/components.formance.com_controls.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/components.formance.com_counterparties.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/components.formance.com_ledgers.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/components.formance.com_orchestrations.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/components.formance.com_payments.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/components.formance.com_searches.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/components.formance.com_searchingesters.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/components.formance.com_wallets.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/components.formance.com_webhooks.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_authclients.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_auths.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_benthos.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_benthosstreams.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_brokerconsumers.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_brokertopicconsumers.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_brokertopics.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_databases.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_gatewayhttpapis.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_gateways.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_ledgers.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_orchestrations.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_payments.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_reconciliations.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_resourcereferences.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_searches.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_settings.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_stacks.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_stargates.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_versions.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_wallets.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_webhooks.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/stack.formance.com_configurations.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/stack.formance.com_licenses.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/stack.formance.com_migrations.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/stack.formance.com_stacks.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/stack.formance.com_versions.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/kustomization.yaml is excluded by !**/*.yaml
  • components/operator/config/rbac/formance.com_brokerconsumer_editor_role.yaml is excluded by !**/*.yaml
  • components/operator/config/rbac/formance.com_brokerconsumer_viewer_role.yaml is excluded by !**/*.yaml
  • components/operator/config/rbac/role.yaml is excluded by !**/*.yaml
  • components/operator/config/samples/formance.com_v1beta1_brokerconsumer.yaml is excluded by !**/*.yaml
  • components/operator/config/samples/kustomization.yaml is excluded by !**/*.yaml
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_authclients.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_auths.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_benthos.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_benthosstreams.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_brokerconsumers.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_brokertopicconsumers.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_brokertopics.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_configurations.stack.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_databases.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_gatewayhttpapis.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_gateways.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_ledgers.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_migrations.stack.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_orchestrations.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_payments.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_reconciliations.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_resourcereferences.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_searches.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_settings.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_stacks.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_stacks.stack.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_stargates.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_versions.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_versions.stack.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_wallets.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_webhooks.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/rbac.authorization.k8s.io_v1_clusterrole_manager-role.yaml is excluded by !**/*.yaml, !**/gen/**
Files selected for processing (15)
  • components/operator/Earthfile (1 hunks)
  • components/operator/Makefile (1 hunks)
  • components/operator/PROJECT (1 hunks)
  • components/operator/api/formance.com/v1beta1/brokerconsumer_types.go (1 hunks)
  • components/operator/api/formance.com/v1beta1/zz_generated.deepcopy.go (1 hunks)
  • components/operator/docs/crd.md (4 hunks)
  • components/operator/internal/resources/brokerconsumers/controller.go (1 hunks)
  • components/operator/internal/resources/brokerconsumers/create.go (1 hunks)
  • components/operator/internal/resources/brokertopicconsumers/controller.go (1 hunks)
  • components/operator/internal/resources/orchestrations/controller.go (4 hunks)
  • components/operator/internal/resources/orchestrations/deployments.go (2 hunks)
  • components/operator/internal/resources/webhooks/controller.go (4 hunks)
  • components/operator/internal/resources/webhooks/deployment.go (6 hunks)
  • components/operator/internal/tests/brokerconsumer_controller_test.go (3 hunks)
  • components/operator/internal/tests/orchestration_controller_test.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • components/operator/internal/tests/brokerconsumer_controller_test.go
Additional Context Used
Additional comments not posted (21)
components/operator/internal/resources/brokerconsumers/create.go (2)

16-43: The Create function efficiently creates or updates a BrokerConsumer object. However, consider adding error handling for the case where services is empty. This could prevent creating a BrokerConsumer with no services, which might not be a valid state depending on your domain logic.


46-63: In CreateOrUpdateOnAllServices, the filtering logic to exclude services of the same kind as the consumer is clear and concise. However, ensure that the ListEventPublishers function, which is not visible in this context, correctly handles errors and edge cases, such as when no publishers are found for the given stack.

Verification successful

The ListEventPublishers function in publisher.go correctly handles errors through its implementation, specifically by returning an error if the List method fails. For the case where no publishers are found for a given stack, it returns an empty slice, which is a standard and acceptable practice in Go for handling such scenarios. The caller of this function is expected to handle the returned slice accordingly, whether it contains items or not. This addresses the concerns raised in the review comment regarding error handling and edge cases.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the error handling and edge cases in ListEventPublishers function
grep -r "ListEventPublishers" .

Length of output: 311



Script:

#!/bin/bash
# Examine the implementation of ListEventPublishers function for error handling and edge cases
cat ./components/operator/internal/core/publisher.go

Length of output: 930

components/operator/api/formance.com/v1beta1/brokerconsumer_types.go (1)

23-63: The BrokerConsumer type is well-defined, with clear specifications for desired and observed states. It's good practice to include methods like SetReady, IsReady, SetError, and GetStack directly within the type definition, as it encapsulates functionality related to the object's state management. Ensure that these methods are used consistently across your controllers to manage the state of BrokerConsumer objects.

components/operator/internal/resources/brokertopicconsumers/controller.go (1)

33-68: The refactored Reconcile function simplifies the management of broker topics and consumers. However, ensure that the sorting of services (sort.Strings(t.Spec.Services)) and setting of owner references (t.SetOwnerReferences(topicQuery.OwnerReferences)) are necessary and correctly implemented. These operations can have implications on the Kubernetes objects' lifecycle and should be carefully considered.

Verification successful

The verification process confirms that both sorting services and setting owner references are standard practices within the project, used across various components for managing lists and Kubernetes object lifecycles, respectively. This underscores the importance of ensuring these operations are correctly implemented in the Reconcile function, as they have significant implications on system behavior and resource management. The original comment remains valid and requires careful consideration of these operations.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the necessity and correctness of sorting services and setting owner references
grep -r "sort.Strings" .
grep -r "SetOwnerReferences" .

Length of output: 1180

components/operator/internal/resources/brokerconsumers/controller.go (1)

36-79: The Reconcile function in brokerconsumers/controller.go demonstrates a comprehensive approach to managing BrokerTopic objects based on BrokerConsumer specifications. It's important to ensure that the error handling for creating and patching BrokerTopic objects is robust, especially in a Kubernetes environment where transient errors can occur. Consider implementing retries or leveraging Kubernetes' built-in retry mechanism for operations that might fail due to temporary issues.

components/operator/internal/resources/webhooks/controller.go (1)

77-89: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [22-99]

The updates in webhooks/controller.go to rename the package and variables from brokertopicconsumers to brokerconsumers are consistent and correctly implemented. The addition of v1beta1.BrokerConsumer in the init function is a good practice for ensuring that the controller is aware of the resources it needs to manage. Ensure that all references to the old package and variable names have been updated across the entire codebase to maintain consistency.

components/operator/internal/resources/orchestrations/controller.go (1)

85-92: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [22-101]

The changes in orchestrations/controller.go to rename the package and update variable names, as well as replacing references from BrokerTopicConsumer to BrokerConsumer, are correctly implemented. This aligns with the PR's objective to consolidate the handling of broker consumers. Ensure that the rest of the codebase reflects these changes consistently to avoid any discrepancies.

components/operator/internal/tests/orchestration_controller_test.go (1)

118-121: The update to the test case description and resource loading in orchestration_controller_test.go to create a BrokerConsumer object is accurate and reflects the changes made in the main code. This ensures that the tests remain relevant and provide coverage for the new functionality. Good practice to keep the tests aligned with the code changes.

components/operator/PROJECT (1)

175-180: The addition of the BrokerConsumer API definition in the PROJECT file is correctly implemented and aligns with the PR's objectives to introduce a new model for managing broker consumers. This change is essential for the Kubernetes CRD scaffolding and ensures that the new BrokerConsumer type is recognized by the Kubernetes API. Good practice to keep the project configuration up to date with the new API definitions.

components/operator/internal/resources/webhooks/deployment.go (3)

67-67: The update to the createAPIDeployment function, including the change to use a single BrokerConsumer and the logic for constructing the KAFKA_TOPICS environment variable, aligns with the PR's objectives. Ensure that all calls to this function have been updated to match the new signature and that the KAFKA_TOPICS environment variable is constructed as intended across different scenarios.

Also applies to: 87-88


113-113: The changes in the createWorkerDeployment function, including the parameter update to use a single BrokerConsumer and the updated logic for the KAFKA_TOPICS environment variable, are consistent with the PR's goals. Verify that all references to this function have been correctly updated and that the KAFKA_TOPICS environment variable is accurately constructed.

Also applies to: 126-127

Verification successful

To complete the verification, we need to examine how the KAFKA_TOPICS environment variable is constructed within the createWorkerDeployment function. This will ensure that the changes are consistent with the PR's goals.


The verification process confirms that the createWorkerDeployment function has been updated as described, including the parameter update and the logic for constructing the KAFKA_TOPICS environment variable. The function's usage in the codebase aligns with the changes, and the KAFKA_TOPICS environment variable is accurately constructed based on the BrokerConsumer specification.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Additional verification for createWorkerDeployment function usage and KAFKA_TOPICS construction.
ast-grep --lang go --pattern $'createWorkerDeployment($_, $_, $_, $_, $_, $_)'

Length of output: 246



Script:

#!/bin/bash
# Examine the construction of KAFKA_TOPICS within createWorkerDeployment
rg "KAFKA_TOPICS" ./components/operator/internal/resources/webhooks/deployment.go

Length of output: 306


148-156: The updates to createSingleDeployment and createDualDeployment functions, adapting them to the new BrokerConsumer model, are in line with the PR's objectives. Ensure that these functions are correctly utilized throughout the codebase with the updated signatures.

Verification successful

The verification confirms that createSingleDeployment and createDualDeployment functions are utilized in the codebase, specifically within controller.go. This aligns with the initial review, approving the updates and suggesting ensuring their correct application. Further analysis of their usage context (e.g., parameter correctness, logic flow) wasn't within the scope of this verification but is recommended as a best practice.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verification for createSingleDeployment and createDualDeployment function usage.
ast-grep --lang go --pattern $'createSingleDeployment($_, $_, $_, $_, $_, $_)'
ast-grep --lang go --pattern $'createDualDeployment($_, $_, $_, $_, $_, $_)'

Length of output: 493

components/operator/Earthfile (1)

37-37: The update of controller-gen to v0.14.0 aligns with the PR's objectives to modernize the project's dependencies. Ensure that the new version does not introduce any breaking changes or unexpected behavior in the generation of CRDs, RBAC, and Webhooks.

components/operator/Makefile (1)

161-161: The update of CONTROLLER_TOOLS_VERSION to v0.14.0 in the Makefile is consistent with the project's objectives to modernize dependencies. Ensure that the new version does not introduce any breaking changes or unexpected behavior in code generation tasks.

components/operator/docs/crd.md (3)

16-16: The addition of BrokerConsumer to the list of Resource Types is noted. Ensure that the corresponding section below provides comprehensive details about this new entity, including fields, descriptions, and any default values or validation rules.


243-277: The documentation for BrokerConsumer and BrokerConsumerSpec has been added correctly. It follows the established format and provides clear information about the fields, their types, and descriptions. This addition aligns with the PR's objective to introduce the BrokerConsumer model.


1084-1084: The inclusion of BrokerConsumerSpec in the StackDependency section indicates that BrokerConsumer entities can specify dependencies on stacks. This is a crucial detail for understanding how BrokerConsumer entities interact with other components in the system.

components/operator/api/formance.com/v1beta1/zz_generated.deepcopy.go (4)

476-501: The deepcopy functions for BrokerConsumer are correctly implemented and follow the expected pattern for autogenerated deepcopy functions. These are crucial for the proper handling of Kubernetes objects.


503-532: The deepcopy functions for BrokerConsumerList are correctly implemented, ensuring that each BrokerConsumer in the list is deep copied. This is essential for managing lists of Kubernetes objects.


535-553: The deepcopy functions for BrokerConsumerSpec are correctly implemented, ensuring that specifications of BrokerConsumer objects, including slices and simple fields, are correctly copied.


556-569: The deepcopy functions for BrokerConsumerStatus are correctly implemented, ensuring that the status of BrokerConsumer objects, including the CommonStatus field, is properly copied.

@@ -47,7 +47,7 @@ func createAuthClient(ctx Context, stack *v1beta1.Stack, orchestration *v1beta1.

func createDeployment(ctx Context, stack *v1beta1.Stack, orchestration *v1beta1.Orchestration,
database *v1beta1.Database, client *v1beta1.AuthClient,
consumers []*v1beta1.BrokerTopicConsumer, image string) error {
consumer *v1beta1.BrokerConsumer, image string) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Tip

Codebase Verification

The verification process revealed that the createDeployment function's signature change has been correctly applied in several parts of the codebase, specifically within reconciliations/controller.go, auths/controller.go, and gateways/controller.go. However, there is an oversight in orchestrations/controller.go, where the function is called with the old signature. This inconsistency needs to be addressed to ensure the application's stability and to fully align with the PR's objectives of streamlining broker consumer management.

Analysis chain

The changes in the createDeployment function, including the parameter change from multiple BrokerTopicConsumers to a single BrokerConsumer and the updated logic for constructing the TOPICS environment variable, align well with the PR's objectives to streamline broker consumer management. Ensure that all calls to this function have been updated to match the new signature and that the TOPICS environment variable is constructed as intended across different scenarios.

Also applies to: 98-99

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Search to find files that import the orchestrations package. Expecting list of dependent files.
rg -C3 --type go $'import .*orchestrations'
# Search old signature to find omissions. Expecting no results.
ast-grep --lang go --pattern $'createDeployment($_, $_, $_, $_, $_, $_, $_)'
# Search new signature to validate usage. Expecting list of locations where the new signature is used.
ast-grep --lang go --pattern $'createDeployment($_, $_, $_, $_, $_, $_)'

Length of output: 836

@gfyrag gfyrag force-pushed the feat/operator-broker-consumer branch from d523350 to 0cb5b62 Compare April 2, 2024 07:32
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Status

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 01c96c3 and 0cb5b62.
Files ignored due to path filters (72)
  • components/operator/config/crd/bases/auth.components.formance.com_clients.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/auth.components.formance.com_scopes.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/components.formance.com_auths.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/components.formance.com_controls.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/components.formance.com_counterparties.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/components.formance.com_ledgers.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/components.formance.com_orchestrations.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/components.formance.com_payments.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/components.formance.com_searches.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/components.formance.com_searchingesters.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/components.formance.com_wallets.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/components.formance.com_webhooks.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_authclients.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_auths.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_benthos.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_benthosstreams.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_brokerconsumers.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_brokertopicconsumers.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_brokertopics.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_databases.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_gatewayhttpapis.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_gateways.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_ledgers.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_orchestrations.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_payments.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_reconciliations.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_resourcereferences.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_searches.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_settings.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_stacks.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_stargates.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_versions.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_wallets.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/formance.com_webhooks.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/stack.formance.com_configurations.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/stack.formance.com_licenses.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/stack.formance.com_migrations.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/stack.formance.com_stacks.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/bases/stack.formance.com_versions.yaml is excluded by !**/*.yaml
  • components/operator/config/crd/kustomization.yaml is excluded by !**/*.yaml
  • components/operator/config/rbac/formance.com_brokerconsumer_editor_role.yaml is excluded by !**/*.yaml
  • components/operator/config/rbac/formance.com_brokerconsumer_viewer_role.yaml is excluded by !**/*.yaml
  • components/operator/config/rbac/role.yaml is excluded by !**/*.yaml
  • components/operator/config/samples/formance.com_v1beta1_brokerconsumer.yaml is excluded by !**/*.yaml
  • components/operator/config/samples/kustomization.yaml is excluded by !**/*.yaml
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_authclients.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_auths.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_benthos.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_benthosstreams.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_brokerconsumers.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_brokertopicconsumers.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_brokertopics.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_configurations.stack.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_databases.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_gatewayhttpapis.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_gateways.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_ledgers.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_migrations.stack.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_orchestrations.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_payments.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_reconciliations.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_resourcereferences.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_searches.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_settings.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_stacks.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_stacks.stack.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_stargates.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_versions.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_versions.stack.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_wallets.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/apiextensions.k8s.io_v1_customresourcedefinition_webhooks.formance.com.yaml is excluded by !**/*.yaml, !**/gen/**
  • components/operator/helm/templates/gen/rbac.authorization.k8s.io_v1_clusterrole_manager-role.yaml is excluded by !**/*.yaml, !**/gen/**
Files selected for processing (15)
  • components/operator/Earthfile (1 hunks)
  • components/operator/Makefile (1 hunks)
  • components/operator/PROJECT (1 hunks)
  • components/operator/api/formance.com/v1beta1/brokerconsumer_types.go (1 hunks)
  • components/operator/api/formance.com/v1beta1/zz_generated.deepcopy.go (1 hunks)
  • components/operator/docs/crd.md (4 hunks)
  • components/operator/internal/resources/brokerconsumers/controller.go (1 hunks)
  • components/operator/internal/resources/brokerconsumers/create.go (1 hunks)
  • components/operator/internal/resources/brokertopicconsumers/controller.go (1 hunks)
  • components/operator/internal/resources/orchestrations/controller.go (4 hunks)
  • components/operator/internal/resources/orchestrations/deployments.go (2 hunks)
  • components/operator/internal/resources/webhooks/controller.go (4 hunks)
  • components/operator/internal/resources/webhooks/deployment.go (6 hunks)
  • components/operator/internal/tests/brokerconsumer_controller_test.go (3 hunks)
  • components/operator/internal/tests/orchestration_controller_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (13)
  • components/operator/Earthfile
  • components/operator/Makefile
  • components/operator/PROJECT
  • components/operator/api/formance.com/v1beta1/brokerconsumer_types.go
  • components/operator/api/formance.com/v1beta1/zz_generated.deepcopy.go
  • components/operator/internal/resources/brokerconsumers/controller.go
  • components/operator/internal/resources/brokerconsumers/create.go
  • components/operator/internal/resources/orchestrations/controller.go
  • components/operator/internal/resources/orchestrations/deployments.go
  • components/operator/internal/resources/webhooks/controller.go
  • components/operator/internal/resources/webhooks/deployment.go
  • components/operator/internal/tests/brokerconsumer_controller_test.go
  • components/operator/internal/tests/orchestration_controller_test.go
Additional comments not posted (5)
components/operator/internal/resources/brokertopicconsumers/controller.go (2)

33-69: The Reconcile function has been refactored to streamline the management of broker topics and consumers. A few observations and suggestions:

  1. Error Handling and Logging: When listing broker topic consumers (lines 36-40), consider adding logging before returning the error. This can help with debugging and understanding the context in which errors occur.

  2. Efficiency in Service Management: The loop for appending services to t.Spec.Services (lines 50-60) could potentially be optimized. If the list of services grows large, this approach might become inefficient due to the nested loops. Consider using a map or set data structure to track existing services for faster lookups.

  3. Owner References: Setting owner references (line 64) is crucial for Kubernetes garbage collection. Ensure that the owner references set here correctly reflect the desired ownership hierarchy, especially in the context of the new BrokerConsumer model.

  4. Error Handling Post-CreateOrUpdate: After the CreateOrUpdate call (lines 43-67), the error is returned directly (line 68). It might be beneficial to add additional context to the error or perform specific error handling based on the error type.

Overall, the changes align with the PR's objectives to simplify and consolidate the management of broker consumers. However, considering the above points could further enhance the code's maintainability and performance.


73-75: The init function setup includes a simple index for BrokerTopicConsumer based on queriedBy. This is a good practice for optimizing lookups. However, ensure that the queriedBy field is always populated and unique as expected, to prevent any potential issues with the indexing mechanism.

components/operator/docs/crd.md (3)

16-16: The addition of BrokerConsumer to the Resource Types list is noted. Ensure that the corresponding detailed documentation for BrokerConsumer is complete and accurate further down in the document.


243-258: The documentation for BrokerConsumer is well-structured, following the expected format for API schema definitions. However, ensure that the fields described under BrokerConsumerSpec are comprehensive and accurately reflect the properties of the BrokerConsumer model.


261-277: The BrokerConsumerSpec section is correctly documented, providing clear information on the desired state of BrokerConsumer. It's important to verify that all fields (stack, services, queriedBy) are fully described and match the implementation in the codebase.

@gfyrag gfyrag added this pull request to the merge queue Apr 3, 2024
Merged via the queue into main with commit 270eb5a Apr 3, 2024
10 checks passed
@gfyrag gfyrag deleted the feat/operator-broker-consumer branch April 3, 2024 15:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants