Skip to content

Commit

Permalink
Allow mixing servers of different series
Browse files Browse the repository at this point in the history
  • Loading branch information
vitobotta committed Aug 8, 2021
1 parent f2362ff commit ab4d7d7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
6 changes: 0 additions & 6 deletions lib/hetzner/k3s/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ def validate_config_file(action)
validate_k3s_version
validate_masters
validate_worker_node_pools
validate_all_nodes_must_be_of_same_series
when :delete
validate_kubeconfig_path_must_exist
when :upgrade
Expand Down Expand Up @@ -221,11 +220,6 @@ def validate_worker_node_pools
end
end

def validate_all_nodes_must_be_of_same_series
series = used_server_types.map{ |used_server_type| used_server_type[0..1]}
errors << "Master and worker node pools must all be of the same server series for networking to function properly (available series: cx, cp, ccx)" unless series.uniq.size == 1
end

def validate_new_k3s_version_must_be_more_recent
return if options[:force] == "true"
return unless kubernetes_client
Expand Down
21 changes: 10 additions & 11 deletions lib/hetzner/k3s/cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def create(configuration:)
@masters_config = configuration.dig("masters")
@worker_node_pools = configuration.dig("worker_node_pools")
@location = configuration.dig("location")
@flannel_interface = find_flannel_interface(configuration.dig("masters")["instance_type"])
@servers = []

create_resources
Expand Down Expand Up @@ -66,7 +65,7 @@ def upgrade(configuration:, new_k3s_version:, config_file:)

attr_reader :hetzner_client, :cluster_name, :kubeconfig_path, :k3s_version,
:masters_config, :worker_node_pools,
:location, :flannel_interface, :ssh_key_path, :kubernetes_client,
:location, :ssh_key_path, :kubernetes_client,
:hetzner_token, :tls_sans, :new_k3s_version, :configuration,
:config_file

Expand Down Expand Up @@ -216,6 +215,7 @@ def upgrade_cluster

def master_script(master)
server = master == first_master ? " --cluster-init " : " --server https://#{first_master_private_ip}:6443 "
flannel_interface = find_flannel_interface(master)

<<~EOF
curl -sfL https://get.k3s.io | INSTALL_K3S_VERSION="#{k3s_version}" K3S_TOKEN="#{k3s_token}" INSTALL_K3S_EXEC="server \
Expand All @@ -242,7 +242,9 @@ def master_script(master)
EOF
end

def worker_script
def worker_script(worker)
flannel_interface = find_flannel_interface(worker)

<<~EOF
curl -sfL https://get.k3s.io | K3S_TOKEN="#{k3s_token}" INSTALL_K3S_VERSION="#{k3s_version}" K3S_URL=https://#{first_master_private_ip}:6443 INSTALL_K3S_EXEC="agent \
--node-name="$(hostname -f)" \
Expand Down Expand Up @@ -285,7 +287,7 @@ def deploy_kubernetes
puts
puts "Deploying k3s to worker (#{worker["name"]})..."

ssh worker, worker_script, print_output: true
ssh worker, worker_script(worker), print_output: true

puts
puts "...k3s has been deployed to worker (#{worker["name"]})."
Expand Down Expand Up @@ -471,14 +473,11 @@ def kubernetes_client
@kubernetes_client = K8s::Client.config(K8s::Config.new(config_hash))
end

def find_flannel_interface(server_type)
case server_type[0..1]
when "cp"
"enp7s0"
when "cc"
"enp7s0"
when "cx"
def find_flannel_interface(server)
if ssh(server, "lscpu | grep Vendor") =~ /Intel/
"ens10"
else
"enp7s0"
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/hetzner/k3s/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Hetzner
module K3s
VERSION = "0.1.0"
VERSION = "0.2.0"
end
end

0 comments on commit ab4d7d7

Please sign in to comment.