hetzner-k3s 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d251d84c9600608af2e382ae10838104bb8fe81fa87b1058b25fd571187a0a88
4
- data.tar.gz: 9530af5905cebe724e6be2eafaf60da07172a7a640b1913e3572ee419b0feaed
3
+ metadata.gz: 7702216e981cea045d5c8fc09087a233a41ed06fa1a812e2aab008db8375e953
4
+ data.tar.gz: 43d606e2517b62bd27ba040305b67c9a84f07d6e55a84ea5ed1a0d92ba501af9
5
5
  SHA512:
6
- metadata.gz: c3b567d8c78c29bc0785d943c52ab65eab40d934ebdf01045c7efd0c76d74087eca2f81c1a790fb4d700bf39c92a696aca9794e17c252467de7838bb2149e56e
7
- data.tar.gz: 010a87dd114c2d1209f8da453ebb8123fbbf4f4684dacf3aa2e85d648715c78013f798e68b413603a25f9869e153afced6104cceca5914060aaedb6de8a358b2
6
+ metadata.gz: 1b7286180209083562f31e07b6227e47c04db0fdc3eadbb9fbd8506cf63bbd59bf449f8d99a48f6d9647e03214a84c04ef2c364c9d2a004b71777557607dd9d1
7
+ data.tar.gz: 6fa33623fb8dccbf06395aa5fbb14d74ad2a4581954c7a425b839eef1ccb04888ed7abe1025b245fcade8dac18be6864c702c240d5c5fdfc87370a884735bfd9
data/README.md CHANGED
@@ -44,6 +44,7 @@ cluster_name: test
44
44
  kubeconfig_path: "./kubeconfig"
45
45
  k3s_version: v1.21.3+k3s1
46
46
  ssh_key_path: "~/.ssh/id_rsa.pub"
47
+ verify_host_key: false
47
48
  location: nbg1
48
49
  masters:
49
50
  instance_type: cpx21
@@ -74,6 +75,8 @@ curl \
74
75
  ```
75
76
 
76
77
 
78
+ Note: the option `verify_host_key` is by default set to `false` to disable host key verification. This is because sometimes when creating new servers, Hetzner may assign IP addresses that were previously used by other servers you owned in the past. Therefore the host key verification would fail. If you set this option to `true` and this happens, the tool won't be able to continue creating the cluster until you resolve the issue with one of the suggestions it will give you.
79
+
77
80
  Finally, to create the cluster run:
78
81
 
79
82
  ```bash
@@ -211,6 +214,9 @@ Once the cluster is ready you can create persistent volumes out of the box with
211
214
 
212
215
  ## changelog
213
216
 
217
+ - 0.3.1
218
+ - Allow enabling/disabling the host key verification
219
+
214
220
  - 0.3.0
215
221
  - Handle case when an SSH key with the given fingerprint already exists in the Hetzner project
216
222
  - Handle a timeout of 5 seconds for requests to the Hetzner API
@@ -4,6 +4,7 @@ cluster_name: test
4
4
  kubeconfig_path: "../kubeconfig"
5
5
  k3s_version: v1.21.3+k3s1
6
6
  ssh_key_path: "~/.ssh/id_rsa.pub"
7
+ verify_host_key: false
7
8
  location: nbg1
8
9
  masters:
9
10
  instance_type: cpx21
@@ -80,6 +80,7 @@ module Hetzner
80
80
  validate_k3s_version
81
81
  validate_masters
82
82
  validate_worker_node_pools
83
+ validate_verify_host_key
83
84
  when :delete
84
85
  validate_kubeconfig_path_must_exist
85
86
  when :upgrade
@@ -292,6 +293,12 @@ module Hetzner
292
293
  errors << "Cannot connect to the Kubernetes cluster"
293
294
  false
294
295
  end
296
+
297
+
298
+ def validate_verify_host_key
299
+ return unless [true, false].include?(configuration.fetch("ssh_key_path", false))
300
+ errors << "Please set the verify_host_key option to either true or false"
301
+ end
295
302
  end
296
303
  end
297
304
  end
@@ -29,6 +29,7 @@ class Cluster
29
29
  @masters_config = configuration.dig("masters")
30
30
  @worker_node_pools = configuration.dig("worker_node_pools")
31
31
  @location = configuration.dig("location")
32
+ @verify_host_key = configuration.fetch("verify_host_key", false)
32
33
  @servers = []
