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

Filter NodeBalancers when we know their ipv4 #126

Merged
merged 4 commits into from
Mar 24, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions cloud/linode/loadbalancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,17 +450,16 @@ func (l *loadbalancers) getNodeBalancerByHostname(ctx context.Context, service *
}

func (l *loadbalancers) getNodeBalancerByIPv4(ctx context.Context, service *v1.Service, ipv4 string) (*linodego.NodeBalancer, error) {
lbs, err := l.client.ListNodeBalancers(ctx, nil)
filter := fmt.Sprintf(`{"ipv4": "%v"}`, ipv4)
lbs, err := l.client.ListNodeBalancers(ctx, &linodego.ListOptions{Filter: filter})
if err != nil {
return nil, err
}

Choose a reason for hiding this comment

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

It seems the loop below this may no longer be needed if we are getting the exact ip. Or it could be adjusted to be cleaner. Although leaving it how it is I don't think will harm anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Did you have something like this in mind?

if len(lbs) == 0 {
    return nil, lbNotFoundError{serviceNn: getServiceNn(service)}
}
klog.V(2).Infof("found NodeBalancer (%d) for service (%s) via IPv4 (%s)", lbs[0].ID, getServiceNn(service), ipv4)
return &lbs[0], nil

Choose a reason for hiding this comment

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

yes I like that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Committed.

for _, lb := range lbs {
if *lb.IPv4 == ipv4 {
klog.V(2).Infof("found NodeBalancer (%d) for service (%s) via IPv4 (%s)", lb.ID, getServiceNn(service), ipv4)
return &lb, nil
}
if len(lbs) == 0 {
return nil, lbNotFoundError{serviceNn: getServiceNn(service)}
}
return nil, lbNotFoundError{serviceNn: getServiceNn(service)}
klog.V(2).Infof("found NodeBalancer (%d) for service (%s) via IPv4 (%s)", lbs[0].ID, getServiceNn(service), ipv4)
return &lbs[0], nil
}

func (l *loadbalancers) getNodeBalancerByID(ctx context.Context, service *v1.Service, id int) (*linodego.NodeBalancer, error) {
Expand Down