Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
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
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
67 additions
and
48 deletions
+67
-48
app/models/gcp/cluster.rb
app/models/gcp/cluster.rb
+36
-16
app/policies/gcp/cluster_policy.rb
app/policies/gcp/cluster_policy.rb
+1
-5
app/services/ci/integrate_cluster_service.rb
app/services/ci/integrate_cluster_service.rb
+1
-1
app/views/projects/clusters/_form.html.haml
app/views/projects/clusters/_form.html.haml
+1
-1
app/views/projects/clusters/show.html.haml
app/views/projects/clusters/show.html.haml
+11
-8
app/workers/concerns/cluster_queue.rb
app/workers/concerns/cluster_queue.rb
+1
-1
config/sidekiq_queues.yml
config/sidekiq_queues.yml
+1
-1
db/migrate/20170924094327_create_gcp_clusters.rb
db/migrate/20170924094327_create_gcp_clusters.rb
+6
-6
db/schema.rb
db/schema.rb
+9
-9
No files found.
app/models/gcp/cluster.rb
View file @
c6d53250
...
@@ -6,6 +6,10 @@ module Gcp
...
@@ -6,6 +6,10 @@ module Gcp
belongs_to
:user
belongs_to
:user
belongs_to
:service
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
,
attr_encrypted
:password
,
mode: :per_attribute_iv
,
mode: :per_attribute_iv
,
key:
Gitlab
::
Application
.
secrets
.
db_key_base
,
key:
Gitlab
::
Application
.
secrets
.
db_key_base
,
...
@@ -28,6 +32,35 @@ module Gcp
...
@@ -28,6 +32,35 @@ module Gcp
errored:
4
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
state_machine
:status
,
initial: :scheduled
do
event
:creating
do
event
:creating
do
transition
any
-
[
:creating
]
=>
:creating
transition
any
-
[
:creating
]
=>
:creating
...
@@ -52,22 +85,9 @@ module Gcp
...
@@ -52,22 +85,9 @@ module Gcp
end
end
end
end
validates
:gcp_project_id
,
presence:
true
def
project_namespace_placeholder
validates
:gcp_cluster_zone
,
presence:
true
"
#{
project
.
path
}
-
#{
project
.
id
}
"
validates
:gcp_cluster_name
,
presence:
true
end
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
on_creation?
def
on_creation?
scheduled?
||
creating?
scheduled?
||
creating?
...
...
app/policies/gcp/cluster_policy.rb
View file @
c6d53250
...
@@ -4,11 +4,7 @@ module Gcp
...
@@ -4,11 +4,7 @@ module Gcp
delegate
{
@subject
.
project
}
delegate
{
@subject
.
project
}
condition
(
:safe_to_change
)
do
rule
{
can?
(
:master_access
)
}.
policy
do
can?
(
:master_access
)
&&
!
cluster
.
on_creation?
end
rule
{
safe_to_change
}.
policy
do
enable
:update_cluster
enable
:update_cluster
enable
:admin_cluster
enable
:admin_cluster
end
end
...
...
app/services/ci/integrate_cluster_service.rb
View file @
c6d53250
...
@@ -9,7 +9,7 @@ module Ci
...
@@ -9,7 +9,7 @@ module Ci
kubernetes_token:
token
,
kubernetes_token:
token
,
username:
username
,
username:
username
,
password:
password
,
password:
password
,
service:
project
.
find_or_initialize_service
(
'kubernetes'
),
service:
cluster
.
project
.
find_or_initialize_service
(
'kubernetes'
),
status_event: :created
)
status_event: :created
)
cluster
.
service
.
update!
(
cluster
.
service
.
update!
(
...
...
app/views/projects/clusters/_form.html.haml
View file @
c6d53250
...
@@ -26,7 +26,7 @@
...
@@ -26,7 +26,7 @@
.form-group
.form-group
=
field
.
label
:project_namespace
=
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
.form-group
=
field
.
label
:gcp_machine_type
=
field
.
label
:gcp_machine_type
...
...
app/views/projects/clusters/show.html.haml
View file @
c6d53250
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
=
s_
(
'ClusterIntegration|Save changes'
)
=
s_
(
'ClusterIntegration|Save changes'
)
-
if
can?
(
current_user
,
:
update_cluster
,
@cluster
)
&&
@cluster
.
on_creation?
-
if
can?
(
current_user
,
:
admin_cluster
,
@cluster
)
.form_group
.form_group
%label
%label
=
s_
(
'ClusterIntegration|Google container engine'
)
=
s_
(
'ClusterIntegration|Google container engine'
)
...
@@ -37,15 +37,18 @@
...
@@ -37,15 +37,18 @@
-
link_gke
=
link_to
(
s_
(
'ClusterIntegration|Google Container Engine'
),
''
,
target:
'_blank'
,
rel:
'noopener noreferrer'
)
-
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
}
=
s_
(
'ClusterIntegration|Manage your cluster by visiting %{link_gke}'
).
html_safe
%
{
link_gke:
link_gke
}
.hidden.js-cluster-error.alert.alert-danger
{
role:
'alert'
}
-
if
@cluster
.
errored?
=
s_
(
'ClusterIntegration|Something went wrong while creating your cluster on Google Container Engine.'
)
.js-cluster-error.alert.alert-danger
{
role:
'alert'
}
%code
.js-error-reason
=
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'
}
-
if
@cluster
.
on_creation?
=
s_
(
'ClusterIntegration|Cluster was successfully created on Google Container Engine.'
)
.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'
}
-
if
@cluster
.
created?
=
s_
(
'ClusterIntegration|Cluster is being created on Google Container Engine...'
)
.js-cluster-success.alert.alert-info
{
role:
'alert'
}
=
s_
(
'ClusterIntegration|Cluster was successfully created on Google Container Engine.'
)
.form_group
.form_group
%label
%label
...
...
app/workers/concerns/cluster_queue.rb
View file @
c6d53250
...
@@ -5,6 +5,6 @@ module ClusterQueue
...
@@ -5,6 +5,6 @@ module ClusterQueue
extend
ActiveSupport
::
Concern
extend
ActiveSupport
::
Concern
included
do
included
do
sidekiq_options
queue: :
manage
_cluster
sidekiq_options
queue: :
gcp
_cluster
end
end
end
end
config/sidekiq_queues.yml
View file @
c6d53250
...
@@ -62,6 +62,6 @@
...
@@ -62,6 +62,6 @@
- [update_user_activity, 1]
- [update_user_activity, 1]
- [propagate_service_template, 1]
- [propagate_service_template, 1]
- [background_migration, 1]
- [background_migration, 1]
- [
manage
_cluster, 1]
- [
gcp
_cluster, 1]
- [project_migrate_hashed_storage, 1]
- [project_migrate_hashed_storage, 1]
- [storage_migrator, 1]
- [storage_migrator, 1]
db/migrate/20170924094327_create_gcp_clusters.rb
View file @
c6d53250
...
@@ -4,13 +4,13 @@ class CreateGcpClusters < ActiveRecord::Migration
...
@@ -4,13 +4,13 @@ class CreateGcpClusters < ActiveRecord::Migration
def
change
def
change
create_table
:gcp_clusters
do
|
t
|
create_table
:gcp_clusters
do
|
t
|
t
.
references
:project
,
null:
false
,
index:
{
unique:
true
},
foreign_key:
{
on_delete: :cascade
}
t
.
references
:project
,
null:
false
,
index:
{
unique:
true
},
foreign_key:
{
on_delete: :cascade
}
t
.
references
:user
,
null:
false
,
foreign_key:
true
t
.
references
:user
,
foreign_key:
{
on_delete: :nullify
}
t
.
references
:service
,
foreign_key:
true
t
.
references
:service
,
foreign_key:
{
on_delete: :nullify
}
# General
# General
t
.
boolean
:enabled
,
default:
true
t
.
boolean
:enabled
,
default:
true
t
.
integer
:status
t
.
integer
:status
t
.
string
:status_reason
t
.
text
:status_reason
# k8s integration specific
# k8s integration specific
t
.
string
:project_namespace
t
.
string
:project_namespace
...
@@ -18,10 +18,10 @@ class CreateGcpClusters < ActiveRecord::Migration
...
@@ -18,10 +18,10 @@ class CreateGcpClusters < ActiveRecord::Migration
# Cluster details
# Cluster details
t
.
string
:endpoint
t
.
string
:endpoint
t
.
text
:ca_cert
t
.
text
:ca_cert
t
.
string
:encrypted_kubernetes_token
t
.
text
:encrypted_kubernetes_token
t
.
string
:encrypted_kubernetes_token_iv
t
.
string
:encrypted_kubernetes_token_iv
t
.
string
:username
t
.
string
:username
t
.
string
:encrypted_password
t
.
text
:encrypted_password
t
.
string
:encrypted_password_iv
t
.
string
:encrypted_password_iv
# GKE
# GKE
...
@@ -31,7 +31,7 @@ class CreateGcpClusters < ActiveRecord::Migration
...
@@ -31,7 +31,7 @@ class CreateGcpClusters < ActiveRecord::Migration
t
.
integer
:gcp_cluster_size
,
null:
false
t
.
integer
:gcp_cluster_size
,
null:
false
t
.
string
:gcp_machine_type
t
.
string
:gcp_machine_type
t
.
string
:gcp_operation_id
t
.
string
:gcp_operation_id
t
.
string
:encrypted_gcp_token
t
.
text
:encrypted_gcp_token
t
.
string
:encrypted_gcp_token_iv
t
.
string
:encrypted_gcp_token_iv
t
.
datetime_with_timezone
:created_at
,
null:
false
t
.
datetime_with_timezone
:created_at
,
null:
false
...
...
db/schema.rb
View file @
c6d53250
...
@@ -577,18 +577,18 @@ ActiveRecord::Schema.define(version: 20170928100231) do
...
@@ -577,18 +577,18 @@ ActiveRecord::Schema.define(version: 20170928100231) do
create_table
"gcp_clusters"
,
force: :cascade
do
|
t
|
create_table
"gcp_clusters"
,
force: :cascade
do
|
t
|
t
.
integer
"project_id"
,
null:
false
t
.
integer
"project_id"
,
null:
false
t
.
integer
"user_id"
,
null:
false
t
.
integer
"user_id"
t
.
integer
"service_id"
t
.
integer
"service_id"
t
.
boolean
"enabled"
,
default:
true
t
.
boolean
"enabled"
,
default:
true
t
.
integer
"status"
t
.
integer
"status"
t
.
string
"status_reason"
t
.
text
"status_reason"
t
.
string
"project_namespace"
t
.
string
"project_namespace"
t
.
string
"endpoint"
t
.
string
"endpoint"
t
.
text
"ca_cert"
t
.
text
"ca_cert"
t
.
string
"encrypted_kubernetes_token"
t
.
text
"encrypted_kubernetes_token"
t
.
string
"encrypted_kubernetes_token_iv"
t
.
string
"encrypted_kubernetes_token_iv"
t
.
string
"username"
t
.
string
"username"
t
.
string
"encrypted_password"
t
.
text
"encrypted_password"
t
.
string
"encrypted_password_iv"
t
.
string
"encrypted_password_iv"
t
.
string
"gcp_project_id"
,
null:
false
t
.
string
"gcp_project_id"
,
null:
false
t
.
string
"gcp_cluster_zone"
,
null:
false
t
.
string
"gcp_cluster_zone"
,
null:
false
...
@@ -596,10 +596,10 @@ ActiveRecord::Schema.define(version: 20170928100231) do
...
@@ -596,10 +596,10 @@ ActiveRecord::Schema.define(version: 20170928100231) do
t
.
integer
"gcp_cluster_size"
,
null:
false
t
.
integer
"gcp_cluster_size"
,
null:
false
t
.
string
"gcp_machine_type"
t
.
string
"gcp_machine_type"
t
.
string
"gcp_operation_id"
t
.
string
"gcp_operation_id"
t
.
string
"encrypted_gcp_token"
t
.
text
"encrypted_gcp_token"
t
.
string
"encrypted_gcp_token_iv"
t
.
string
"encrypted_gcp_token_iv"
t
.
datetime
"created_at"
,
null:
false
t
.
datetime
_with_timezone
"created_at"
,
null:
false
t
.
datetime
"updated_at"
,
null:
false
t
.
datetime
_with_timezone
"updated_at"
,
null:
false
end
end
add_index
"gcp_clusters"
,
[
"project_id"
],
name:
"index_gcp_clusters_on_project_id"
,
unique:
true
,
using: :btree
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
...
@@ -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
"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
"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"
,
"projects"
,
on_delete: :cascade
add_foreign_key
"gcp_clusters"
,
"services"
add_foreign_key
"gcp_clusters"
,
"services"
,
on_delete: :nullify
add_foreign_key
"gcp_clusters"
,
"users"
add_foreign_key
"gcp_clusters"
,
"users"
,
on_delete: :nullify
add_foreign_key
"gpg_keys"
,
"users"
,
on_delete: :cascade
add_foreign_key
"gpg_keys"
,
"users"
,
on_delete: :cascade
add_foreign_key
"gpg_signatures"
,
"gpg_keys"
,
on_delete: :nullify
add_foreign_key
"gpg_signatures"
,
"gpg_keys"
,
on_delete: :nullify
add_foreign_key
"gpg_signatures"
,
"projects"
,
on_delete: :cascade
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