From ca9415d9d6977c0b4b6d8ab0ac886d47af9b80ae Mon Sep 17 00:00:00 2001 From: Zipofar Date: Mon, 16 Oct 2023 15:50:09 +0300 Subject: [PATCH] [343] Fix after rebase --- lib/uffizzi/auth_helper.rb | 2 +- lib/uffizzi/cli/cluster.rb | 16 ++++++++-------- lib/uffizzi/cli/dev.rb | 18 +++++++----------- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/lib/uffizzi/auth_helper.rb b/lib/uffizzi/auth_helper.rb index b35e1fe9..37204b55 100644 --- a/lib/uffizzi/auth_helper.rb +++ b/lib/uffizzi/auth_helper.rb @@ -16,7 +16,7 @@ def sign_out Uffizzi::Token.delete if Uffizzi::Token.exists? end - def check_login(project_option) + def check_login(project_option = nil) raise Uffizzi::Error.new('You are not logged in. Run `uffizzi login`.') unless signed_in? raise Uffizzi::Error.new('This command needs project to be set in config file') unless project_set?(project_option) end diff --git a/lib/uffizzi/cli/cluster.rb b/lib/uffizzi/cli/cluster.rb index bc25eae9..32e51ca7 100644 --- a/lib/uffizzi/cli/cluster.rb +++ b/lib/uffizzi/cli/cluster.rb @@ -66,7 +66,6 @@ def disconnect def run(command, command_args = {}) Uffizzi.ui.output_format = options[:output] Uffizzi::AuthHelper.check_login(options[:project]) - project_slug = options[:project].nil? ? ConfigFile.read_option(:project) : options[:project] case command when 'list' @@ -110,16 +109,13 @@ def handle_create_command(command_args) end cluster_name = command_args[:name] || options[:name] || ClusterService.generate_name - 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) 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) + params = cluster_creation_params(cluster_name) response = create_cluster(server, project_slug, params) return ResponseHelper.handle_failed_response(response) unless ResponseHelper.created?(response) @@ -240,11 +236,15 @@ def say_error_update_kubeconfig(cluster_data) end end - def cluster_creation_params(name:, creation_source:, manifest_file_path:, k8s_version:) + def cluster_creation_params(cluster_name) + creation_source = options[:"creation-source"] || ClusterService::MANUAL_CREATION_SOURCE + manifest_file_path = options[:manifest] + k8s_version = options[:"k8s-version"] manifest_content = load_manifest_file(manifest_file_path) + { cluster: { - name: name, + name: cluster_name, manifest: manifest_content, creation_source: creation_source, k8s_version: k8s_version, @@ -381,7 +381,7 @@ def oidc_token end def project_slug - @project_slug ||= ConfigFile.read_option(:project) + @project_slug ||= options[:project].nil? ? ConfigFile.read_option(:project) : options[:project] end def server diff --git a/lib/uffizzi/cli/dev.rb b/lib/uffizzi/cli/dev.rb index d0022a33..b9f21559 100644 --- a/lib/uffizzi/cli/dev.rb +++ b/lib/uffizzi/cli/dev.rb @@ -15,7 +15,7 @@ class Cli::Dev < Thor method_option :kubeconfig, type: :string method_option :'k8s-version', required: false, type: :string def start(config_path = 'skaffold.yaml') - Uffizzi::AuthHelper.check_login(options[:project]) + Uffizzi::AuthHelper.check_login DevService.check_skaffold_existence DevService.check_running_daemon if options[:quiet] DevService.check_skaffold_config_existence(config_path) @@ -52,7 +52,7 @@ def stop desc 'describe [NAME]', 'Describe dev environment' def describe(name = nil) - check_login + Uffizzi::AuthHelper.check_login dev_environment = get_dev_environment(name) if dev_environment.nil? @@ -71,11 +71,7 @@ def describe(name = nil) private def start_create_cluster - params = cluster_creation_params( - name: ClusterService.generate_name, - creation_source: ClusterService::MANUAL_CREATION_SOURCE, - k8s_version: options[:"k8s-version"], - ) + params = cluster_creation_params Uffizzi.ui.say('Start creating a cluster') response = create_cluster(server, project_slug, params) return ResponseHelper.handle_failed_response(response) unless ResponseHelper.created?(response) @@ -128,13 +124,13 @@ def update_clusters_config(id, params) ConfigFile.write_option(:clusters, clusters_config) end - def cluster_creation_params(name, creation_source) + def cluster_creation_params { cluster: { - name: name, + name: ClusterService.generate_name, manifest: nil, - creation_source: creation_source, - k8s_version: k8s_version, + creation_source: ClusterService::MANUAL_CREATION_SOURCE, + k8s_version: options[:"k8s-version"], }, token: oidc_token, }