Commit 07247601 authored by Kamil Trzcinski's avatar Kamil Trzcinski

Remove status enum from Gcp::Cluster, use state_machine#state

parent bee5c080
...@@ -25,13 +25,6 @@ module Gcp ...@@ -25,13 +25,6 @@ module Gcp
key: Gitlab::Application.secrets.db_key_base, key: Gitlab::Application.secrets.db_key_base,
algorithm: 'aes-256-cbc' algorithm: 'aes-256-cbc'
enum status: {
scheduled: 1,
creating: 2,
created: 3,
errored: 4
}
validates :gcp_project_id, validates :gcp_project_id,
length: 1..63, length: 1..63,
format: { format: {
...@@ -67,6 +60,11 @@ module Gcp ...@@ -67,6 +60,11 @@ module Gcp
validate :restrict_modification, on: :update, unless: :status_changed? validate :restrict_modification, on: :update, unless: :status_changed?
state_machine :status, initial: :scheduled do state_machine :status, initial: :scheduled do
state :scheduled, value: 1
state :creating, value: 2
state :created, value: 3
state :errored, value: 4
event :make_creating do event :make_creating do
transition any - [:creating] => :creating transition any - [:creating] => :creating
end end
...@@ -86,7 +84,7 @@ module Gcp ...@@ -86,7 +84,7 @@ module Gcp
before_transition any => [:errored] do |cluster, transition| before_transition any => [:errored] do |cluster, transition|
status_reason = transition.args.first status_reason = transition.args.first
cluster.status_reason = status_reason cluster.status_reason = status_reason if status_reason
end end
end end
......
class ClusterEntity < Grape::Entity class ClusterEntity < Grape::Entity
include RequestAwareEntity include RequestAwareEntity
expose :status expose :status_name, as: :status
expose :status_reason expose :status_reason
end end
...@@ -5,7 +5,6 @@ module Ci ...@@ -5,7 +5,6 @@ module Ci
project.create_cluster( project.create_cluster(
params.merge(user: current_user, params.merge(user: current_user,
status: Gcp::Cluster.statuses[:scheduled],
gcp_token: access_token)).tap do |cluster| gcp_token: access_token)).tap do |cluster|
ClusterProvisionWorker.perform_async(cluster.id) if cluster.persisted? ClusterProvisionWorker.perform_async(cluster.id) if cluster.persisted?
end end
......
- status_path = status_namespace_project_cluster_path(@cluster.project.namespace, @cluster.project, @cluster.id, format: :json) if can?(current_user, :admin_cluster, @cluster) && @cluster.on_creation? - status_path = status_namespace_project_cluster_path(@cluster.project.namespace, @cluster.project, @cluster.id, format: :json) if can?(current_user, :admin_cluster, @cluster) && @cluster.on_creation?
.row.prepend-top-default.edit-cluster-form.js-edit-cluster-form{ data: { status_path: status_path, .row.prepend-top-default.edit-cluster-form.js-edit-cluster-form{ data: { status_path: status_path,
toggle_status: @cluster.enabled? ? 'true': 'false', toggle_status: @cluster.enabled? ? 'true': 'false',
cluster_status: @cluster.status, cluster_status: @cluster.status_name,
cluster_status_reason: @cluster.status_reason }} cluster_status_reason: @cluster.status_reason }}
= render 'sidebar' = render 'sidebar'
.col-lg-8 .col-lg-8
......
...@@ -13,11 +13,17 @@ FactoryGirl.define do ...@@ -13,11 +13,17 @@ FactoryGirl.define do
end end
trait :created_on_gke do trait :created_on_gke do
status_event :make_created
endpoint '111.111.111.111' endpoint '111.111.111.111'
ca_cert 'xxxxxx' ca_cert 'xxxxxx'
kubernetes_token 'xxxxxx' kubernetes_token 'xxxxxx'
username 'xxxxxx' username 'xxxxxx'
password 'xxxxxx' password 'xxxxxx'
end end
trait :errored do
status_event :make_errored
status_reason 'general error'
end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment