-
Notifications
You must be signed in to change notification settings - Fork 4.2k
feat(hetzner): add IP range configuration for private network #8570
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
Changes from 2 commits
58386d9
3ab4087
6a0f0af
4025cf0
b6b4d19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -63,6 +63,7 @@ type ClusterConfig struct { | |||||
NodeConfigs map[string]*NodeConfig | ||||||
IsUsingNewFormat bool | ||||||
LegacyConfig LegacyConfig | ||||||
IPRange string | ||||||
|
IPRange string | |
DefaultSubnetIPRange string |
Outdated
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.
IPRange string | |
SubnetIPRange string |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -22,6 +22,7 @@ import ( | |||||||||||||||||||||||||||||||||||||||
"fmt" | ||||||||||||||||||||||||||||||||||||||||
"maps" | ||||||||||||||||||||||||||||||||||||||||
"math/rand" | ||||||||||||||||||||||||||||||||||||||||
"net" | ||||||||||||||||||||||||||||||||||||||||
"strings" | ||||||||||||||||||||||||||||||||||||||||
"sync" | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
|
@@ -452,6 +453,39 @@ func instanceTypeArch(manager *hetznerManager, instanceType string) (string, err | |||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
func findIpRange(nodeId string, clusterConfig *ClusterConfig) (*net.IPNet, error) { | ||||||||||||||||||||||||||||||||||||||||
if !clusterConfig.IsUsingNewFormat { | ||||||||||||||||||||||||||||||||||||||||
return nil, nil | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
if nodeConfig, exists := clusterConfig.NodeConfigs[nodeId]; exists && nodeConfig.IPRange != "" { | ||||||||||||||||||||||||||||||||||||||||
_, ipNet, err := net.ParseCIDR(nodeConfig.IPRange) | ||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||
return nil, fmt.Errorf("failed to parse IP range %s for node %s: %v", nodeConfig.IPRange, nodeId, err) | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
return ipNet, nil | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
if clusterConfig.IPRange != "" { | ||||||||||||||||||||||||||||||||||||||||
_, ipNet, err := net.ParseCIDR(clusterConfig.IPRange) | ||||||||||||||||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||||||||||||||||
return nil, fmt.Errorf("failed to parse global IP range %s: %v", clusterConfig.IPRange, err) | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
return ipNet, nil | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
return nil, nil | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
func isIpRangeInNetwork(ipRange *net.IPNet, network *hcloud.Network) bool { | ||||||||||||||||||||||||||||||||||||||||
found := false | ||||||||||||||||||||||||||||||||||||||||
for _, nSubnet := range network.Subnets { | ||||||||||||||||||||||||||||||||||||||||
_, nSubnetRange, _ := net.ParseCIDR(nSubnet.IPRange.String()) | ||||||||||||||||||||||||||||||||||||||||
if nSubnetRange.String() == ipRange.String() { | ||||||||||||||||||||||||||||||||||||||||
found = true | ||||||||||||||||||||||||||||||||||||||||
break | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
return found | ||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||
|
func isIpRangeInNetwork(ipRange *net.IPNet, network *hcloud.Network) bool { | |
found := false | |
for _, nSubnet := range network.Subnets { | |
_, nSubnetRange, _ := net.ParseCIDR(nSubnet.IPRange.String()) | |
if nSubnetRange.String() == ipRange.String() { | |
found = true | |
break | |
} | |
} | |
return found | |
} | |
func isIpRangeInNetwork(ipRange *net.IPNet, network *hcloud.Network) bool { | |
return slices.ContainsFunc(network.Subnets, func(subnet hcloud.NetworkSubnet) bool { | |
if ipRange == nil || subnet.IPRange == nil { | |
return false | |
} | |
return subnet.IPRange.IP.Equal(ipRange.IP) && len(subnet.IPRange.Mask) == len(ipRange.Mask) | |
}) | |
} |
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.
Needs update when config values change. Please add a small notice, that the subnetwork needs to exist beforehand.