From 982b77719d6f23a04d1fee642eddfab82c0f4e56 Mon Sep 17 00:00:00 2001 From: Lidia Mokevnina Date: Mon, 9 Oct 2023 11:26:07 +0200 Subject: [PATCH 1/4] [346] added k8s version option --- lib/uffizzi/cli/cluster.rb | 30 +++++++++++++++++++++--------- man/uffizzi-cluster-create.ronn | 11 ++++++++++- 2 files changed, 31 insertions(+), 10 deletions(-) diff --git a/lib/uffizzi/cli/cluster.rb b/lib/uffizzi/cli/cluster.rb index 02bbd31f..8b1945f7 100644 --- a/lib/uffizzi/cli/cluster.rb +++ b/lib/uffizzi/cli/cluster.rb @@ -11,6 +11,9 @@ require 'uffizzi/services/kubeconfig_service' require 'uffizzi/services/cluster/disconnect_service' +MANUAL = 'manual' +DEFAULT_K8S_VERSION = '1.27' + module Uffizzi class Cli::Cluster < Thor class Error < StandardError; end @@ -30,6 +33,7 @@ def list method_option :'update-current-context', type: :boolean, required: false, default: true method_option :output, required: false, type: :string, aliases: '-o', enum: ['json', 'pretty-json'] method_option :'creation-source', required: false, type: :string + method_option :'k8s-version', required: false, type: :string, default: '1.27' def create(name = nil) run('create', { name: name }) end @@ -113,14 +117,17 @@ def handle_create_command(project_slug, command_args) end cluster_name = command_args[:name] || options[:name] || ClusterService.generate_name - creation_source = options[:"creation-source"] || ClusterService::MANUAL_CREATION_SOURCE - - unless ClusterService.valid_name?(cluster_name) - Uffizzi.ui.say_error_and_exit("Cluster name: #{cluster_name} is not valid.") - end - - manifest_file_path = options[:manifest] - params = cluster_creation_params(cluster_name, creation_source, manifest_file_path) + creation_source = options[:"creation-source"] || MANUAL + k8s_version = options[:k8s_version] || DEFAULT_K8S_VERSION + Uffizzi.ui.say_error_and_exit('k8s version should be formatted as [MAJOR].[MINOR].') unless valid_k8s_version?(k8s_version) + Uffizzi.ui.say_error_and_exit("Cluster name: #{cluster_name} is not valid.") unless ClusterService.valid_name?(cluster_name) + + params = cluster_creation_params( + name: cluster_name, + creation_source: creation_source, + manifest_file_path: options[:manifest], + k8s_version: k8s_version, + ) response = create_cluster(ConfigFile.read_option(:server), project_slug, params) return ResponseHelper.handle_failed_response(response) unless ResponseHelper.created?(response) @@ -239,7 +246,7 @@ def say_error_update_kubeconfig(cluster_data) end end - def cluster_creation_params(name, creation_source, manifest_file_path) + def cluster_creation_params(name:, creation_source:, manifest_file_path:, k8s_version:) manifest_content = load_manifest_file(manifest_file_path) oidc_token = Uffizzi::ConfigFile.read_option(:oidc_token) @@ -248,6 +255,7 @@ def cluster_creation_params(name, creation_source, manifest_file_path) name: name, manifest: manifest_content, creation_source: creation_source, + k8s_version: k8s_version, }, token: oidc_token, } @@ -397,5 +405,9 @@ def save_previous_current_context(kubeconfig_path, current_context) previous_current_contexts = Uffizzi::ConfigHelper.set_previous_current_context_by_path(kubeconfig_path, current_context) ConfigFile.write_option(:previous_current_contexts, previous_current_contexts) end + + def valid_k8s_version?(version) + ['1.28', '1.27', '1.26'].include?(version) + end end end diff --git a/man/uffizzi-cluster-create.ronn b/man/uffizzi-cluster-create.ronn index 0420fe82..bed1e943 100644 --- a/man/uffizzi-cluster-create.ronn +++ b/man/uffizzi-cluster-create.ronn @@ -1,3 +1,4 @@ +uffizzi cluster create -h uffizzi-cluster-create - create a cluster ================================================================ @@ -12,9 +13,17 @@ uffizzi-cluster-create - create a cluster https://docs.uffizzi.com/references/cli/ ## FLAGS + --name Option is deprecated and will be removed in the newer versions. - Please use a positional argument instead: uffizzi cluster create my-awesome-name. + Please use a positional argument instead: uffizzi cluster create + my-awesome-name. + + --k8s-version= + Specify which version of the Kubernetes API to use when creating + the cluster, formatted as [MAJOR].[MINOR]. Defaults to 1.27. + Minor versions point to the latest release of the corresponding k3s + minor version. See https://github.com/k3s-io/k3s/releases --kubeconfig="/path/to/your/kubeconfig" Path to kubeconfig file From 54941fde439ea3bbcd455b9158d93a7aba3e2e51 Mon Sep 17 00:00:00 2001 From: Lidia Mokevnina Date: Mon, 9 Oct 2023 18:08:20 +0200 Subject: [PATCH 2/4] [346] removed k8s_version validation --- lib/uffizzi/cli/cluster.rb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/uffizzi/cli/cluster.rb b/lib/uffizzi/cli/cluster.rb index 8b1945f7..0f60b274 100644 --- a/lib/uffizzi/cli/cluster.rb +++ b/lib/uffizzi/cli/cluster.rb @@ -12,7 +12,6 @@ require 'uffizzi/services/cluster/disconnect_service' MANUAL = 'manual' -DEFAULT_K8S_VERSION = '1.27' module Uffizzi class Cli::Cluster < Thor @@ -118,8 +117,7 @@ def handle_create_command(project_slug, command_args) cluster_name = command_args[:name] || options[:name] || ClusterService.generate_name creation_source = options[:"creation-source"] || MANUAL - k8s_version = options[:k8s_version] || DEFAULT_K8S_VERSION - Uffizzi.ui.say_error_and_exit('k8s version should be formatted as [MAJOR].[MINOR].') unless valid_k8s_version?(k8s_version) + k8s_version = options[:k8s_version] Uffizzi.ui.say_error_and_exit("Cluster name: #{cluster_name} is not valid.") unless ClusterService.valid_name?(cluster_name) params = cluster_creation_params( @@ -405,9 +403,5 @@ def save_previous_current_context(kubeconfig_path, current_context) previous_current_contexts = Uffizzi::ConfigHelper.set_previous_current_context_by_path(kubeconfig_path, current_context) ConfigFile.write_option(:previous_current_contexts, previous_current_contexts) end - - def valid_k8s_version?(version) - ['1.28', '1.27', '1.26'].include?(version) - end end end From cd4909e15131a06423afd3e87557d9767e438b94 Mon Sep 17 00:00:00 2001 From: Lidia Mokevnina Date: Tue, 10 Oct 2023 11:17:13 +0200 Subject: [PATCH 3/4] [346] fixed getting the version option --- lib/uffizzi/cli/cluster.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/uffizzi/cli/cluster.rb b/lib/uffizzi/cli/cluster.rb index 0f60b274..b38460d5 100644 --- a/lib/uffizzi/cli/cluster.rb +++ b/lib/uffizzi/cli/cluster.rb @@ -32,7 +32,7 @@ def list method_option :'update-current-context', type: :boolean, required: false, default: true method_option :output, required: false, type: :string, aliases: '-o', enum: ['json', 'pretty-json'] method_option :'creation-source', required: false, type: :string - method_option :'k8s-version', required: false, type: :string, default: '1.27' + method_option :'k8s-version', required: false, type: :string def create(name = nil) run('create', { name: name }) end @@ -117,7 +117,7 @@ def handle_create_command(project_slug, command_args) cluster_name = command_args[:name] || options[:name] || ClusterService.generate_name creation_source = options[:"creation-source"] || MANUAL - k8s_version = options[:k8s_version] + k8s_version = options[:"k8s-version"] Uffizzi.ui.say_error_and_exit("Cluster name: #{cluster_name} is not valid.") unless ClusterService.valid_name?(cluster_name) params = cluster_creation_params( @@ -309,6 +309,7 @@ def handle_succeed_describe(cluster_data) status: cluster_data[:state], created: Time.strptime(cluster_data[:created_at], '%Y-%m-%dT%H:%M:%S.%N').strftime('%a %b %d %H:%M:%S %Y'), url: cluster_data[:host], + k8s_version: cluster_data[:k8s_version], } rendered_cluster_data = if Uffizzi.ui.output_format.nil? From e3c7673d2a7556f0a2aa62ba8c24b061903cd132 Mon Sep 17 00:00:00 2001 From: Lidia Mokevnina Date: Wed, 11 Oct 2023 14:17:30 +0200 Subject: [PATCH 4/4] [346] added k8s version option to uffizzi dev --- lib/uffizzi/cli/cluster.rb | 4 +--- lib/uffizzi/cli/dev.rb | 12 ++++++++---- man/uffizzi-dev-start.ronn | 9 +++++---- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/lib/uffizzi/cli/cluster.rb b/lib/uffizzi/cli/cluster.rb index b38460d5..91b17ffd 100644 --- a/lib/uffizzi/cli/cluster.rb +++ b/lib/uffizzi/cli/cluster.rb @@ -11,8 +11,6 @@ require 'uffizzi/services/kubeconfig_service' require 'uffizzi/services/cluster/disconnect_service' -MANUAL = 'manual' - module Uffizzi class Cli::Cluster < Thor class Error < StandardError; end @@ -116,7 +114,7 @@ def handle_create_command(project_slug, command_args) end cluster_name = command_args[:name] || options[:name] || ClusterService.generate_name - creation_source = options[:"creation-source"] || MANUAL + creation_source = options[:"creation-source"] || ClusterService::MANUAL_CREATION_SOURCE k8s_version = options[:"k8s-version"] Uffizzi.ui.say_error_and_exit("Cluster name: #{cluster_name} is not valid.") unless ClusterService.valid_name?(cluster_name) diff --git a/lib/uffizzi/cli/dev.rb b/lib/uffizzi/cli/dev.rb index a41bbdb0..1395781d 100644 --- a/lib/uffizzi/cli/dev.rb +++ b/lib/uffizzi/cli/dev.rb @@ -13,6 +13,7 @@ class Cli::Dev < Thor method_option :quiet, type: :boolean, aliases: :q method_option :'default-repo', type: :string method_option :kubeconfig, type: :string + method_option :'k8s-version', required: false, type: :string def start(config_path = 'skaffold.yaml') DevService.check_skaffold_existence DevService.check_running_daemon if options[:quiet] @@ -55,9 +56,11 @@ def check_login end def start_create_cluster - cluster_name = ClusterService.generate_name - creation_source = ClusterService::MANUAL_CREATION_SOURCE - params = cluster_creation_params(cluster_name, creation_source) + params = cluster_creation_params( + name: ClusterService.generate_name, + creation_source: ClusterService::MANUAL_CREATION_SOURCE, + k8s_version: options[:"k8s-version"], + ) Uffizzi.ui.say('Start creating a cluster') response = create_cluster(ConfigFile.read_option(:server), project_slug, params) return ResponseHelper.handle_failed_response(response) unless ResponseHelper.created?(response) @@ -110,7 +113,7 @@ def update_clusters_config(id, params) ConfigFile.write_option(:clusters, clusters_config) end - def cluster_creation_params(name, creation_source) + def cluster_creation_params(name:, creation_source:, k8s_version:) oidc_token = Uffizzi::ConfigFile.read_option(:oidc_token) { @@ -118,6 +121,7 @@ def cluster_creation_params(name, creation_source) name: name, manifest: nil, creation_source: creation_source, + k8s_version: k8s_version, }, token: oidc_token, } diff --git a/man/uffizzi-dev-start.ronn b/man/uffizzi-dev-start.ronn index 59e510c4..35b5c02a 100644 --- a/man/uffizzi-dev-start.ronn +++ b/man/uffizzi-dev-start.ronn @@ -31,10 +31,11 @@ uffizzi-dev-start - start a development environment Currently supports skaffold.yaml files. ## FLAGS - --build="" - This option specifies whether to build images on the - local environment or on the remote Uffizzi cluster. - Possible values are "local" or "remote". + --k8s-version= + Specify which version of the Kubernetes API to use when creating + the cluster, formatted as [MAJOR].[MINOR]. Defaults to 1.27. + Minor versions point to the latest release of the corresponding k3s + minor version. See https://github.com/k3s-io/k3s/releases --default-repo="" A public or private repo used to push/pull build