Skip to content

Commit

Permalink
Prefer running kubernetes version to configured one
Browse files Browse the repository at this point in the history
  • Loading branch information
dbackeus committed Nov 13, 2024
1 parent d2d6e3e commit 88158df
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
12 changes: 11 additions & 1 deletion app/models/machine_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,21 @@ def generate_config(output_type: server.talos_type)
patch_worker_file = "#{Dir.tmpdir}/patch-worker-#{SecureRandom.hex}"
File.write(patch_worker_file, replace_substitution_variables(config.patch_worker || ""))

# Prefer the running kubernetes version over the configured one since bootstrapping
# outdated versions can lead to issues.
running_or_configured_kubernetes_version =
# Avoid infinite recursion since talosconfig is used to determine the running kubernetes version
if output_type == "talosconfig"
config.kubernetes_version
else
server.cluster.running_kubernetes_version || config.kubernetes_version
end

command = %(
talosctl gen config \
--install-disk #{install_disk} \
--install-image #{config.install_image} \
--kubernetes-version #{config.kubernetes_version} \
--kubernetes-version #{running_or_configured_kubernetes_version} \
--config-patch @#{patch_file} \
--config-patch-control-plane @#{patch_control_plane_file} \
--config-patch-worker @#{patch_worker_file} \
Expand Down
4 changes: 4 additions & 0 deletions app/models/talosctl.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require "open3"

# Wrapper around the talosctl command line tool to interact with already bootstrapped Talos clusters

class Talosctl
def initialize(config_string)
@config_string = config_string
Expand Down Expand Up @@ -35,6 +37,8 @@ def run(command)
end
end

private

def config_file
return @config_file if defined?(@config_file)

Expand Down
2 changes: 1 addition & 1 deletion app/views/configs/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<%# installed via a disk image (which we do when bootstrapping). Can change it back to text_field %>
<%# when/if Talos starts making proper use of the configuration. %>
<%= f.hidden_field :install_image, readonly: true, hint: "Gets passed into the --imagedisk argument for talosctl gen config." %>
<%= f.text_field :kubernetes_version, placeholder: "1.26.3", hint: "Gets passed into the --kubernetes-version argument for talosctl gen config." %>
<%= f.text_field :kubernetes_version, placeholder: "1.30.6", hint: "Gets passed into the --kubernetes-version argument for talosctl gen config on new clusters. For already running clusters, the kubernetes version found on existing control planes will be used instead, to avoid accidentally onboarding nodes with incompatible Kubernetes versions." %>

<%= f.label :kubespan, class: "mb-5 block" do %>
<h3 class="font-bold mb-1 text-gray-900">Enable Kubespan</h3>
Expand Down

0 comments on commit 88158df

Please sign in to comment.