Class: UffizziCore::ClusterService

Inherits:
Object
  • Object
show all
Defined in:
app/services/uffizzi_core/cluster_service.rb

Class Method Summary collapse

Class Method Details

.deploy_cluster(cluster) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/uffizzi_core/cluster_service.rb', line 9

def deploy_cluster(cluster)
  begin
    UffizziCore::ControllerService.create_namespace(cluster)
  rescue UffizziCore::ControllerClient::ConnectionError
    return cluster.fail_deploy_namespace!
  end

  cluster.start_deploying!

  begin
    UffizziCore::ControllerService.create_cluster(cluster)
  rescue UffizziCore::ControllerClient::ConnectionError
    return cluster.fail!
  end

  UffizziCore::Cluster::ManageDeployingJob.perform_in(5.seconds, cluster.id)
end

.filter_user_ingress_host(cluster, ingress_hosts) ⇒ Object



71
72
73
# File 'app/services/uffizzi_core/cluster_service.rb', line 71

def filter_user_ingress_host(cluster, ingress_hosts)
  ingress_hosts.reject { |h| h == cluster.host }
end

.manage_deploying(cluster, try) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/services/uffizzi_core/cluster_service.rb', line 53

def manage_deploying(cluster, try)
  return if cluster.disabled?
  return cluster.fail! if try > Settings.vcluster.max_creation_retry_count

  deployed_cluster = UffizziCore::ControllerService.show_cluster(cluster)

  if deployed_cluster.status.ready && deployed_cluster.status.kube_config.present?
    cluster.finish_deploy
    cluster.kubeconfig = deployed_cluster.status.kube_config
    cluster.host = deployed_cluster.status.host
    cluster.save!

    return
  end

  UffizziCore::Cluster::ManageDeployingJob.perform_in(5.seconds, cluster.id, ++try)
end

.manage_scale_down(cluster) ⇒ Object



47
48
49
50
51
# File 'app/services/uffizzi_core/cluster_service.rb', line 47

def manage_scale_down(cluster)
  return cluster.scale_down! unless awake?(cluster)

  UffizziCore::Cluster::ManageScalingDownJob.perform_in(5.seconds, cluster.id)
end

.manage_scale_up(cluster, try) ⇒ Object



33
34
35
36
37
38
# File 'app/services/uffizzi_core/cluster_service.rb', line 33

def manage_scale_up(cluster, try)
  return cluster.fail_scale_up! if try > Settings.vcluster.max_scale_up_retry_count
  return cluster.scale_up! if ready?(cluster)

  UffizziCore::Cluster::ManageScalingUpJob.perform_in(5.seconds, cluster.id, ++try)
end

.scale_down!(cluster) ⇒ Object



40
41
42
43
44
45
# File 'app/services/uffizzi_core/cluster_service.rb', line 40

def scale_down!(cluster)
  cluster.start_scaling_down!
  UffizziCore::ControllerService.patch_cluster(cluster, sleep: true)

  UffizziCore::Cluster::ManageScalingDownJob.perform_in(5.seconds, cluster.id)
end

.scale_up!(cluster) ⇒ Object



27
28
29
30
31
# File 'app/services/uffizzi_core/cluster_service.rb', line 27

def scale_up!(cluster)
  cluster.start_scaling_up!
  UffizziCore::ControllerService.patch_cluster(cluster, sleep: false)
  UffizziCore::Cluster::ManageScalingUpJob.perform_in(5.seconds, cluster.id)
end

.start_deploy(cluster) ⇒ Object



5
6
7
# File 'app/services/uffizzi_core/cluster_service.rb', line 5

def start_deploy(cluster)
  UffizziCore::Cluster::DeployJob.perform_async(cluster.id)
end