-
Notifications
You must be signed in to change notification settings - Fork 62
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
Add feature to update / delete attached firewall #171
Conversation
@@ -229,6 +229,90 @@ func (l *loadbalancers) EnsureLoadBalancer(ctx context.Context, clusterName stri | |||
return lbStatus, nil | |||
} | |||
|
|||
func (l *loadbalancers) getNodeBalancerDeviceId(ctx context.Context, firewallID, nbID, page int) (int, bool, error) { | |||
devices, err := l.client.ListFirewallDevices(ctx, firewallID, &linodego.ListOptions{PageSize: 500, PageOptions: &linodego.PageOptions{Page: page}}) |
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.
I don't think you need to handle pagination manually here - linodego abstracts it from you
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.
Though the output is []linodego.FirewallDevice. The PageOptions is passed as an input parameter. The max. page size is 500. If there are more than 500 items, this might be useful.
As discussed, for the sake of simplicity, this could be skipped with just a single call rather than recursive set of calls.
// get the attached firewall | ||
firewalls, err := l.client.ListNodeBalancerFirewalls(ctx, nb.ID, &linodego.ListOptions{}) | ||
if err != nil { | ||
if !ok { |
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.
can you add comments explaining this logic?
if existingFirewallID != newFirewallID { | ||
// remove the existing firewall | ||
|
||
if existingFirewallID != 0 { |
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.
when will existingFirewallID be 0?
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.
The value is zero when there is no Firewall assigned. Default value of a integer variable in golang is 0. The existingFirewallID
variable would only be tampered if there's a firewall attached to nodeBalancer. If not, it would be 0
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.
ah I see the logic now. can you move the declaration for existingFirewallID to line 277 so its immediately obvious?
@@ -186,6 +190,40 @@ func (f *fakeAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |||
_, _ = w.Write(rr) | |||
return | |||
} | |||
|
|||
rx, _ = regexp.Compile("/nodebalancers/[0-9]+/firewalls") |
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.
It's weird to ignore the error here - maybe just run MustCompile
to ensure it passes.
{Reason: "Not Found"}, | ||
}, | ||
} | ||
rr, _ := json.Marshal(resp) |
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.
It's kinda weird that we check errors from strconv.Atoi
and not these ones. They seem to be similarly likely to happen.
@@ -24,6 +24,8 @@ type fakeAPI struct { | |||
nb map[string]*linodego.NodeBalancer | |||
nbc map[string]*linodego.NodeBalancerConfig | |||
nbn map[string]*linodego.NodeBalancerNode | |||
fw map[int]*linodego.Firewall | |||
fwd map[int]map[int]*linodego.FirewallDevice |
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.
It's useful to add comments here to signal what the int
s stand for
@@ -229,6 +229,103 @@ func (l *loadbalancers) EnsureLoadBalancer(ctx context.Context, clusterName stri | |||
return lbStatus, nil | |||
} | |||
|
|||
// getNodeBalancerDeviceId gets the deviceID of the nodeBalancer that is attached to the firewall. | |||
func (l *loadbalancers) getNodeBalancerDeviceId(ctx context.Context, firewallID, nbID, page int) (int, bool, error) { | |||
devices, err := l.client.ListFirewallDevices(ctx, firewallID, &linodego.ListOptions{PageSize: 500, PageOptions: &linodego.PageOptions{Page: page}}) |
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.
This is only called with Page: 1
- so when do we actually paginate?
firewalls, err := l.client.ListNodeBalancerFirewalls(ctx, nb.ID, &linodego.ListOptions{}) | ||
if err != nil { | ||
if !ok { | ||
if err.Error() != "[404] Not Found" { |
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.
This is a bit icky, can we maybe use the linodego.Error
type assertion and its Code
field?
@@ -258,6 +354,12 @@ func (l *loadbalancers) updateNodeBalancer(ctx context.Context, clusterName stri | |||
} | |||
} | |||
|
|||
// update node-balancer firewall |
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.
nit: this comment seems redundant
@@ -639,7 +651,7 @@ func testUpdateLoadBalancerAddTLSPort(t *testing.T, client *linodego.Client, _ * | |||
} | |||
|
|||
if !reflect.DeepEqual(expectedPorts, observedPorts) { | |||
t.Errorf("NodeBalancer ports mismatch: expected %v, got %v", expectedPorts, observedPorts) | |||
t.Errorf("NodeBalancer ports mismatch: expected %v, got %v", `expectedPorts`, observedPorts) |
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.
Why are we passing a string literal to the formatter?
Merging now, will address comments in a followup PR |
Fixes #146
Changes:
General:
Pull Request Guidelines: