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

fix(operator): only delete ledger deployment on strategy change #1639

Conversation

Dav-14
Copy link
Contributor

@Dav-14 Dav-14 commented Aug 6, 2024

  • feat: add method lock/unlock on stack
  • feat: delete deployment only on strategy update

@Dav-14 Dav-14 requested a review from a team as a code owner August 6, 2024 14:44
Copy link
Contributor

coderabbitai bot commented Aug 6, 2024

Warning

Rate limit exceeded

@Dav-14 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 13 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

Commits

Files that changed from the base of the PR and between ff4fbcd and 82a99bf.

Walkthrough

The recent updates enhance the functionality and structure of the Stack and Ledger components. Key modifications include introducing locking mechanisms in the Stack struct for improved state control and the addition of deployment strategy handling in the Ledger component. These enhancements streamline operations, increase clarity, and bolster the system's robustness in managing concurrent tasks and various deployment scenarios.

Changes

Files Change Summary
components/operator/api/.../stack_types.go Modified Stack struct by moving and redefining GetConditions, and introducing Lock and UnLock methods for managing annotations and state control.
components/operator/internal/resources/.../deployments.go Added constants for deployment strategies, created hasDeploymentStrategyChanged function, and adjusted installLedger for improved decision flow and error handling.
components/operator/internal/tests/.../ledger_controller_test.go Introduced new test cases to verify updates to ledger deployment strategies and resource management.
components/operator/internal/tests/.../stack_controller_test.go Updated test logic to utilize the locking mechanism instead of annotations, ensuring a clearer sequence of operations for testing.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant StackController
    participant LedgerController

    User->>StackController: Request stack operation
    StackController->>Stack: Lock()
    Stack->>Stack: Update annotations
    StackController->>Stack: Unlock()
    User->>LedgerController: Request ledger operation
    LedgerController->>Ledger: Check deployment strategy
    Ledger->>Ledger: Update status
Loading

🐇 In fields of code, I hop with glee,
New locks and strategies, oh what a sight to see!
Deployments dance, conditions align,
With every change, our system will shine!
So let’s rejoice, with carrots we cheer,
For improvements made, bring the future near! 🥕


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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

CodeRabbit Configuration 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/schema.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.

@Dav-14 Dav-14 changed the title feat(operator): only delete ledger deployment on strategy change fix(operator): only delete ledger deployment on strategy change Aug 6, 2024
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

Outside diff range, codebase verification and nitpick comments (1)
components/operator/internal/resources/ledgers/deployments.go (1)

Line range hint 59-96: Ensure proper error handling in deferred function.

While the deferred function updates the ledger conditions, it does not handle potential errors that might occur during this operation. Consider adding error handling to ensure robustness.

-	defer func() {
-		ledger.GetConditions().AppendOrReplace(*cond, predicate)
-	}()
+	defer func() {
+		if err := ledger.GetConditions().AppendOrReplace(*cond, predicate); err != nil {
+			ctx.Logger().Error(err, "Failed to update ledger conditions")
+		}
+	}()
Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 8436bef and a135a51.

Files selected for processing (4)
  • components/operator/api/formance.com/v1beta1/stack_types.go (2 hunks)
  • components/operator/internal/resources/ledgers/deployments.go (3 hunks)
  • components/operator/internal/tests/ledger_controller_test.go (2 hunks)
  • components/operator/internal/tests/stack_controller_test.go (2 hunks)
Additional comments not posted (9)
components/operator/api/formance.com/v1beta1/stack_types.go (3)

103-105: Relocation of GetConditions method is acceptable.

The method's implementation remains unchanged, and its new location does not affect functionality.


111-116: Implementation of Lock method is correct.

The method correctly initializes the Annotations map if it is nil and sets the SkipLabel entry to "true".


118-119: Implementation of UnLock method is correct.

The method correctly removes the SkipLabel entry from the Annotations map.

components/operator/internal/tests/stack_controller_test.go (2)

187-187: Usage of stack.Lock() in BeforeEach block is correct.

The call to stack.Lock() correctly replaces the previous annotation setup, aligning with the new locking mechanism.


227-227: Usage of stack.UnLock() in JustBeforeEach block is correct.

The call to stack.UnLock() correctly precedes the patch operation, ensuring proper sequence of operations.

components/operator/internal/tests/ledger_controller_test.go (2)

209-215: New test case for strategy condition update is correct.

The test case correctly verifies that the strategy condition is updated by checking the ledger.Status.Conditions.


216-222: New test case for deployment deletion is correct.

The test case correctly verifies the deletion of a deployment by ensuring that a specific resource cannot be successfully retrieved after the deletion operation.

components/operator/internal/resources/ledgers/deployments.go (2)

34-56: LGTM!

The function hasDeploymentStrategyChanged is well-structured and logically sound. It effectively checks the deployment strategy and handles the uninstallation of the ledger based on the strategy.


Line range hint 59-96: LGTM!

The function installLedger is well-structured and logically sound. It effectively installs the ledger based on the deployment strategy and handles errors appropriately.

@Dav-14 Dav-14 force-pushed the feat/eng-1259-fixoperator-no-drop-deployments-when-ledger-is-update branch from 00cf878 to f6c7f39 Compare August 6, 2024 15:20
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 details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a135a51 and f6c7f39.

