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(backup): separate backup settings from default settings #2235

Merged
merged 1 commit into from
Jan 7, 2025

Conversation

mantissahz
Copy link
Contributor

@mantissahz mantissahz commented Dec 30, 2024

Which issue(s) this PR fixes:

Issue # longhorn/longhorn#5411, longhorn/longhorn#10089

What this PR does / why we need it:

Separate the default backup related settings from default settings into a new yaml file default-backupstore-setting.yaml

Introduce a new category defaultBackupStoreSettings and a new ConfigMap longhorn-default-backupstore-settings to control the default backupstore related settings with Helm/Kubectl.

Special notes for your reviewer:

Additional documentation or context

Summary by CodeRabbit

  • Chores
    • Enhanced test settings configuration with new constants.
    • Updated method signatures to improve configuration map handling.
    • Added more flexible parameters for configuration management in the test environment.
    • Improved error handling for invalid settings in the test suite.

@mantissahz mantissahz self-assigned this Dec 30, 2024
@mantissahz mantissahz requested a review from a team as a code owner December 30, 2024 09:34
Copy link

coderabbitai bot commented Dec 30, 2024

Walkthrough

The pull request modifies the test_settings.py file in the Longhorn integration tests, introducing new constants and updating function signatures to improve configuration management. The changes enhance the flexibility of settings management by adding constants for configuration maps and updating functions to accept additional parameters, allowing for more dynamic handling of configuration maps and error management in the testing framework.

Changes

File Change Summary
manager/integration/tests/test_settings.py - Added constants: SETTING_BACKUP_TARGET_CREDENTIAL_SECRET, SETTING_BACKUPSTORE_POLL_INTERVAL, DEFAULT_SETTING_CONFIGMAP_NAME, DEFAULT_RESOURCE_CONFIGMAP_NAME, DEFAULT_SETTING_YAML_NAME, DEFAULT_RESOURCE_YAML_NAME.
- Updated method signatures for config_map_with_value(), init_longhorn_default_setting_configmap(), and update_settings_via_configmap() to include optional configmap_name and data_yaml_name parameters.
- Adjusted logic for initializing and updating settings based on the existence of the longhorn-default-resource config map.
- Refined error handling in test_setting_update_with_invalid_value_via_configmap to accommodate new configuration logic.

Possibly related PRs

Suggested reviewers

  • COLDTURNIP
  • innobead
  • chriscchien
  • yangchiu
  • roger-ryao

Poem

🐰 In the land of settings, constants grow,
With maps and values, we put on a show!
Flexible updates, tests in delight,
Longhorn's new dance takes flight tonight!
Hopping through code, with joy we bestow! 🚀


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 59f5e72 and c6faba8.

