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 1 commit
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
10 changes: 9 additions & 1 deletion cloud/linode/loadbalancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,15 @@ 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)
// TODO: use this constructor once we merge in linodego v1 update
mrogers950 marked this conversation as resolved.
Show resolved Hide resolved
git-it127 marked this conversation as resolved.
Show resolved Hide resolved
// f := &linodego.Filter{}
// f.AddField(linodego.Eq, "ipv4", ipv4)
// filter, err := f.MarshalJSON()
// if err != nil {
// return nil, err
// }
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.

Expand Down