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
c6d53250
Commit
c6d53250
authored
Oct 04, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Specify defaults, fix policies, fix db columns
parent
c471430a
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
67 additions
and
48 deletions
+67
-48
cluster.rb
app/models/gcp/cluster.rb
+36
-16
cluster_policy.rb
app/policies/gcp/cluster_policy.rb
+1
-5
integrate_cluster_service.rb
app/services/ci/integrate_cluster_service.rb
+1
-1
_form.html.haml
app/views/projects/clusters/_form.html.haml
+1
-1
show.html.haml
app/views/projects/clusters/show.html.haml
+11
-8
cluster_queue.rb
app/workers/concerns/cluster_queue.rb
+1
-1
sidekiq_queues.yml
config/sidekiq_queues.yml
+1
-1
20170924094327_create_gcp_clusters.rb
db/migrate/20170924094327_create_gcp_clusters.rb
+6
-6
schema.rb
db/schema.rb
+9
-9
No files found.
app/models/gcp/cluster.rb
View file @
c6d53250
...
...
@@ -6,6 +6,10 @@ module Gcp
belongs_to
:user
belongs_to
:service
default_value_for
:gcp_cluster_zone
,
'us-central1-a'
default_value_for
:gcp_cluster_size
,
3
default_value_for
:gcp_machine_type
,
'n1-standard-4'
attr_encrypted
:password
,
mode: :per_attribute_iv
,
key:
Gitlab
::
Application
.
secrets
.
db_key_base
,
...
...
@@ -28,6 +32,35 @@ module Gcp
errored:
4
}
validates
:gcp_project_id
,
length:
1
..
63
,
format:
{
with:
Gitlab
::
Regex
.
kubernetes_namespace_regex
,
message:
Gitlab
::
Regex
.
kubernetes_namespace_regex_message
}
validates
:gcp_cluster_name
,
length:
1
..
63
,
format:
{
with:
Gitlab
::
Regex
.
kubernetes_namespace_regex
,
message:
Gitlab
::
Regex
.
kubernetes_namespace_regex_message
}
validates
:gcp_cluster_zone
,
presence:
true
validates
:gcp_cluster_size
,
presence:
true
,
numericality:
{
only_integer:
true
,
greater_than:
0
}
validates
:project_namespace
,
allow_blank:
true
,
length:
1
..
63
,
format:
{
with:
Gitlab
::
Regex
.
kubernetes_namespace_regex
,
message:
Gitlab
::
Regex
.
kubernetes_namespace_regex_message
}
# if we do not do status transition we prevent change
validate
:restrict_modification
,
on: :update
,
unless: :status_changed?
state_machine
:status
,
initial: :scheduled
do
event
:creating
do
transition
any
-
[
:creating
]
=>
:creating
...
...
@@ -52,22 +85,9 @@ module Gcp
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
}
validates
:project_namespace
,
allow_blank:
true
,
length:
1
..
63
,
format:
{
with:
Gitlab
::
Regex
.
kubernetes_namespace_regex
,
message:
Gitlab
::
Regex
.
kubernetes_namespace_regex_message
}
# if we do not do status transition we prevent change
validate
:restrict_modification
,
on: :update
,
unless: :status_changed?
def
project_namespace_placeholder
"
#{
project
.
path
}
-
#{
project
.
id
}
"
end
def
on_creation?
scheduled?
||
creating?
...
...
app/policies/gcp/cluster_policy.rb
View file @
c6d53250
...
...
@@ -4,11 +4,7 @@ module Gcp
delegate
{
@subject
.
project
}
condition
(
:safe_to_change
)
do
can?
(
:master_access
)
&&
!
cluster
.
on_creation?
end
rule
{
safe_to_change
}.
policy
do
rule
{
can?
(
:master_access
)
}.
policy
do
enable
:update_cluster
enable
:admin_cluster
end
...
...
app/services/ci/integrate_cluster_service.rb
View file @
c6d53250
...
...
@@ -9,7 +9,7 @@ module Ci
kubernetes_token:
token
,
username:
username
,
password:
password
,
service:
project
.
find_or_initialize_service
(
'kubernetes'
),
service:
cluster
.
project
.
find_or_initialize_service
(
'kubernetes'
),
status_event: :created
)
cluster
.
service
.
update!
(
...
...
app/views/projects/clusters/_form.html.haml
View file @
c6d53250
...
...
@@ -26,7 +26,7 @@
.form-group
=
field
.
label
:project_namespace
=
field
.
text_field
:project_namespace
,
class:
'form-control'
=
field
.
text_field
:project_namespace
,
class:
'form-control'
,
placeholder:
@cluster
.
project_namespace_placeholder
.form-group
=
field
.
label
:gcp_machine_type
...
...
app/views/projects/clusters/show.html.haml
View file @
c6d53250
...
...
@@ -29,7 +29,7 @@
=
s_
(
'ClusterIntegration|Save changes'
)
-
if
can?
(
current_user
,
:
update_cluster
,
@cluster
)
&&
@cluster
.
on_creation?
-
if
can?
(
current_user
,
:
admin_cluster
,
@cluster
)
.form_group
%label
=
s_
(
'ClusterIntegration|Google container engine'
)
...
...
@@ -37,15 +37,18 @@
-
link_gke
=
link_to
(
s_
(
'ClusterIntegration|Google Container Engine'
),
''
,
target:
'_blank'
,
rel:
'noopener noreferrer'
)
=
s_
(
'ClusterIntegration|Manage your cluster by visiting %{link_gke}'
).
html_safe
%
{
link_gke:
link_gke
}
.hidden.js-cluster-error.alert.alert-danger
{
role:
'alert'
}
=
s_
(
'ClusterIntegration|Something went wrong while creating your cluster on Google Container Engine.'
)
%code
.js-error-reason
-
if
@cluster
.
errored?
.js-cluster-error.alert.alert-danger
{
role:
'alert'
}
=
s_
(
'ClusterIntegration|Something went wrong while creating your cluster on Google Container Engine.'
)
%code
.js-error-reason
.hidden.js-cluster-success.alert.alert-info
{
role:
'alert'
}
=
s_
(
'ClusterIntegration|Cluster was successfully created on Google Container Engine.'
)
-
if
@cluster
.
on_creation?
.js-cluster-creating.alert.alert-info
{
role:
'alert'
}
=
s_
(
'ClusterIntegration|Cluster is being created on Google Container Engine...'
)
.hidden.js-cluster-creating.alert.alert-info
{
role:
'alert'
}
=
s_
(
'ClusterIntegration|Cluster is being created on Google Container Engine...'
)
-
if
@cluster
.
created?
.js-cluster-success.alert.alert-info
{
role:
'alert'
}
=
s_
(
'ClusterIntegration|Cluster was successfully created on Google Container Engine.'
)
.form_group
%label
...
...
app/workers/concerns/cluster_queue.rb
View file @
c6d53250
...
...
@@ -5,6 +5,6 @@ module ClusterQueue
extend
ActiveSupport
::
Concern
included
do
sidekiq_options
queue: :
manage
_cluster
sidekiq_options
queue: :
gcp
_cluster
end
end
config/sidekiq_queues.yml
View file @
c6d53250
...
...
@@ -62,6 +62,6 @@
-
[
update_user_activity
,
1
]
-
[
propagate_service_template
,
1
]
-
[
background_migration
,
1
]
-
[
manage
_cluster
,
1
]
-
[
gcp
_cluster
,
1
]
-
[
project_migrate_hashed_storage
,
1
]
-
[
storage_migrator
,
1
]
db/migrate/20170924094327_create_gcp_clusters.rb
View file @
c6d53250
...
...
@@ -4,13 +4,13 @@ class CreateGcpClusters < ActiveRecord::Migration
def
change
create_table
:gcp_clusters
do
|
t
|
t
.
references
:project
,
null:
false
,
index:
{
unique:
true
},
foreign_key:
{
on_delete: :cascade
}
t
.
references
:user
,
null:
false
,
foreign_key:
true
t
.
references
:service
,
foreign_key:
true
t
.
references
:user
,
foreign_key:
{
on_delete: :nullify
}
t
.
references
:service
,
foreign_key:
{
on_delete: :nullify
}
# General
t
.
boolean
:enabled
,
default:
true
t
.
integer
:status
t
.
string
:status_reason
t
.
text
:status_reason
# k8s integration specific
t
.
string
:project_namespace
...
...
@@ -18,10 +18,10 @@ class CreateGcpClusters < ActiveRecord::Migration
# Cluster details
t
.
string
:endpoint
t
.
text
:ca_cert
t
.
string
:encrypted_kubernetes_token
t
.
text
:encrypted_kubernetes_token
t
.
string
:encrypted_kubernetes_token_iv
t
.
string
:username
t
.
string
:encrypted_password
t
.
text
:encrypted_password
t
.
string
:encrypted_password_iv
# GKE
...
...
@@ -31,7 +31,7 @@ class CreateGcpClusters < ActiveRecord::Migration
t
.
integer
:gcp_cluster_size
,
null:
false
t
.
string
:gcp_machine_type
t
.
string
:gcp_operation_id
t
.
string
:encrypted_gcp_token
t
.
text
:encrypted_gcp_token
t
.
string
:encrypted_gcp_token_iv
t
.
datetime_with_timezone
:created_at
,
null:
false
...
...
db/schema.rb
View file @
c6d53250
...
...
@@ -577,18 +577,18 @@ ActiveRecord::Schema.define(version: 20170928100231) do
create_table
"gcp_clusters"
,
force: :cascade
do
|
t
|
t
.
integer
"project_id"
,
null:
false
t
.
integer
"user_id"
,
null:
false
t
.
integer
"user_id"
t
.
integer
"service_id"
t
.
boolean
"enabled"
,
default:
true
t
.
integer
"status"
t
.
string
"status_reason"
t
.
text
"status_reason"
t
.
string
"project_namespace"
t
.
string
"endpoint"
t
.
text
"ca_cert"
t
.
string
"encrypted_kubernetes_token"
t
.
text
"encrypted_kubernetes_token"
t
.
string
"encrypted_kubernetes_token_iv"
t
.
string
"username"
t
.
string
"encrypted_password"
t
.
text
"encrypted_password"
t
.
string
"encrypted_password_iv"
t
.
string
"gcp_project_id"
,
null:
false
t
.
string
"gcp_cluster_zone"
,
null:
false
...
...
@@ -596,10 +596,10 @@ ActiveRecord::Schema.define(version: 20170928100231) do
t
.
integer
"gcp_cluster_size"
,
null:
false
t
.
string
"gcp_machine_type"
t
.
string
"gcp_operation_id"
t
.
string
"encrypted_gcp_token"
t
.
text
"encrypted_gcp_token"
t
.
string
"encrypted_gcp_token_iv"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
datetime
_with_timezone
"created_at"
,
null:
false
t
.
datetime
_with_timezone
"updated_at"
,
null:
false
end
add_index
"gcp_clusters"
,
[
"project_id"
],
name:
"index_gcp_clusters_on_project_id"
,
unique:
true
,
using: :btree
...
...
@@ -1752,8 +1752,8 @@ ActiveRecord::Schema.define(version: 20170928100231) do
add_foreign_key
"events"
,
"users"
,
column:
"author_id"
,
name:
"fk_edfd187b6f"
,
on_delete: :cascade
add_foreign_key
"forked_project_links"
,
"projects"
,
column:
"forked_to_project_id"
,
name:
"fk_434510edb0"
,
on_delete: :cascade
add_foreign_key
"gcp_clusters"
,
"projects"
,
on_delete: :cascade
add_foreign_key
"gcp_clusters"
,
"services"
add_foreign_key
"gcp_clusters"
,
"users"
add_foreign_key
"gcp_clusters"
,
"services"
,
on_delete: :nullify
add_foreign_key
"gcp_clusters"
,
"users"
,
on_delete: :nullify
add_foreign_key
"gpg_keys"
,
"users"
,
on_delete: :cascade
add_foreign_key
"gpg_signatures"
,
"gpg_keys"
,
on_delete: :nullify
add_foreign_key
"gpg_signatures"
,
"projects"
,
on_delete: :cascade
...
...
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