Class: UffizziCore::Api::Cli::V1::Projects::ClustersController

Inherits:
ApplicationController
  • Object
show all
Includes:
ClustersControllerModule
Defined in:
app/controllers/uffizzi_core/api/cli/v1/projects/clusters_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/uffizzi_core/api/cli/v1/projects/clusters_controller.rb', line 18

def create
  version = cluster_params[:k8s_version]
  kubernetes_distribution = find_kubernetes_distribution(version)
  return render_distribution_version_error(version) if kubernetes_distribution.blank?

  cluster_form = UffizziCore::Api::Cli::V1::Cluster::CreateForm.new(cluster_params)
  cluster_form.project = resource_project
  cluster_form.deployed_by = current_user
  cluster_form.kubernetes_distribution = kubernetes_distribution
  return respond_with cluster_form unless cluster_form.save

  UffizziCore::ClusterService.start_deploy(cluster_form)

  respond_with cluster_form
end

#destroyObject



72
73
74
75
76
# File 'app/controllers/uffizzi_core/api/cli/v1/projects/clusters_controller.rb', line 72

def destroy
  resource_cluster.disable!

  head(:no_content)
end

#indexObject



11
12
13
14
15
16
# File 'app/controllers/uffizzi_core/api/cli/v1/projects/clusters_controller.rb', line 11

def index
  clusters = resource_project.clusters.enabled
  return respond_with clusters if request_by_admin? || valid_request_from_ci_workflow?

  respond_with clusters.deployed_by_user(current_user), each_serializer: UffizziCore::Api::Cli::V1::Projects::ShortClusterSerializer
end

#scale_downObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/uffizzi_core/api/cli/v1/projects/clusters_controller.rb', line 34

def scale_down
  if resource_cluster.deployed?
    UffizziCore::ClusterService.scale_down!(resource_cluster)
    return respond_with resource_cluster
  end

  return render_scale_error(I18n.t('cluster.already_asleep', name: resource_cluster.name)) if resource_cluster.scaled_down?

  if resource_cluster.deploying_namespace? || resource_cluster.deploying?
    render_scale_error(I18n.t('cluster.deploy_in_process', name: resource_cluster.name))
  end
rescue AASM::InvalidTransition, UffizziCore::ClusterScaleError => e
  render_scale_error(e.message)
end

#scale_upObject



49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/uffizzi_core/api/cli/v1/projects/clusters_controller.rb', line 49

def scale_up
  if resource_cluster.scaled_down?
    UffizziCore::ClusterService.scale_up!(resource_cluster)
    return respond_with resource_cluster
  end

  return render_scale_error(I18n.t('cluster.already_awake', name: resource_cluster.name)) if resource_cluster.deployed?
rescue AASM::InvalidTransition, UffizziCore::ClusterScaleError => e
  render_scale_error(e.message)
end

#showObject



60
61
62
# File 'app/controllers/uffizzi_core/api/cli/v1/projects/clusters_controller.rb', line 60

def show
  respond_with resource_cluster
end

#syncObject



64
65
66
67
68
69
70
# File 'app/controllers/uffizzi_core/api/cli/v1/projects/clusters_controller.rb', line 64

def sync
  cluster_form = resource_cluster.becomes(UffizziCore::Api::Cli::V1::Cluster::SyncForm)
  cluster_form.sync_status
  cluster_form.save

  respond_with cluster_form
end