Files selected for processing (4)
  • components/operator/api/formance.com/v1beta1/stack_types.go (2 hunks)
  • components/operator/internal/resources/ledgers/deployments.go (3 hunks)
  • components/operator/internal/tests/ledger_controller_test.go (3 hunks)
  • components/operator/internal/tests/stack_controller_test.go (2 hunks)
Files skipped from review as they are similar to previous changes (3)
  • components/operator/api/formance.com/v1beta1/stack_types.go
  • components/operator/internal/resources/ledgers/deployments.go
  • components/operator/internal/tests/ledger_controller_test.go
Additional comments not posted (2)
components/operator/internal/tests/stack_controller_test.go (2)

187-187: Good use of locking mechanism.

The stack.Lock() call in the BeforeEach block ensures that the stack is properly locked before performing any operations, enhancing the safety and reliability of concurrent access or state changes.


227-227: Good use of unlocking mechanism before patching.

The stack.UnLock() call before patching the stack ensures that the stack is properly unlocked, aligning with the intended use of locking mechanisms to manage concurrent access or state changes.

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 details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between f6c7f39 and e510f25.

Files selected for processing (1)
  • components/operator/internal/resources/ledgers/deployments.go (3 hunks)
Additional comments not posted (3)
components/operator/internal/resources/ledgers/deployments.go (3)

28-32: LGTM!

The new constants for deployment strategy conditions and reasons improve code readability and maintainability.


Line range hint 63-99:
LGTM! But verify the function usage in the codebase.

The function implementation is approved.

However, ensure that all function calls to installLedger are correctly integrated.


34-60: LGTM! But verify the function usage in the codebase.

The function implementation is approved.

However, ensure that all function calls to hasDeploymentStrategyChanged are correctly integrated.

Verification successful

The function hasDeploymentStrategyChanged is correctly integrated within the file components/operator/internal/resources/ledgers/deployments.go.

  • The function is defined and used exclusively within this file, indicating proper encapsulation and usage.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `hasDeploymentStrategyChanged` are correctly integrated.

# Test: Search for the function usage. Expect: Correct integration of the new function.
rg --type go -A 5 $'hasDeploymentStrategyChanged'

Length of output: 1363


Script:

#!/bin/bash
# Description: Verify all function calls to `hasDeploymentStrategyChanged` are correctly integrated across the entire codebase.

# Test: Search for the function usage across the codebase. Expect: Correct integration of the new function.
rg --type go 'hasDeploymentStrategyChanged'

Length of output: 422

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: 3

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between e510f25 and bdbaab3.

Files selected for processing (2)
  • components/operator/internal/resources/ledgers/deployments.go (2 hunks)
  • components/operator/internal/tests/ledger_controller_test.go (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • components/operator/internal/tests/ledger_controller_test.go
Additional comments not posted (1)
components/operator/internal/resources/ledgers/deployments.go (1)

96-97: Add a default case in the switch statement.

The switch statement for deploymentStrategySettings could benefit from a default case to handle unexpected values.

switch deploymentStrategySettings {
case v1beta1.DeploymentStrategySingle:
	return installLedgerSingleInstance(ctx, stack, ledger, database, image, isV2)
case v1beta1.DeploymentStrategyMonoWriterMultipleReader:
	return installLedgerMonoWriterMultipleReader(ctx, stack, ledger, database, image, isV2)
default:
	return fmt.Errorf("unknown deployment strategy %s", deploymentStrategySettings)
}

Likely invalid or redundant comment.

Comment on lines +87 to +88
if err = hasDeploymentStrategyChanged(ctx, stack, ledger, deploymentStrategySettings); err != nil {
return
Copy link
Contributor

Choose a reason for hiding this comment

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

Improve error handling for hasDeploymentStrategyChanged.

The error handling for hasDeploymentStrategyChanged could be more descriptive to provide better context in case of failure.

if err = hasDeploymentStrategyChanged(ctx, stack, ledger, deploymentStrategySettings); err != nil {
	return fmt.Errorf("failed to check if deployment strategy changed: %w", err)
}
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if err = hasDeploymentStrategyChanged(ctx, stack, ledger, deploymentStrategySettings); err != nil {
return
if err = hasDeploymentStrategyChanged(ctx, stack, ledger, deploymentStrategySettings); err != nil {
return fmt.Errorf("failed to check if deployment strategy changed: %w", err)

@Dav-14 Dav-14 force-pushed the feat/eng-1259-fixoperator-no-drop-deployments-when-ledger-is-update branch from bdbaab3 to ff4fbcd Compare August 6, 2024 19:15
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 details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between bdbaab3 and ff4fbcd.

Files selected for processing (2)
  • components/operator/internal/resources/ledgers/deployments.go (2 hunks)
  • components/operator/internal/tests/ledger_controller_test.go (3 hunks)
Files skipped from review as they are similar to previous changes (2)
  • components/operator/internal/resources/ledgers/deployments.go
  • components/operator/internal/tests/ledger_controller_test.go

@Dav-14 Dav-14 added this pull request to the merge queue Aug 7, 2024
Merged via the queue into main with commit a835b5d Aug 7, 2024
13 checks passed
@Dav-14 Dav-14 deleted the feat/eng-1259-fixoperator-no-drop-deployments-when-ledger-is-update branch August 7, 2024 08:57
Dav-14 added a commit that referenced this pull request Aug 21, 2024
@Dav-14 Dav-14 mentioned this pull request Aug 22, 2024
Dav-14 added a commit that referenced this pull request Aug 22, 2024
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.

3 participants