Class: InstallService
- Inherits:
-
Object
show all
- Extended by:
- ApiClient
- Defined in:
- lib/uffizzi/services/install_service.rb
Constant Summary
collapse
- DEFAULT_HELM_RELEASE_NAME =
'uffizzi'
- INGRESS_NAME =
"#{DEFAULT_HELM_RELEASE_NAME}-controller"
- DEFAULT_HELM_REPO_NAME =
'uffizzi'
- DEFAULT_CONTROLLER_CHART_NAME =
'uffizzi-controller'
- HELM_DEPLOYED_STATUS =
'deployed'
- VALUES_FILE_NAME =
'helm_values.yaml'
- DEFAULT_NAMESPACE =
'default'
- DEFAULT_CLUSTER_ISSUER =
'letsencrypt'
- DEFAULT_CONTROLLER_REPO_URL =
'https://uffizzicloud.github.io/uffizzi_controller'
- DEFAULT_CONTROLLER_DOMAIN_PREFIX =
'controller'
Class Method Summary
collapse
Methods included from ApiClient
bulk_create_secrets, check_can_install, check_credential, create_access_token, create_account_controller_settings, create_ci_session, create_cluster, create_credential, create_deployment, create_project, create_session, delete_account_controller_settings, delete_cluster, delete_credential, delete_deployment, delete_project, delete_secret, deploy_containers, describe_compose_file, describe_deployment, destroy_session, fetch_account, fetch_account_projects, fetch_accounts, fetch_credentials, fetch_deployment_service_logs, fetch_deployment_services, fetch_deployments, fetch_events, fetch_project, fetch_projects, fetch_secrets, get_access_token, get_account_clusters, get_account_controller_settings, get_activity_items, get_cluster, get_cluster_ingresses, get_k8s_container_description, get_project_clusters, scale_down_cluster, scale_up_cluster, set_compose_file, sync_cluster, unset_compose_file, update_account, update_account_controller_settings, update_credential, update_deployment, validate_compose_file
Methods included from ApiRoutes
#access_token_url, #access_tokens_url, #account_can_install_uri, #account_clusters_uri, #account_controller_setting_uri, #account_controller_settings_uri, #account_projects_uri, #account_uri, #accounts_uri, #activity_items_uri, #browser_sign_in_url, #check_credential_uri, #ci_session_uri, #cluster_uri, #compose_file_uri, #create_projects_uri, #credential_uri, #credentials_uri, #deploy_containers_uri, #deployment_uri, #deployments_uri, #events_uri, #k8s_container_description_uri, #preview_service_logs_uri, #preview_services_uri, #project_cluster_ingresses_uri, #project_clusters_uri, #project_uri, #projects_uri, #scale_down_cluster_uri, #scale_up_cluster_uri, #secret_uri, #secrets_uri, #session_uri, #sync_cluster_uri, #validate_compose_file_uri
Class Method Details
.build_controller_host(host) ⇒ Object
.create_helm_values_file(values) ⇒ Object
112
113
114
115
|
# File 'lib/uffizzi/services/install_service.rb', line 112
def create_helm_values_file(values)
FileUtils.mkdir_p(helm_values_dir_path) unless File.directory?(helm_values_dir_path)
File.write(helm_values_file_path, values.to_yaml)
end
|
.current_namespace ⇒ Object
.delete_helm_values_file ⇒ Object
108
109
110
|
# File 'lib/uffizzi/services/install_service.rb', line 108
def delete_helm_values_file
File.delete(helm_values_file_path) if File.exist?(helm_values_file_path)
end
|
.get_controller_endpoint(namespace) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/uffizzi/services/install_service.rb', line 88
def get_controller_endpoint(namespace)
cmd = "kubectl get ingress -n #{namespace} -o json"
res = execute_command(cmd, say: false)
ingress = JSON.parse(res)['items'].detect { |i| i['metadata']['name'] = INGRESS_NAME }
return if ingress.blank?
load_balancers = ingress.dig('status', 'loadBalancer', 'ingress')
return if load_balancers.blank?
ip = load_balancers.map { |i| i['ip'] }[0]
return ip if ip.present?
load_balancers.map { |i| i['hostname'] }[0]
end
|
.helm_exists? ⇒ Boolean
26
27
28
29
|
# File 'lib/uffizzi/services/install_service.rb', line 26
def helm_exists?
cmd = 'helm version --short'
execute_command(cmd, say: false).present?
end
|
.helm_install!(namespace) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/uffizzi/services/install_service.rb', line 50
def helm_install!(namespace)
Uffizzi.ui.say('Start helm release installation')
repo = "#{DEFAULT_HELM_REPO_NAME}/#{DEFAULT_CONTROLLER_CHART_NAME}"
cmd = "helm upgrade #{DEFAULT_HELM_RELEASE_NAME} #{repo}" \
" --values #{helm_values_file_path}" \
" --namespace #{namespace}" \
' --create-namespace' \
' --install' \
' --output json'
res = execute_command(cmd, say: false)
info = JSON.parse(res)['info']
return if info['status'] == HELM_DEPLOYED_STATUS
Uffizzi.ui.say_error_and_exit(info)
end
|
.helm_repo_add(repo_url) ⇒ Object
.helm_repo_remove ⇒ Object
31
32
33
34
|
# File 'lib/uffizzi/services/install_service.rb', line 31
def helm_repo_remove
cmd = "helm repo remove #{DEFAULT_HELM_REPO_NAME}"
execute_command(cmd, skip_error: true)
end
|
.helm_repo_search ⇒ Object
36
37
38
39
40
41
42
|
# File 'lib/uffizzi/services/install_service.rb', line 36
def helm_repo_search
cmd = "helm search repo #{DEFAULT_HELM_REPO_NAME}/#{DEFAULT_CONTROLLER_CHART_NAME} -o json"
execute_command(cmd) do |result, err|
err.present? ? nil : JSON.parse(result)
end
end
|
.helm_uninstall!(namespace) ⇒ Object
69
70
71
72
73
74
75
|
# File 'lib/uffizzi/services/install_service.rb', line 69
def helm_uninstall!(namespace)
Uffizzi.ui.say('Start helm release uninstallation')
cmd = "helm uninstall #{DEFAULT_HELM_RELEASE_NAME} --namespace #{namespace}"
execute_command(cmd)
end
|
.helm_values_dir_path ⇒ Object
121
122
123
|
# File 'lib/uffizzi/services/install_service.rb', line 121
def helm_values_dir_path
File.dirname(Uffizzi::ConfigFile.config_path)
end
|
.helm_values_file_path ⇒ Object
117
118
119
|
# File 'lib/uffizzi/services/install_service.rb', line 117
def helm_values_file_path
File.join(helm_values_dir_path, VALUES_FILE_NAME)
end
|
.kubeconfig_current_context ⇒ Object
82
83
84
85
86
|
# File 'lib/uffizzi/services/install_service.rb', line 82
def kubeconfig_current_context
cmd = 'kubectl config current-context'
execute_command(cmd, say: false) { |stdout| stdout.present? && stdout.chop }
end
|
.kubectl_exists? ⇒ Boolean
21
22
23
24
|
# File 'lib/uffizzi/services/install_service.rb', line 21
def kubectl_exists?
cmd = 'kubectl version -o json'
execute_command(cmd, say: false).present?
end
|
.set_current_context(context) ⇒ Object
77
78
79
80
|
# File 'lib/uffizzi/services/install_service.rb', line 77
def set_current_context(context)
cmd = "kubectl config use-context #{context}"
execute_command(cmd)
end
|