refactor: improve maintainability (issue #58)#59
Merged
Conversation
added 6 commits
March 6, 2026 13:39
Create src/test_utils.rs module with common test fixtures for Service and ServiceSpec creation. This reduces code duplication across controller/mod.rs and controller/nodes.rs test modules. No functional changes - behavior preserved.
Rename all annotation constants to use consistent _ANNOTATION suffix instead of mixing _LABEL_NAME, _ANN_NAME, and bare names. Changes: - LB_NAME_LABEL_NAME -> LB_NAME_ANNOTATION - LB_NODE_SELECTOR -> LB_NODE_SELECTOR_ANNOTATION - LB_NODE_IP_LABEL_NAME -> LB_NODE_IP_ANNOTATION - LB_CHECK_INTERVAL_ANN_NAME -> LB_CHECK_INTERVAL_ANNOTATION - LB_TIMEOUT_ANN_NAME -> LB_TIMEOUT_ANNOTATION - LB_RETRIES_ANN_NAME -> LB_RETRIES_ANNOTATION - LB_PROXY_MODE_LABEL_NAME -> LB_PROXY_MODE_ANNOTATION - LB_NETWORK_LABEL_NAME -> LB_NETWORK_ANNOTATION - LB_PRIVATE_IP_LABEL_NAME -> LB_PRIVATE_IP_ANNOTATION - LB_LOCATION_LABEL_NAME -> LB_LOCATION_ANNOTATION - LB_ALGORITHM_LABEL_NAME -> LB_ALGORITHM_ANNOTATION - LB_BALANCER_TYPE_LABEL_NAME -> LB_BALANCER_TYPE_ANNOTATION No functional changes - behavior preserved.
Extract network reconciliation into smaller, focused methods: - detach_unwanted_networks: handles detaching networks that shouldn't be attached - matches_desired_ip: checks if current IP matches desired IP This reduces cognitive complexity and improves readability by: - Removing nested conditionals - Using early returns and guard clauses - Separating concerns into distinct methods No functional changes - behavior preserved.
Change visibility of internal-only types from pub to pub(crate): - LBService - LBAlgorithm - ParsedLoadBalancerConfig - ServiceReconcileAction - TargetReconcileAction - service_matches_desired - normalize_ip These types are only used within the crate and don't need to be part of the public API. This improves encapsulation and makes the module boundaries clearer. No functional changes - behavior preserved.
Add module-level documentation and doc comments for: - Metrics struct and its purpose - ReconcileMeasurer RAII guard - ReconcileTimer for tracking operations Improves code understandability and maintainability.
- Remove unused LBService struct - Use correct visibility for types (pub(super) for module-internal, pub(crate) for crate-internal) - Collapse nested if statement in reconcile_network - Add clippy allow for redundant_pub_crate where needed All 27 tests pass and clippy is clean.
Closed
- Fix trailing whitespace in src/lb/mod.rs - Fix import ordering in src/metrics.rs - Fix formatting issues (long lines, imports) - Add #[must_use] attribute to service_with_spec function
Author
|
✅ CI Fix Applied I've pushed a fix for the CI failure. The changes should trigger a new CI run. Commit: Waiting for CI to re-run... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements maintainability improvements as requested in #58:
Changes Made
Eliminated code duplication (commit 4943e21)
src/test_utils.rsmodule with shared test fixturesservice_with_specandservice_spechelpers from controller modulesStandardized naming (commit f344797)
_ANNOTATIONsuffix_LABEL_NAME,_ANN_NAME) with uniform namingSimplified reconcile_network logic (commit 4f21ec4)
detach_unwanted_networkshelper methodmatches_desired_iphelper methodTightened module visibility (commits 7fa9a4b, a3888b6)
pubtopub(super)orpub(crate)LBServicestructAdded documentation (commit 359d7a8)
Verification
-D warningsResolves: #58