From 982b77719d6f23a04d1fee642eddfab82c0f4e56 Mon Sep 17 00:00:00 2001 From: Lidia Mokevnina Date: Mon, 9 Oct 2023 11:26:07 +0200 Subject: [PATCH 1/8] [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/8] [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/8] [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 ec9fdc1f0335c0114f972268a856ad0ebb5b9386 Mon Sep 17 00:00:00 2001 From: Lidia Mokevnina Date: Wed, 11 Oct 2023 12:39:42 +0200 Subject: [PATCH 4/8] [347] improved auth logic --- lib/uffizzi/auth_helper.rb | 18 ++++++++++++++---- lib/uffizzi/cli/account.rb | 2 +- lib/uffizzi/cli/cluster.rb | 8 ++++---- lib/uffizzi/cli/dev.rb | 8 ++------ lib/uffizzi/cli/preview.rb | 3 +-- lib/uffizzi/cli/preview/service.rb | 6 ++---- lib/uffizzi/cli/project.rb | 2 +- lib/uffizzi/cli/project/compose.rb | 3 +-- 8 files changed, 26 insertions(+), 24 deletions(-) diff --git a/lib/uffizzi/auth_helper.rb b/lib/uffizzi/auth_helper.rb index 91f20a3b..0d3d5d1a 100644 --- a/lib/uffizzi/auth_helper.rb +++ b/lib/uffizzi/auth_helper.rb @@ -4,7 +4,7 @@ module Uffizzi module AuthHelper class << self def signed_in? - config_data_exists? || Uffizzi::Token.exists? + config_data_exists? && authorized? end def sign_out @@ -16,13 +16,23 @@ def sign_out Uffizzi::Token.delete if Uffizzi::Token.exists? end + def check_login(options = nil) + raise Uffizzi::Error.new('You are not logged in. Run `uffizzi login`.') unless signed_in? + return unless options + + raise Uffizzi::Error.new('This command needs project to be set in config file') unless CommandService.project_set?(options) + end + private def config_data_exists? ConfigFile.exists? && - ConfigFile.option_has_value?(:account) && - ConfigFile.option_has_value?(:cookie) && - ConfigFile.option_has_value?(:server) + ConfigFile.option_has_value?(:server) && + ConfigFile.option_has_value?(:account) + end + + def authorized? + ConfigFile.option_has_value?(:cookie) || Uffizzi::Token.exists? end end end diff --git a/lib/uffizzi/cli/account.rb b/lib/uffizzi/cli/account.rb index a99ffc17..0012810e 100644 --- a/lib/uffizzi/cli/account.rb +++ b/lib/uffizzi/cli/account.rb @@ -25,7 +25,7 @@ def set_default(account_name) private def run(command, account_name = nil) - return Uffizzi.ui.say('You are not logged in.') unless Uffizzi::AuthHelper.signed_in? + Uffizzi::AuthHelper.check_login case command when 'list' diff --git a/lib/uffizzi/cli/cluster.rb b/lib/uffizzi/cli/cluster.rb index 02bbd31f..9677ca72 100644 --- a/lib/uffizzi/cli/cluster.rb +++ b/lib/uffizzi/cli/cluster.rb @@ -10,6 +10,7 @@ require 'uffizzi/services/cluster_service' require 'uffizzi/services/kubeconfig_service' require 'uffizzi/services/cluster/disconnect_service' +require 'byebug' module Uffizzi class Cli::Cluster < Thor @@ -65,9 +66,7 @@ def disconnect def run(command, command_args = {}) Uffizzi.ui.output_format = options[:output] - raise Uffizzi::Error.new('You are not logged in.') unless Uffizzi::AuthHelper.signed_in? - raise Uffizzi::Error.new('This command needs project to be set in config file') unless CommandService.project_set?(options) - + Uffizzi::AuthHelper.check_login(options) project_slug = options[:project].nil? ? ConfigFile.read_option(:project) : options[:project] case command @@ -335,7 +334,6 @@ def handle_succeed_create_response(cluster_data) end def save_kubeconfig(kubeconfig, kubeconfig_path) - kubeconfig_path = kubeconfig_path.nil? ? KubeconfigService.default_path : kubeconfig_path is_update_current_context = options[:'update-current-context'] KubeconfigService.save_to_filepath(kubeconfig_path, kubeconfig) do |kubeconfig_by_path| @@ -354,6 +352,8 @@ def save_kubeconfig(kubeconfig, kubeconfig_path) merged_kubeconfig end end + + Uffizzi.ui.say("Kubeconfig was updated by the path: #{kubeconfig_path}") if is_update_current_context end def update_clusters_config(id, params) diff --git a/lib/uffizzi/cli/dev.rb b/lib/uffizzi/cli/dev.rb index a41bbdb0..eea4a628 100644 --- a/lib/uffizzi/cli/dev.rb +++ b/lib/uffizzi/cli/dev.rb @@ -4,6 +4,7 @@ require 'uffizzi/services/cluster_service' require 'uffizzi/services/dev_service' require 'uffizzi/services/kubeconfig_service' +require 'uffizzi/auth_helper' module Uffizzi class Cli::Dev < Thor @@ -14,10 +15,10 @@ class Cli::Dev < Thor method_option :'default-repo', type: :string method_option :kubeconfig, type: :string def start(config_path = 'skaffold.yaml') + Uffizzi::AuthHelper.check_login(options) DevService.check_skaffold_existence DevService.check_running_daemon if options[:quiet] DevService.check_skaffold_config_existence(config_path) - check_login cluster_id, cluster_name = start_create_cluster kubeconfig = wait_cluster_creation(cluster_name) @@ -49,11 +50,6 @@ def stop private - def check_login - raise Uffizzi::Error.new('You are not logged in.') unless Uffizzi::AuthHelper.signed_in? - raise Uffizzi::Error.new('This command needs project to be set in config file') unless CommandService.project_set?(options) - end - def start_create_cluster cluster_name = ClusterService.generate_name creation_source = ClusterService::MANUAL_CREATION_SOURCE diff --git a/lib/uffizzi/cli/preview.rb b/lib/uffizzi/cli/preview.rb index edc6c198..77ec38d9 100644 --- a/lib/uffizzi/cli/preview.rb +++ b/lib/uffizzi/cli/preview.rb @@ -55,8 +55,7 @@ def events(deployment_name) def run(command, file_path: nil, deployment_name: nil) Uffizzi.ui.output_format = options[:output] - raise Uffizzi::Error.new('You are not logged in.') unless Uffizzi::AuthHelper.signed_in? - raise Uffizzi::Error.new('This command needs project to be set in config file') unless CommandService.project_set?(options) + Uffizzi::AuthHelper.check_login(options) project_slug = options[:project].nil? ? ConfigFile.read_option(:project) : options[:project] diff --git a/lib/uffizzi/cli/preview/service.rb b/lib/uffizzi/cli/preview/service.rb index a65b3199..d22699ae 100644 --- a/lib/uffizzi/cli/preview/service.rb +++ b/lib/uffizzi/cli/preview/service.rb @@ -12,8 +12,7 @@ class Cli::Preview::Service < Thor desc 'logs [LOGS_TYPE] [DEPLOYMENT_ID] [CONTAINER_NAME]', 'Show the logs for a container service of a preview' def logs(logs_type, deployment_name, container_name = args) - return Uffizzi.ui.say('You are not logged in.') unless Uffizzi::AuthHelper.signed_in? - return Uffizzi.ui.say('This command needs project to be set in config file') unless CommandService.project_set?(options) + Uffizzi::AuthHelper.check_login(options) deployment_id = PreviewService.read_deployment_id(deployment_name) response = service_logs_response(logs_type, deployment_id, container_name) @@ -28,8 +27,7 @@ def logs(logs_type, deployment_name, container_name = args) desc 'list [DEPLOYMENT_ID]', 'List the container services of a given compose environment (preview)' def list(deployment_name) - return Uffizzi.ui.say('You are not logged in.') unless Uffizzi::AuthHelper.signed_in? - return Uffizzi.ui.say('This command needs project to be set in config file') unless CommandService.project_set?(options) + Uffizzi::AuthHelper.check_login(options) project_slug = options[:project].nil? ? ConfigFile.read_option(:project) : options[:project] server = ConfigFile.read_option(:server) diff --git a/lib/uffizzi/cli/project.rb b/lib/uffizzi/cli/project.rb index 4652a2df..40725d6a 100644 --- a/lib/uffizzi/cli/project.rb +++ b/lib/uffizzi/cli/project.rb @@ -55,7 +55,7 @@ def delete(project_slug) private def run(command, project_slug: nil) - return Uffizzi.ui.say('You are not logged in.') unless Uffizzi::AuthHelper.signed_in? + Uffizzi::AuthHelper.check_login case command when 'list' diff --git a/lib/uffizzi/cli/project/compose.rb b/lib/uffizzi/cli/project/compose.rb index 66771989..63736316 100644 --- a/lib/uffizzi/cli/project/compose.rb +++ b/lib/uffizzi/cli/project/compose.rb @@ -29,8 +29,7 @@ def describe private def run(command) - return Uffizzi.ui.say('You are not logged in.') unless Uffizzi::AuthHelper.signed_in? - return Uffizzi.ui.say('This command needs project to be set in config file') unless CommandService.project_set?(options) + Uffizzi::AuthHelper.check_login(options) project_slug = options[:project].nil? ? ConfigFile.read_option(:project) : options[:project] file_path = options[:file] From 5e23b7a7b5568500e22e34bea994a9fd2c6f1aa5 Mon Sep 17 00:00:00 2001 From: Lidia Mokevnina Date: Wed, 11 Oct 2023 12:55:24 +0200 Subject: [PATCH 5/8] [347] removed byebug import --- lib/uffizzi/cli/cluster.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/uffizzi/cli/cluster.rb b/lib/uffizzi/cli/cluster.rb index 9677ca72..47a50934 100644 --- a/lib/uffizzi/cli/cluster.rb +++ b/lib/uffizzi/cli/cluster.rb @@ -10,7 +10,6 @@ require 'uffizzi/services/cluster_service' require 'uffizzi/services/kubeconfig_service' require 'uffizzi/services/cluster/disconnect_service' -require 'byebug' module Uffizzi class Cli::Cluster < Thor From ccff663d8a137eb2df9d439f372e0f7654a29130 Mon Sep 17 00:00:00 2001 From: Lidia Mokevnina Date: Wed, 11 Oct 2023 14:05:09 +0200 Subject: [PATCH 6/8] [347] made project config required for account and project commands --- lib/uffizzi/auth_helper.rb | 10 ++++++---- lib/uffizzi/cli/account.rb | 2 +- lib/uffizzi/cli/cluster.rb | 3 +-- lib/uffizzi/cli/dev.rb | 3 +-- lib/uffizzi/cli/preview.rb | 3 +-- lib/uffizzi/cli/preview/service.rb | 5 ++--- lib/uffizzi/cli/project.rb | 2 +- lib/uffizzi/cli/project/compose.rb | 3 +-- lib/uffizzi/services/command_service.rb | 9 --------- test/uffizzi/cli/account_test.rb | 1 + test/uffizzi/cli/cluster_test.rb | 2 +- test/uffizzi/cli/dev_test.rb | 2 +- test/uffizzi/cli/preview/service_test.rb | 2 +- test/uffizzi/cli/preview_test.rb | 2 +- test/uffizzi/cli/project/compose_test.rb | 2 +- test/uffizzi/cli/project_test.rb | 1 + 16 files changed, 21 insertions(+), 31 deletions(-) delete mode 100644 lib/uffizzi/services/command_service.rb diff --git a/lib/uffizzi/auth_helper.rb b/lib/uffizzi/auth_helper.rb index 0d3d5d1a..b35e1fe9 100644 --- a/lib/uffizzi/auth_helper.rb +++ b/lib/uffizzi/auth_helper.rb @@ -16,11 +16,9 @@ def sign_out Uffizzi::Token.delete if Uffizzi::Token.exists? end - def check_login(options = nil) + def check_login(project_option) raise Uffizzi::Error.new('You are not logged in. Run `uffizzi login`.') unless signed_in? - return unless options - - raise Uffizzi::Error.new('This command needs project to be set in config file') unless CommandService.project_set?(options) + raise Uffizzi::Error.new('This command needs project to be set in config file') unless project_set?(project_option) end private @@ -34,6 +32,10 @@ def config_data_exists? def authorized? ConfigFile.option_has_value?(:cookie) || Uffizzi::Token.exists? end + + def project_set?(project_option) + !project_option.nil? || (Uffizzi::ConfigFile.exists? && Uffizzi::ConfigFile.option_has_value?(:project)) + end end end end diff --git a/lib/uffizzi/cli/account.rb b/lib/uffizzi/cli/account.rb index 0012810e..5b3f0dc5 100644 --- a/lib/uffizzi/cli/account.rb +++ b/lib/uffizzi/cli/account.rb @@ -25,7 +25,7 @@ def set_default(account_name) private def run(command, account_name = nil) - Uffizzi::AuthHelper.check_login + Uffizzi::AuthHelper.check_login(options[:project]) case command when 'list' diff --git a/lib/uffizzi/cli/cluster.rb b/lib/uffizzi/cli/cluster.rb index 47a50934..2b95e2cd 100644 --- a/lib/uffizzi/cli/cluster.rb +++ b/lib/uffizzi/cli/cluster.rb @@ -6,7 +6,6 @@ require 'uffizzi/auth_helper' require 'uffizzi/helpers/config_helper' require 'uffizzi/services/preview_service' -require 'uffizzi/services/command_service' require 'uffizzi/services/cluster_service' require 'uffizzi/services/kubeconfig_service' require 'uffizzi/services/cluster/disconnect_service' @@ -65,7 +64,7 @@ def disconnect def run(command, command_args = {}) Uffizzi.ui.output_format = options[:output] - Uffizzi::AuthHelper.check_login(options) + Uffizzi::AuthHelper.check_login(options[:project]) project_slug = options[:project].nil? ? ConfigFile.read_option(:project) : options[:project] case command diff --git a/lib/uffizzi/cli/dev.rb b/lib/uffizzi/cli/dev.rb index eea4a628..2a5a577c 100644 --- a/lib/uffizzi/cli/dev.rb +++ b/lib/uffizzi/cli/dev.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require 'uffizzi/services/command_service' require 'uffizzi/services/cluster_service' require 'uffizzi/services/dev_service' require 'uffizzi/services/kubeconfig_service' @@ -15,7 +14,7 @@ class Cli::Dev < Thor method_option :'default-repo', type: :string method_option :kubeconfig, type: :string def start(config_path = 'skaffold.yaml') - Uffizzi::AuthHelper.check_login(options) + Uffizzi::AuthHelper.check_login(options[:project]) DevService.check_skaffold_existence DevService.check_running_daemon if options[:quiet] DevService.check_skaffold_config_existence(config_path) diff --git a/lib/uffizzi/cli/preview.rb b/lib/uffizzi/cli/preview.rb index 77ec38d9..c7963ed6 100644 --- a/lib/uffizzi/cli/preview.rb +++ b/lib/uffizzi/cli/preview.rb @@ -3,7 +3,6 @@ require 'uffizzi' require 'uffizzi/auth_helper' require 'uffizzi/services/preview_service' -require 'uffizzi/services/command_service' require 'uffizzi/services/github_service' module Uffizzi @@ -55,7 +54,7 @@ def events(deployment_name) def run(command, file_path: nil, deployment_name: nil) Uffizzi.ui.output_format = options[:output] - Uffizzi::AuthHelper.check_login(options) + Uffizzi::AuthHelper.check_login(options[:project]) project_slug = options[:project].nil? ? ConfigFile.read_option(:project) : options[:project] diff --git a/lib/uffizzi/cli/preview/service.rb b/lib/uffizzi/cli/preview/service.rb index d22699ae..d8520e99 100644 --- a/lib/uffizzi/cli/preview/service.rb +++ b/lib/uffizzi/cli/preview/service.rb @@ -4,7 +4,6 @@ require 'uffizzi/auth_helper' require 'uffizzi/response_helper' require 'uffizzi/services/preview_service' -require 'uffizzi/services/command_service' module Uffizzi class Cli::Preview::Service < Thor @@ -12,7 +11,7 @@ class Cli::Preview::Service < Thor desc 'logs [LOGS_TYPE] [DEPLOYMENT_ID] [CONTAINER_NAME]', 'Show the logs for a container service of a preview' def logs(logs_type, deployment_name, container_name = args) - Uffizzi::AuthHelper.check_login(options) + Uffizzi::AuthHelper.check_login(options[:project]) deployment_id = PreviewService.read_deployment_id(deployment_name) response = service_logs_response(logs_type, deployment_id, container_name) @@ -27,7 +26,7 @@ def logs(logs_type, deployment_name, container_name = args) desc 'list [DEPLOYMENT_ID]', 'List the container services of a given compose environment (preview)' def list(deployment_name) - Uffizzi::AuthHelper.check_login(options) + Uffizzi::AuthHelper.check_login(options[:project]) project_slug = options[:project].nil? ? ConfigFile.read_option(:project) : options[:project] server = ConfigFile.read_option(:server) diff --git a/lib/uffizzi/cli/project.rb b/lib/uffizzi/cli/project.rb index 40725d6a..fc23347a 100644 --- a/lib/uffizzi/cli/project.rb +++ b/lib/uffizzi/cli/project.rb @@ -55,7 +55,7 @@ def delete(project_slug) private def run(command, project_slug: nil) - Uffizzi::AuthHelper.check_login + Uffizzi::AuthHelper.check_login(options[:project]) case command when 'list' diff --git a/lib/uffizzi/cli/project/compose.rb b/lib/uffizzi/cli/project/compose.rb index 63736316..a73b2f96 100644 --- a/lib/uffizzi/cli/project/compose.rb +++ b/lib/uffizzi/cli/project/compose.rb @@ -5,7 +5,6 @@ require 'uffizzi/response_helper' require 'uffizzi/services/compose_file_service' require 'uffizzi/services/env_variables_service' -require 'uffizzi/services/command_service' module Uffizzi class Cli::Project::Compose < Thor @@ -29,7 +28,7 @@ def describe private def run(command) - Uffizzi::AuthHelper.check_login(options) + Uffizzi::AuthHelper.check_login(options[:project]) project_slug = options[:project].nil? ? ConfigFile.read_option(:project) : options[:project] file_path = options[:file] diff --git a/lib/uffizzi/services/command_service.rb b/lib/uffizzi/services/command_service.rb deleted file mode 100644 index 34de4736..00000000 --- a/lib/uffizzi/services/command_service.rb +++ /dev/null @@ -1,9 +0,0 @@ -# frozen_string_literal: true - -class CommandService - class << self - def project_set?(options) - !options[:project].nil? || (Uffizzi::ConfigFile.exists? && Uffizzi::ConfigFile.option_has_value?(:project)) - end - end -end diff --git a/test/uffizzi/cli/account_test.rb b/test/uffizzi/cli/account_test.rb index 460c43f6..ef782697 100644 --- a/test/uffizzi/cli/account_test.rb +++ b/test/uffizzi/cli/account_test.rb @@ -5,6 +5,7 @@ class AccountTest < Minitest::Test def setup @account = Uffizzi::Cli::Account.new + Uffizzi::ConfigFile.write_option(:project, 'uffizzi') sign_in end diff --git a/test/uffizzi/cli/cluster_test.rb b/test/uffizzi/cli/cluster_test.rb index ab2ce473..b40d04bf 100644 --- a/test/uffizzi/cli/cluster_test.rb +++ b/test/uffizzi/cli/cluster_test.rb @@ -11,7 +11,7 @@ def setup Uffizzi.stubs(:prompt).returns(@mock_prompt) sign_in - Uffizzi::ConfigFile.write_option(:project, 'dbp') + Uffizzi::ConfigFile.write_option(:project, 'uffizzi') @project_slug = Uffizzi::ConfigFile.read_option(:project) ENV['GITHUB_OUTPUT'] = '/tmp/.env' ENV['GITHUB_ACTIONS'] = 'true' diff --git a/test/uffizzi/cli/dev_test.rb b/test/uffizzi/cli/dev_test.rb index 38775a73..d4153ed2 100644 --- a/test/uffizzi/cli/dev_test.rb +++ b/test/uffizzi/cli/dev_test.rb @@ -11,7 +11,7 @@ def setup Uffizzi.stubs(:prompt).returns(@mock_prompt) sign_in - Uffizzi::ConfigFile.write_option(:project, 'dbp') + Uffizzi::ConfigFile.write_option(:project, 'uffizzi') @project_slug = Uffizzi::ConfigFile.read_option(:project) tmp_dir_name = (Time.now.utc.to_f * 100_000).to_i @kubeconfig_path = "/tmp/test/#{tmp_dir_name}/test-kubeconfig.yaml" diff --git a/test/uffizzi/cli/preview/service_test.rb b/test/uffizzi/cli/preview/service_test.rb index 92f3d047..50c2c5be 100644 --- a/test/uffizzi/cli/preview/service_test.rb +++ b/test/uffizzi/cli/preview/service_test.rb @@ -7,7 +7,7 @@ def setup @service = Uffizzi::Cli::Preview::Service.new sign_in - Uffizzi::ConfigFile.write_option(:project, 'dbp') + Uffizzi::ConfigFile.write_option(:project, 'uffizzi') @project_slug = Uffizzi::ConfigFile.read_option(:project) end diff --git a/test/uffizzi/cli/preview_test.rb b/test/uffizzi/cli/preview_test.rb index 6b9ebfb1..eaca850b 100644 --- a/test/uffizzi/cli/preview_test.rb +++ b/test/uffizzi/cli/preview_test.rb @@ -7,7 +7,7 @@ def setup @preview = Uffizzi::Cli::Preview.new sign_in - Uffizzi::ConfigFile.write_option(:project, 'dbp') + Uffizzi::ConfigFile.write_option(:project, 'uffizzi') @project_slug = Uffizzi::ConfigFile.read_option(:project) ENV.delete('IMAGE') ENV.delete('CONFIG_SOURCE') diff --git a/test/uffizzi/cli/project/compose_test.rb b/test/uffizzi/cli/project/compose_test.rb index 0e8eb245..e41d382d 100644 --- a/test/uffizzi/cli/project/compose_test.rb +++ b/test/uffizzi/cli/project/compose_test.rb @@ -7,7 +7,7 @@ def setup @compose = Uffizzi::Cli::Project::Compose.new sign_in - Uffizzi::ConfigFile.write_option(:project, 'dbp') + Uffizzi::ConfigFile.write_option(:project, 'uffizzi') @project_slug = Uffizzi::ConfigFile.read_option(:project) ENV.delete('IMAGE') ENV.delete('CONFIG_SOURCE') diff --git a/test/uffizzi/cli/project_test.rb b/test/uffizzi/cli/project_test.rb index 50f1def0..bcea4b0a 100644 --- a/test/uffizzi/cli/project_test.rb +++ b/test/uffizzi/cli/project_test.rb @@ -5,6 +5,7 @@ class ProjectsTest < Minitest::Test def setup @project = Uffizzi::Cli::Project.new + Uffizzi::ConfigFile.write_option(:project, 'uffizzi') sign_in end From e3c7673d2a7556f0a2aa62ba8c24b061903cd132 Mon Sep 17 00:00:00 2001 From: Lidia Mokevnina Date: Wed, 11 Oct 2023 14:17:30 +0200 Subject: [PATCH 7/8] [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 From 50191080c9af3c2868de4615989d329cb5ce9420 Mon Sep 17 00:00:00 2001 From: Lidia Mokevnina Date: Mon, 16 Oct 2023 10:53:28 +0200 Subject: [PATCH 8/8] Change version to 2.1.3 --- Gemfile.lock | 2 +- lib/uffizzi/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 46589405..d0eaec85 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - uffizzi-cli (2.1.2) + uffizzi-cli (2.1.3) activesupport awesome_print faker diff --git a/lib/uffizzi/version.rb b/lib/uffizzi/version.rb index ee11e5f3..1d1e8b10 100644 --- a/lib/uffizzi/version.rb +++ b/lib/uffizzi/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Uffizzi - VERSION = '2.1.2' + VERSION = '2.1.3' end