core: refactor lbaas util functions - #3075
Conversation
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
3d13181 to
ab2defc
Compare
|
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... |
|
The Kubernetes project currently lacks enough contributors to adequately respond to all PRs. This bot triages PRs according to the following rules:
You can:
Please send feedback to sig-contributor-experience at kubernetes/community. /lifecycle stale |
|
I see that the bug fixes and refactoring are deeply intertwined. The bugs (missing metrics observations) are fixed implicitly via the new helpers, so there's no standalone commit of fixed metrics possible without either the helpers or inline fixes. However it is possible to split this logically via commits if it's important to split this anyway. I can propose to split these fixes into 5 or 6 logical commits:
|
|
@kayrus I was thinking about that this PR has some general independent parts:
Splitting those out while keeping the bug-fix/helper-extraction/refactor as one atomic commit would reduce the noise in review without fragmenting what can't actually be separated, so I think that split this into some general commits will be feasible and it can be not a broken glass if just to separate some things, it's not a big deal here
@gouthampacha would like to ask just how much reasonable to split it into clear commits? |
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
I left only the code improvement with new helpers. @zetaab @gouthampacha @stephenfin please give this PR a try one more time. |
gouthampacha
left a comment
There was a problem hiding this comment.
/lgtm
This works for me, but, a couple of comments inline that could be addressed if you make another patch
769ff53 to
5545247
Compare
5545247 to
7cee2ef
Compare
f88dd2d to
0a21e49
Compare
|
@jihyun-huh @gouthampacha @stephenfin @zetaab a few improvements were made (by me, not AI :) ). please review one more time. |
0a21e49 to
93b8986
Compare
93b8986 to
73c265a
Compare
|
/lgtm minor issue with returning a stale object in |
it is fixed, see line 190 |
anguslees
left a comment
There was a problem hiding this comment.
/lgtm
Next time, however - a PR like this is very hard to review. You have mixed unrelated no-op code cleanups across multiple areas with real bug fixes. Please don't do this again, since if we have to roll back an unexpected behaviour change, then we're also rolling back all these other improvements.
Using AI for this type of cleanup is a great idea. Easier code gen means even more reason to optimise for review however, not the reverse.
|
@anguslees I understand the concern about mixing changes. The refactoring was necessary because the new helper function needed to be integrated across multiple functions, I could have introduced the helper in one PR, then applied it to each function in dozens of follow-up PRs. However, that approach wouldn't scale and would look bizarre. |
| mc := metrics.NewMetricContext(resourceType, operation) | ||
| result, err := fn() | ||
| if mc.ObserveRequest(err) != nil { | ||
| return result, fmt.Errorf("failed to %s %s: %v", operation, resourceType, err) |
| if operation == "delete" && cpoerrors.IsNotFound(err) { | ||
| klog.V(2).Infof("%s was already deleted", resourceType) | ||
| } else { | ||
| return result, fmt.Errorf("failed to %s %s on load balancer %s: %v", operation, resourceType, lbID, err) |
| } | ||
| } | ||
| if _, err := WaitActiveAndGetLoadBalancer(ctx, client, lbID); err != nil { | ||
| return result, fmt.Errorf("failed to wait for load balancer %s ACTIVE after %s %s: %v", |
| if cpoerrors.IsNotFound(err) { | ||
| return nil, cpoerrors.ErrNotFound | ||
| } | ||
| listener, err := listWithUniqueResult(ctx, "loadbalancer_listener", "list", listeners.List(client, listOpts), listeners.ExtractListeners) |
There was a problem hiding this comment.
this is actually now hardfail if not found, we are not checking ErrNotFound error at all
|
@kayrus: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
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
Reduced code duplication (-118 lines, ~15% reduction) - Extracted common patterns into reusable generic helpers:
executeAndWaitActive/executeExtractAndWaitActive- Centralizes metrics tracking, error handling, and LB wait logiclist/listWithUniqueResult- Standardizes pagination with early-exit optimizationgetSingleResource- Consistent single-resource retrieval with metricsFixed bugs and inconsistencies:
GetPools,GetL7policies,GetL7Rules,GetListenersByLoadBalancerID,getOctaviaVersionextraction error)DeleteListenerGetPoolByNamePerformance optimization:
GetPoolByListenernow uses direct listener Get instead of listing all pools (major API call reduction)listWithUniqueResultimplements early-exit when multiple results detected on first pageImproved consistency:
Better organization:
UpdatePoolandDeletePoolto correct section (Pool Operations, not Pool Member Operations)GetMembersbyPool→GetPoolMembers)Testing
go test ./pkg/util/openstack/...Files changed
pkg/util/openstack/loadbalancer.go- Main refactoringSpecial notes for reviewers:
Release note: