Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
lidiamokevnina committed Apr 2, 2024
2 parents 0eccfe0 + d6562bd commit da4e9db
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
uffizzi-cli (2.4.8)
uffizzi-cli (2.4.9)
activesupport
awesome_print
faker
Expand Down
28 changes: 2 additions & 26 deletions lib/uffizzi/cli/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def build_installation_options(uri)
end

def wait_ip
spinner = TTY::Spinner.new('[:spinner] Waiting IP addess...', format: :dots)
spinner = TTY::Spinner.new('[:spinner] Waiting on IP address...', format: :dots)
spinner.auto_spin

ip = nil
Expand All @@ -82,7 +82,7 @@ def wait_ip
ip = InstallService.get_controller_ip(namespace)
break if ip.present?

if try == 30
if try == 90
spinner.error

return 'unknown'
Expand All @@ -97,29 +97,6 @@ def wait_ip
ip
end

def wait_certificate_request_ready(uri)
spinner = TTY::Spinner.new('[:spinner] Waiting create certificate for controller host...', format: :dots)
spinner.auto_spin

try = 0

loop do
requests = InstallService.get_certificate_request(namespace, uri)
break if requests.all? { |r| r['status'].downcase == 'true' }

if try == 60
spinner.error

return Uffizzi.ui.say('Stop waiting creation certificate')
end

try += 1
sleep(2)
end

spinner.success
end

def build_helm_values(params)
{
global: {
Expand Down Expand Up @@ -220,7 +197,6 @@ def build_controller_setting_params(uri, installation_options)

def say_success(uri)
ip_address = wait_ip
wait_certificate_request_ready(uri)

msg = 'Your Uffizzi controller is ready. To configure DNS,'\
" create a record for the hostname '*.#{uri.host}' pointing to '#{ip_address}'"
Expand Down
4 changes: 2 additions & 2 deletions lib/uffizzi/cli/uninstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Cli::Uninstall < Thor
default_task :controller

desc 'controller [HOSTNAME]', 'Install uffizzi controller to cluster'
method_option :namespace, type: :string
method_option :namespace, type: :string, aliases: '-n'
method_option :context, type: :string
def controller
Uffizzi::AuthHelper.check_login
Expand Down Expand Up @@ -86,7 +86,7 @@ def unset_account_installation
end

def namespace
options[:namespace] || InstallService::DEFAULT_NAMESPACE
options[:namespace] || InstallService.current_namespace
end

def server
Expand Down
19 changes: 8 additions & 11 deletions lib/uffizzi/services/install_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,6 @@ def get_controller_ip(namespace)
load_balancers.map { |i| i['ip'] }[0]
end

def get_certificate_request(namespace, uri)
cmd = "kubectl get certificaterequests -n #{namespace} -o json"
res = execute_command(cmd, say: false)
certificate_request = JSON.parse(res)['items'].detect { |i| i['metadata']['name'].include?(uri.host) }

return [] if certificate_request.nil?

conditions = certificate_request.dig('status', 'conditions') || []
conditions.map { |c| c.slice('type', 'status') }
end

def build_controller_host(host)
[DEFAULT_CONTROLLER_DOMAIN_PREFIX, host].join('.')
end
Expand All @@ -130,6 +119,14 @@ def helm_values_dir_path
File.dirname(Uffizzi::ConfigFile.config_path)
end

def current_namespace
path = KubeconfigService.default_path
kubeconfig = KubeconfigService.read_kubeconfig(path)
return if kubeconfig.nil?

KubeconfigService.get_current_namespace(kubeconfig) || DEFAULT_NAMESPACE
end

private

def execute_command(command, say: true, skip_error: false)
Expand Down
6 changes: 6 additions & 0 deletions lib/uffizzi/services/kubeconfig_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ def get_current_cluster_name(kubeconfig)
.dig('context', 'cluster')
end

def get_current_namespace(kubeconfig)
get_cluster_contexts(kubeconfig)
.detect { |c| c['name'] == get_current_context(kubeconfig) }
.dig('context', 'namespace')
end

def get_cluster_contexts(kubeconfig)
kubeconfig.fetch('contexts', [])
end
Expand Down
2 changes: 1 addition & 1 deletion lib/uffizzi/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Uffizzi
VERSION = '2.4.8'
VERSION = '2.4.9'
end

0 comments on commit da4e9db

Please sign in to comment.