33
34
 
34
35
  create_resources
@@ -68,7 +69,7 @@ class Cluster
68
69
  :masters_config, :worker_node_pools,
69
70
  :location, :ssh_key_path, :kubernetes_client,
70
71
  :hetzner_token, :tls_sans, :new_k3s_version, :configuration,
71
- :config_file
72
+ :config_file, :verify_host_key
72
73
 
73
74
 
74
75
  def latest_k3s_version
@@ -138,14 +139,14 @@ class Cluster
138
139
  end
139
140
  end
140
141
 
141
- threads.each(&:join)
142
+ threads.each(&:join) unless threads.empty?
142
143
 
143
144
  puts
144
145
  threads = servers.map do |server|
145
146
  Thread.new { wait_for_ssh server }
146
147
  end
147
148
 
148
- threads.each(&:join)
149
+ threads.each(&:join) unless threads.empty?
149
150
  end
150
151
 
151
152
  def delete_resources
@@ -160,22 +161,22 @@ class Cluster
160
161
  end
161
162
  end
162
163
 
163
- threads.each(&:join)
164
+ threads.each(&:join) unless threads.empty?
164
165
  end
165
- rescue Timeout::Error
166
+ rescue Timeout::Error, Excon::Error::Socket
166
167
  puts "Unable to fetch nodes from Kubernetes API. Is the cluster online?"
167
168
  end
168
169
 
169
170
  # Deleting nodes defined in the config file just in case there are leftovers i.e. nodes that
170
171
  # were not part of the cluster for some reason
171
172
 
172
- threads = all_servers.each do |server|
173
+ threads = all_servers.map do |server|
173
174
  Thread.new do
174
175
  Hetzner::Server.new(hetzner_client: hetzner_client, cluster_name: cluster_name).delete(server_name: server["name"])
175
176
  end
176
177
  end
177
178
 
178
- threads.each(&:join)
179
+ threads.each(&:join) unless threads.empty?
179
180
 
180
181
  puts
181
182
 
@@ -292,7 +293,7 @@ class Cluster
292
293
  end
293
294
  end
294
295
 
295
- threads.each(&:join)
296
+ threads.each(&:join) unless threads.empty?
296
297
  end
297
298
 
298
299
  threads = workers.map do |worker|
@@ -307,7 +308,7 @@ class Cluster
307
308
  end
308
309
  end
309
310
 
310
- threads.each(&:join)
311
+ threads.each(&:join) unless threads.empty?
311
312
  end
312
313
 
313
314
  def deploy_cloud_controller_manager
@@ -464,18 +465,23 @@ class Cluster
464
465
  public_ip = server.dig("public_net", "ipv4", "ip")
465
466
  output = ""
466
467
 
467
- Net::SSH.start(public_ip, "root", verify_host_key: :never) do |session|
468
+ Net::SSH.start(public_ip, "root", verify_host_key: (verify_host_key ? :always : :never)) do |session|
468
469
  session.exec!(command) do |channel, stream, data|
469
470
  output << data
470
471
  puts data if print_output
471
472
  end
472
473
  end
473
-
474
474
  output.chop
475
475
  rescue Net::SSH::Disconnect => e
476
476
  retry unless e.message =~ /Too many authentication failures/
477
477
  rescue Net::SSH::ConnectionTimeout, Errno::ECONNREFUSED, Errno::ENETUNREACH, Errno::EHOSTUNREACH
478
478
  retry
479
+ rescue Net::SSH::HostKeyMismatch
480
+ puts
481
+ puts "Cannot continue: Unable to SSH into server with IP #{public_ip} because the existing fingerprint in the known_hosts file does not match that of the actual host key."
482
+ puts "This is due to a security check but can also happen when creating a new server that gets assigned the same IP address as another server you've owned in the past."
483
+ puts "If are sure no security is being violated here and you're just creating new servers, you can eiher remove the relevant lines from your known_hosts (see IPs from the cloud console) or disable host key verification by setting the option 'verify_host_key' to false in the configuration file for the cluster."
484
+ exit 1
479
485
  end
480
486
 
481
487
  def kubernetes_client
@@ -1,5 +1,5 @@
1
1
  module Hetzner
2
2
  module K3s
3
- VERSION = "0.3.0"
3
+ VERSION = "0.3.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hetzner-k3s
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vito Botta