Skip to content

Commit

Permalink
[343] Fix after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
zipofar committed Oct 19, 2023
1 parent 4de63e9 commit 1e24815
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/uffizzi/auth_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 10 additions & 9 deletions lib/uffizzi/cli/cluster.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def wake(name = nil)
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'
Expand Down Expand Up @@ -124,16 +123,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)
Expand Down Expand Up @@ -211,7 +207,8 @@ def handle_delete_cluster(cluster_name)

def handle_update_kubeconfig_command(command_args)
kubeconfig_path = options[:kubeconfig] || KubeconfigService.default_path
cluster_data = ClusterService.fetch_cluster_data(command_args[:cluster_name], **cluster_api_connection_params)
cluster_name = command_args[:cluster_name]
cluster_data = ClusterService.fetch_cluster_data(cluster_name, **cluster_api_connection_params)

unless cluster_data[:kubeconfig].present?
say_error_update_kubeconfig(cluster_data)
Expand Down Expand Up @@ -289,11 +286,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,
Expand Down Expand Up @@ -438,7 +439,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
Expand Down
18 changes: 7 additions & 11 deletions lib/uffizzi/cli/dev.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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?
Expand All @@ -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)
Expand Down Expand Up @@ -129,13 +125,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,
}
Expand Down

0 comments on commit 1e24815

Please sign in to comment.