-
Notifications
You must be signed in to change notification settings - Fork 461
refactor: extract helper methods to reduce cyclomatic complexity #5984
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
base: main
Are you sure you want to change the base?
Conversation
|
Skipping CI for Draft Pull Request. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/test all |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5984 +/- ##
==========================================
+ Coverage 44.54% 44.66% +0.11%
==========================================
Files 279 279
Lines 25140 25248 +108
==========================================
+ Hits 11199 11277 +78
- Misses 13128 13145 +17
- Partials 813 826 +13 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Split the monolithic Parameters() method (340 lines, complexity 55) into focused helper methods to improve readability and maintainability. Extracted methods: - convertExistingToHub: convert existing object to hub version - initializeManagedCluster: create or return existing cluster - configureBasicProperties: set name, owner, identity, location - configureNetworkProfile: network settings and CIDR configuration - configureServiceCIDR: service CIDR and DNS IP calculation - configureLinuxProfile: SSH and Linux settings - configureOperatorSpec: kubeconfig secrets configuration - configureAADProfile: Azure Active Directory settings - configureAddonProfiles: add-on configuration - configureSKU: SKU tier settings - configureAPIServerAccessProfile: API server access settings - configureIdentity: identity and kubelet identity - configureHTTPProxyConfig: HTTP proxy settings - configureOIDCIssuerProfile: OIDC issuer settings - configureAutoUpgradeProfile: auto upgrade settings - configureSecurityProfile: security profile orchestration - configureAgentPoolProfiles: agent pool configuration - convertToTargetVersion: convert to stable/preview API Also extracted constants for magic strings (identityTypeMSI, dnsIPLastOctet). No functional changes - all existing tests pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> Co-Authored-By: Bryan Cox <[email protected]>
Split the validateSpec() method (107 lines, complexity 30) into focused helper methods to improve readability and maintainability. Extracted methods: - validateVMCapabilities: validate vCPU, memory, ephemeral OS, encryption - validateUltraDiskSupport: validate ultra disk support for location/zones - requiresUltraDiskValidation: check if ultra disk validation is needed - validateUltraDiskInZone: validate ultra disk support per zone - validateDiagnosticsProfile: validate diagnostics configuration - validateAvailabilityZones: validate availability zone support No functional changes - all existing tests pass. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> Co-Authored-By: Bryan Cox <[email protected]>
0ed137c to
e18fe2f
Compare
|
/test all |
mboersma
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
This diff became challenging to read, but AFAICT all the same validations are present after refactoring, and unit tests still pass. Thanks @bryan-cox!
| if err != nil { | ||
| return "", fmt.Errorf("failed to parse service cidr: %w", err) | ||
| } | ||
| // Set the last octet of the IP to .10 to ensure a valid DNS IP within the service CIDR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1 thanks for improving this code comment too
|
LGTM label has been added. Git tree hash: b40f5dbd7425ba137e4ea3874027b23340546bcf
|
What type of PR is this?
/kind cleanup
What this PR does / why we need it:
This PR refactors two high-complexity methods to improve code readability and maintainability:
ManagedClusterSpec.Parameters()inazure/services/managedclusters/spec.go//nolint:gocyclodirectiveService.validateSpec()inazure/services/scalesets/scalesets.goChanges Made
managedclusters/spec.go:
convertExistingToHub,initializeManagedClusterconfigureBasicProperties,configureNetworkProfile,configureServiceCIDRconfigureLinuxProfile,configureOperatorSpec,configureAADProfileconfigureAddonProfiles,configureSKU,configureAPIServerAccessProfileconfigureIdentity,configureHTTPProxyConfig,configureOIDCIssuerProfileconfigureAutoUpgradeProfile,configureSecurityProfileconfigureAgentPoolProfiles,convertToTargetVersionidentityTypeMSI,dnsIPLastOctet)scalesets/scalesets.go:
validateVMCapabilities: vCPU, memory, ephemeral OS, encryptionvalidateUltraDiskSupport: ultra disk support for location/zonesrequiresUltraDiskValidation: check if validation neededvalidateUltraDiskInZone: per-zone validationvalidateDiagnosticsProfile: diagnostics configurationvalidateAvailabilityZones: availability zone supportWhich issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)format, will close the issue(s) when PR gets merged):Fixes #
Special notes for your reviewer:
This is a pure refactoring PR with no functional changes. All existing tests pass.
The refactoring follows these principles:
TODOs:
Release note: