Skip to content

Commit

Permalink
Make it possible to customize the subnet
Browse files Browse the repository at this point in the history
  • Loading branch information
vitobotta committed Feb 15, 2023
1 parent cd044bf commit 222bcb1
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ ssh_allowed_networks:
- 0.0.0.0/0
api_allowed_networks:
- 0.0.0.0/0
private_network_subnet: 10.0.0.0/16
schedule_workloads_on_masters: false
# image: rocky-9 # optional: default is ubuntu-22.04
# snapshot_os: microos # otional: specified the os type when using a custom snapshot
Expand Down
1 change: 1 addition & 0 deletions cluster_config.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ssh_allowed_networks:
api_allowed_networks:
- 0.0.0.0/0
schedule_workloads_on_masters: false
private_network_subnet: 10.0.0.0/16
# image: rocky-9 # optional: default is ubuntu-22.04
# snapshot_os: microos # otional: specified the os type when using a custom snapshot
masters_pool:
Expand Down
6 changes: 4 additions & 2 deletions src/cluster/create.cr
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ class Cluster::Create
firewall_name: settings.cluster_name,
ssh_allowed_networks: settings.ssh_allowed_networks,
api_allowed_networks: settings.api_allowed_networks,
high_availability: settings.masters_pool.instance_count > 1
high_availability: settings.masters_pool.instance_count > 1,
private_network_subnet: settings.private_network_subnet
).run

@ssh_key = Hetzner::SSHKey::Create.new(
Expand Down Expand Up @@ -186,7 +187,8 @@ class Cluster::Create
hetzner_client: hetzner_client,
network_name: settings.cluster_name,
location: settings.masters_pool.location,
locations: configuration.locations
locations: configuration.locations,
private_network_subnet: settings.private_network_subnet
).run
end
end
Expand Down
1 change: 1 addition & 0 deletions src/configuration/main.cr
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,5 @@ class Configuration::Main
getter existing_network : String?
getter image : String = "ubuntu-22.04"
getter snapshot_os : String = "default"
getter private_network_subnet : String = "10.0.0.0/16"
end
2 changes: 1 addition & 1 deletion src/hetzner-k3s.cr
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require "./cluster/upgrade"

module Hetzner::K3s
class CLI < Admiral::Command
VERSION = "1.0.8"
VERSION = "1.0.9"

class Create < Admiral::Command
define_help description: "create - Create a cluster"
Expand Down
8 changes: 5 additions & 3 deletions src/hetzner/firewall/create.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ require "./find"
class Hetzner::Firewall::Create
getter hetzner_client : Hetzner::Client
getter firewall_name : String
getter private_network_subnet : String
getter ssh_allowed_networks : Array(String)
getter api_allowed_networks : Array(String)
getter high_availability : Bool
Expand All @@ -14,7 +15,8 @@ class Hetzner::Firewall::Create
@firewall_name,
@ssh_allowed_networks,
@api_allowed_networks,
@high_availability
@high_availability,
@private_network_subnet
)
@firewall_finder = Hetzner::Firewall::Find.new(hetzner_client, firewall_name)
end
Expand Down Expand Up @@ -70,7 +72,7 @@ class Hetzner::Firewall::Create
protocol: "tcp",
port: "any",
source_ips: [
"10.0.0.0/16"
private_network_subnet
],
destination_ips: [] of String
},
Expand All @@ -80,7 +82,7 @@ class Hetzner::Firewall::Create
protocol: "udp",
port: "any",
source_ips: [
"10.0.0.0/16"
private_network_subnet
],
destination_ips: [] of String
}
Expand Down
7 changes: 4 additions & 3 deletions src/hetzner/network/create.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ class Hetzner::Network::Create
getter location : String
getter network_finder : Hetzner::Network::Find
getter locations : Array(Hetzner::Location)
getter private_network_subnet : String

def initialize(@hetzner_client, @network_name, @location, @locations)
def initialize(@hetzner_client, @network_name, @location, @locations, @private_network_subnet)
@network_finder = Hetzner::Network::Find.new(@hetzner_client, @network_name)
end

Expand Down Expand Up @@ -38,10 +39,10 @@ class Hetzner::Network::Create

{
name: network_name,
ip_range: "10.0.0.0/16",
ip_range: private_network_subnet,
subnets: [
{
ip_range: "10.0.0.0/16",
ip_range: private_network_subnet,
network_zone: network_zone,
type: "cloud"
}
Expand Down

0 comments on commit 222bcb1

Please sign in to comment.