BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
c471430a
Commit
c471430a
authored
Oct 03, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Gcp::Cluster improvements
- introduce state machine - use before transitions to clear data - introduce namespace validation
parent
7e3e8ae8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
42 additions
and
31 deletions
+42
-31
cluster.rb
app/models/gcp/cluster.rb
+33
-30
integrate_cluster_service.rb
app/services/ci/integrate_cluster_service.rb
+9
-1
No files found.
app/models/gcp/cluster.rb
View file @
c471430a
...
...
@@ -22,49 +22,52 @@ module Gcp
algorithm:
'aes-256-cbc'
enum
status:
{
unknown:
nil
,
scheduled:
1
,
creating:
2
,
created:
3
,
errored:
4
}
state_machine
:status
,
initial: :scheduled
do
event
:creating
do
transition
any
-
[
:creating
]
=>
:creating
end
event
:created
do
transition
any
-
[
:created
]
=>
:created
end
event
:errored
do
transition
any
-
[
:errored
]
=>
:errored
end
before_transition
any
=>
[
:errored
,
:created
]
do
|
cluster
|
cluster
.
gcp_token
=
nil
cluster
.
gcp_operation_id
=
nil
end
before_transition
any
=>
[
:errored
]
do
|
cluster
|
status_reason
=
transition
.
args
.
first
cluster
.
status_reason
=
status_reason
end
end
validates
:gcp_project_id
,
presence:
true
validates
:gcp_cluster_zone
,
presence:
true
validates
:gcp_cluster_name
,
presence:
true
validates
:gcp_cluster_size
,
presence:
true
,
numericality:
{
only_integer:
true
,
greater_than:
0
}
validate
:restrict_modification
,
on: :update
def
errored!
(
reason
)
self
.
status
=
:errored
self
.
status_reason
=
reason
self
.
gcp_token
=
nil
save!
(
validate:
false
)
end
def
creating!
(
gcp_operation_id
)
self
.
status
=
:creating
self
.
gcp_operation_id
=
gcp_operation_id
save!
(
validate:
false
)
end
validates
:project_namespace
,
allow_blank:
true
,
length:
1
..
63
,
format:
{
with:
Gitlab
::
Regex
.
kubernetes_namespace_regex
,
message:
Gitlab
::
Regex
.
kubernetes_namespace_regex_message
}
def
created!
(
endpoint
,
ca_cert
,
kubernetes_token
,
username
,
password
)
self
.
status
=
:created
self
.
enabled
=
true
self
.
endpoint
=
endpoint
self
.
ca_cert
=
ca_cert
self
.
kubernetes_token
=
kubernetes_token
self
.
username
=
username
self
.
password
=
password
self
.
service
=
project
.
find_or_initialize_service
(
'kubernetes'
)
self
.
gcp_token
=
nil
self
.
gcp_operation_id
=
nil
save!
end
# if we do not do status transition we prevent change
validate
:restrict_modification
,
on: :update
,
unless: :status_changed?
def
on_creation?
scheduled?
||
creating?
...
...
app/services/ci/integrate_cluster_service.rb
View file @
c471430a
...
...
@@ -2,7 +2,15 @@ module Ci
class
IntegrateClusterService
def
execute
(
cluster
,
endpoint
,
ca_cert
,
token
,
username
,
password
)
Gcp
::
Cluster
.
transaction
do
cluster
.
created!
(
endpoint
,
ca_cert
,
token
,
username
,
password
)
cluster
.
update!
(
enabled:
true
,
endpoint:
endpoint
,
ca_cert:
ca_cert
,
kubernetes_token:
token
,
username:
username
,
password:
password
,
service:
project
.
find_or_initialize_service
(
'kubernetes'
),
status_event: :created
)
cluster
.
service
.
update!
(
active:
true
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment