Skip to content

core: refactor lbaas util functions#3075

Open
kayrus wants to merge 1 commit intokubernetes:masterfrom
kayrus:os-utils-refactor
Open

core: refactor lbaas util functions#3075
kayrus wants to merge 1 commit intokubernetes:masterfrom
kayrus:os-utils-refactor

Conversation

@kayrus
Copy link
Contributor

@kayrus kayrus commented Feb 26, 2026

What this PR does / why we need it:

This is an experimental code refactoring using Claude AI as a development assistant. Each change was discussed and reviewed by me during the development process, it took about 6h in total. The refactoring reduces code duplication, fixes several bugs (missing metrics, potential panics, double observations), and optimizes API call patterns while preserving all existing functionality. All tests pass without modification. @zetaab @dulek @stephenfin I'd like you to review this as well. What do you think about such AI-assisted PRs?

Below is AI summary:

Key improvements

  1. Reduced code duplication (-118 lines, ~15% reduction) - Extracted common patterns into reusable generic helpers:

    • executeAndWaitActive / executeExtractAndWaitActive - Centralizes metrics tracking, error handling, and LB wait logic
    • list / listWithUniqueResult - Standardizes pagination with early-exit optimization
    • getSingleResource - Consistent single-resource retrieval with metrics
  2. Fixed bugs and inconsistencies:

    • Fixed missing metrics observation in 5 functions (GetPools, GetL7policies, GetL7Rules, GetListenersByLoadBalancerID, getOctaviaVersion extraction error)
    • Fixed double metrics observation bug in DeleteListener
    • Eliminated redundant check in GetPoolByName
  3. Performance optimization:

    • GetPoolByListener now uses direct listener Get instead of listing all pools (major API call reduction)
    • listWithUniqueResult implements early-exit when multiple results detected on first page
  4. Improved consistency:

    • Centralized NotFound error handling for all delete operations
    • Standardized error message format across all operations
    • Unified function documentation style (following AWS SDK Go conventions)
    • Consistent metrics tracking across all operations
  5. Better organization:

    • Moved UpdatePool and DeletePool to correct section (Pool Operations, not Pool Member Operations)
    • Added clear section separators
    • Fixed function naming (GetMembersbyPoolGetPoolMembers)

Testing

  • All existing unit tests pass without modification
  • No functional changes - pure refactoring
  • Verified with go test ./pkg/util/openstack/...

Files changed

  • pkg/util/openstack/loadbalancer.go - Main refactoring

Special notes for reviewers:

Release note:

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Feb 26, 2026
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign kayrus for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Feb 26, 2026
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 11, 2026
@kayrus kayrus force-pushed the os-utils-refactor branch from 3d13181 to ab2defc Compare March 12, 2026 14:42
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 12, 2026
@gouthampacha
Copy link
Contributor

Hi @kayrus:

I don't have +2 powers here, so I'm just exercising my review judgement as a long time OpenStack maintainer and sharing my 0.02 cents of opinion.

I think the intent to address bugs is good, but, i'd like to suggest a different approach. You should break this down into multiple commits - get Claude to do it. I know we don't apply the same commit standards here as we do in OpenStack or core Kubernetes projects; but, for the sake of maintainability, seeing single-intent commits is preferred.

@stephenfin
Copy link
Member

Hi @kayrus:

I don't have +2 powers here, so I'm just exercising my review judgement as a long time OpenStack maintainer and sharing my 0.02 cents of opinion.

I think the intent to address bugs is good, but, i'd like to suggest a different approach. You should break this down into multiple commits - get Claude to do it. I know we don't apply the same commit standards here as we do in OpenStack or core Kubernetes projects; but, for the sake of maintainability, seeing single-intent commits is preferred.

I asked for the same thing 😅 Must be an OpenStack thing...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants