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
key: Gitlab::Application.secrets.db_key_base,
algorithm: 'aes-256-cbc'
enum status: {
scheduled: 1,
creating: 2,
created: 3,
errored: 4
}
validates :gcp_project_id,
length: 1..63,
format: {
......@@ -67,6 +60,11 @@ module Gcp
validate :restrict_modification, on: :update, unless: :status_changed?
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
transition any - [:creating] => :creating
end
......@@ -86,7 +84,7 @@ module Gcp
before_transition any => [:errored] do |cluster, transition|
status_reason = transition.args.first
cluster.status_reason = status_reason
cluster.status_reason = status_reason if status_reason
end
end
......
class ClusterEntity < Grape::Entity
include RequestAwareEntity
expose :status
expose :status_name, as: :status
expose :status_reason
end
......@@ -5,7 +5,6 @@ module Ci
project.create_cluster(
params.merge(user: current_user,
status: Gcp::Cluster.statuses[:scheduled],
gcp_token: access_token)).tap do |cluster|
ClusterProvisionWorker.perform_async(cluster.id) if cluster.persisted?
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?
.row.prepend-top-default.edit-cluster-form.js-edit-cluster-form{ data: { status_path: status_path,
toggle_status: @cluster.enabled? ? 'true': 'false',
cluster_status: @cluster.status,
cluster_status: @cluster.status_name,
cluster_status_reason: @cluster.status_reason }}
= render 'sidebar'
.col-lg-8
......
......@@ -13,11 +13,17 @@ FactoryGirl.define do
end
trait :created_on_gke do
status_event :make_created
endpoint '111.111.111.111'
ca_cert 'xxxxxx'
kubernetes_token 'xxxxxx'
username 'xxxxxx'
password 'xxxxxx'
end
trait :errored do
status_event :make_errored
status_reason 'general error'
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