📒 Files selected for processing (1)
  • manager/integration/tests/test_settings.py (8 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build images
  • GitHub Check: Summary
🔇 Additional comments (6)
manager/integration/tests/test_settings.py (6)

34-35: LGTM! Constants align with PR objective.

The new constants are well-named and support the separation of backup settings from default settings.

Also applies to: 60-63


Line range hint 1045-1058: LGTM! Function signature update maintains backward compatibility.

The addition of the data_yaml_name parameter with a default value ensures existing code continues to work while enabling flexibility for different YAML files.


1086-1095: LGTM! Function signature update supports config map separation.

The addition of configmap_name and data_yaml_name parameters enables initialization of different config maps while maintaining backward compatibility through default values.


1100-1126: LGTM! Reset logic handles both default and backup settings.

The reset_default_settings function now correctly handles both default settings and backup settings based on the config map name.


1190-1199: LGTM! Config map selection logic is robust.

The code correctly checks for the existence of the backup config map and falls back to the default config map if needed.


Line range hint 1251-1299: LGTM! Test case handles both config maps.

The test case has been updated to handle both default and backup settings while maintaining the original test objectives.


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

Copy link

@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

🧹 Nitpick comments (3)
manager/integration/tests/test_settings.py (3)

Line range hint 1045-1058: Improve flexibility of config_map_with_value.
The new data_yaml_name parameter increases versatility by letting callers specify different target YAML files. Consider adding a short docstring, explaining usage for debugging and maintainability.


1100-1126: Enhanced update_settings_via_configmap to support backupstore defaults.
Passing configmap_name and data_yaml_name at runtime provides better extensibility. The reset logic is reasonable, but ensure the finalizer’s usage does not inadvertently overwrite custom user settings in certain test flows.


1190-1216: Conditional logic for selecting backupstore configmap.
The approach eliminates confusion if multiple configmaps exist. Confirm proper fallback when the backupstore configmap is absent. Consider logging actions or reason for fallback to help debugging in CI or support scenarios.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c1c04a5 and 6f9c0fc.

📒 Files selected for processing (1)
  • manager/integration/tests/test_settings.py (8 hunks)
🔇 Additional comments (4)
manager/integration/tests/test_settings.py (4)

34-35: New constants for backup store credentials and poll interval.
These constants look correct and will help decouple backup-related settings from the broader default settings.


60-64: Separation of default settings and backupstore settings constants.
Defining dedicated ConfigMap names and YAML filenames for backupstore and default settings is a good move toward clarity and modularity.


1086-1095: Optional parameters introduced for configmap initialization.
Utilizing default values for configmap_name and data_yaml_name is beneficial. Ensure that callers needing backupstore-specific logic are consistently passing in the right arguments.


Line range hint 1252-1301: Handling invalid settings with backupstore configmap.
The logic correctly checks for the backupstore configmap and resets invalid settings when volumes are attached. Ensure that ignoring invalid updates does not mask critical configuration issues for other settings.

Copy link

@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

🧹 Nitpick comments (1)
manager/integration/tests/test_settings.py (1)

Line range hint 1045-1058: Consider adding type hints for better maintainability.

The function signatures have been updated correctly to support both default and backup store settings. Consider adding type hints to improve code maintainability and IDE support.

Example with type hints:

-def config_map_with_value(configmap_name, setting_names, setting_values, data_yaml_name="default-setting.yaml"):
+def config_map_with_value(configmap_name: str, setting_names: list[str], setting_values: list[str], data_yaml_name: str = "default-setting.yaml") -> dict:

Also applies to: 1086-1126

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6f9c0fc and 07ef4b2.

📒 Files selected for processing (1)
  • manager/integration/tests/test_settings.py (8 hunks)
🔇 Additional comments (2)
manager/integration/tests/test_settings.py (2)

60-63: LGTM! Constants are well-defined.

The new constants clearly separate backup store settings from default settings, aligning with the PR objectives.


Line range hint 1190-1301: LGTM! Test cases handle both configmap scenarios.

The test cases have been updated to:

  1. Check for the existence of the backup store configmap
  2. Use the appropriate configmap based on availability
  3. Maintain proper cleanup through finalizers

@mantissahz mantissahz force-pushed the issue10089 branch 3 times, most recently from dd5bbb5 to f27f73e Compare January 6, 2025 00:43
Copy link

@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

🧹 Nitpick comments (2)
manager/integration/tests/test_settings.py (2)

1100-1126: Consider enhancing error handling for ConfigMap operations.

While the function's signature update is good, consider adding error handling for ConfigMap operations to gracefully handle potential API failures.

 def update_settings_via_configmap(core_api, client, setting_names, setting_values, request,
                                   configmap_name=DEFAULT_SETTING_CONFIGMAP_NAME,
                                   data_yaml_name=DEFAULT_SETTING_YAML_NAME):
+    try:
         configmap_body = config_map_with_value(configmap_name,
                                                setting_names,
                                                setting_values,
                                                data_yaml_name)
         core_api.patch_namespaced_config_map(name=configmap_name,
                                              namespace='longhorn-system',
                                              body=configmap_body)
+    except Exception as e:
+        print(f"Failed to update ConfigMap {configmap_name}: {str(e)}")
+        raise

Line range hint 1251-1299: Consider extracting ConfigMap existence check into a helper function.

The ConfigMap existence check is duplicated. Consider extracting it into a reusable helper function.

+def get_backup_configmap_details(core_api):
+    """Helper function to determine which ConfigMap to use for backup settings."""
+    lh_cms = core_api.list_namespaced_config_map(namespace='longhorn-system')
+    cm_names = [config_map.metadata.name for config_map in lh_cms.items]
+    if DEFAULT_RESOURCE_CONFIGMAP_NAME in cm_names:
+        return DEFAULT_RESOURCE_CONFIGMAP_NAME, DEFAULT_RESOURCE_YAML_NAME, True
+    return DEFAULT_SETTING_CONFIGMAP_NAME, DEFAULT_SETTING_YAML_NAME, False

 def test_setting_update_with_invalid_value_via_configmap(core_api, request):
-    backup_cm_created = False
-    lh_cms = core_api.list_namespaced_config_map(namespace='longhorn-system')
-    cm_names = [config_map.metadata.name for config_map in lh_cms.items]
-    if DEFAULT_RESOURCE_CONFIGMAP_NAME in cm_names:
-        backup_cm_created = True
-        bt_config_map_name = DEFAULT_RESOURCE_CONFIGMAP_NAME
-        bt_data_yaml_name = DEFAULT_RESOURCE_YAML_NAME
+    bt_config_map_name, bt_data_yaml_name, backup_cm_created = get_backup_configmap_details(core_api)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dd5bbb5 and f27f73e.

📒 Files selected for processing (1)
  • manager/integration/tests/test_settings.py (8 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build images
  • GitHub Check: Summary
🔇 Additional comments (4)
manager/integration/tests/test_settings.py (4)

60-63: LGTM! Well-defined constants for ConfigMap management.

The constants follow proper naming conventions and clearly define the ConfigMap and YAML file names used for settings management.


Line range hint 1045-1058: LGTM! Well-structured function with backward compatibility.

The function has been enhanced to support configurable YAML file names while maintaining backward compatibility through default parameters.


1086-1095: LGTM! Improved initialization function with configurable parameters.

The function now supports customizable ConfigMap and YAML file names, aligning with the PR's objective of separating settings.


1190-1198: LGTM! Good implementation of ConfigMap selection logic.

The code appropriately checks for the existence of the default resource ConfigMap and selects the correct ConfigMap and YAML names.

Copy link

@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

🧹 Nitpick comments (2)
manager/integration/tests/test_settings.py (2)

1100-1126: Consider adding error handling for ConfigMap operations.

While the function correctly handles different ConfigMap scenarios, it would be beneficial to add error handling for ConfigMap operations to gracefully handle failures.

 def update_settings_via_configmap(core_api, client, setting_names, setting_values, request,
                                   configmap_name=DEFAULT_SETTING_CONFIGMAP_NAME,
                                   data_yaml_name=DEFAULT_SETTING_YAML_NAME):
+    try:
         configmap_body = config_map_with_value(configmap_name,
                                                setting_names,
                                                setting_values,
                                                data_yaml_name)
         core_api.patch_namespaced_config_map(name=configmap_name,
                                              namespace='longhorn-system',
                                              body=configmap_body)
+    except Exception as e:
+        print(f"Failed to update ConfigMap {configmap_name}: {str(e)}")
+        raise

Line range hint 1251-1299: Consider adding test coverage for backup settings validation.

The test case handles the backup ConfigMap scenario, but it would be beneficial to add specific test cases for validating backup-related settings.

Consider adding test cases to validate:

  1. Invalid backup target credentials
  2. Invalid backup store poll interval values
  3. Interaction between backup settings when updated simultaneously
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f27f73e and 59f5e72.

📒 Files selected for processing (1)
  • manager/integration/tests/test_settings.py (8 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build images
  • GitHub Check: Summary
🔇 Additional comments (5)
manager/integration/tests/test_settings.py (5)

34-35: LGTM!

The new imports for backup-related settings align with the PR objective of separating backup settings from default settings.


60-63: LGTM!

The new constants are well-named and align with the PR objective of separating backup settings into a separate ConfigMap.


Line range hint 1045-1058: LGTM!

The function modification maintains backward compatibility while supporting the new ConfigMap structure through the optional data_yaml_name parameter.


1086-1095: LGTM!

The function now supports configurable ConfigMap and YAML names, aligning with the separation of backup settings.


1190-1215: LGTM!

The test case correctly handles the presence of both ConfigMap types and uses the appropriate one for backup settings.

Separate the default backup related settings from default settings
into a new yaml file `default-resource.yaml`

Introduce a new category `defaultBackupStore` and a new
ConfigMap `longhorn-default-resouce` to control
the default backupstore related settings with Helm/Kubectl.

ref: longhorn/longhorn 5411, 10089

Signed-off-by: James Lu <jamesluhz@gmail.com>
@mantissahz
Copy link
Contributor Author

This PR will fix the failed test cases https://ci.longhorn.io/job/public/job/v1.8.x/job/v1.8.x-longhorn-tests-sles-arm64/17/testReport/

Hi @chriscchien, @roger-ryao @yangchiu,
Please review this PR when you are available. Thanks.

Copy link
Member

@yangchiu yangchiu left a comment

Choose a reason for hiding this comment

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

LGTM

@yangchiu yangchiu merged commit d4bb4e9 into longhorn:master Jan 7, 2025
9 checks passed
@yangchiu
Copy link
Member

yangchiu commented Jan 7, 2025

@mergify backport v1.8.x

Copy link

mergify bot commented Jan 7, 2025

backport v1.8.x

✅ Backports have been created

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.

2 participants