Skip to content

Commit

Permalink
firewall: Add empty slices for respective direction instead of nil-sl…
Browse files Browse the repository at this point in the history
…ices

As reported in #320, firewall rules can not be deleted because they
would not exist even if they are shown in "firewall describe".
This behaviour was correct because reflect.DeepEqual also compares if a
slice is empty or nil.
The slices DestinationIPs and SourceIPs are empty slices in an existing
firewall rule. However, the temporary FirewallRule object had slices
that were nil.

To fix this problem, the simple solution is to create an empty IPNet slice
for the respective direction (DestinationIPs for the direction "in", and
SourceIPs for the direction "out").

Signed-off-by: Tom Siewert <[email protected]>
  • Loading branch information
tomsiewert committed May 13, 2021
1 parent 3d72d34 commit 811774d
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/cmd/firewall/delete_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func runDeleteRule(cli *state.State, cmd *cobra.Command, args []string) error {
return fmt.Errorf("destination ips error on index %d: %s", i, err)
}
rule.DestinationIPs[i] = *n
rule.SourceIPs = make([]net.IPNet, 0)
}
case hcloud.FirewallRuleDirectionIn:
rule.SourceIPs = make([]net.IPNet, len(sourceIPs))
Expand All @@ -81,6 +82,7 @@ func runDeleteRule(cli *state.State, cmd *cobra.Command, args []string) error {
if err != nil {
return fmt.Errorf("source ips error on index %d: %s", i, err)
}
rule.DestinationIPs = make([]net.IPNet, 0)
rule.SourceIPs[i] = *n
}
}
Expand Down

0 comments on commit 811774d

Please sign in to comment.