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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
0d95ce51
Commit
0d95ce51
authored
Nov 21, 2017
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Check diff between KubernetesService and Platforms::Kubernetes. Synchronize again.
parent
8a55d2c5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
62 additions
and
67 deletions
+62
-67
app/models/clusters/platforms/kubernetes.rb
app/models/clusters/platforms/kubernetes.rb
+57
-67
app/models/project_services/kubernetes_service.rb
app/models/project_services/kubernetes_service.rb
+5
-0
No files found.
app/models/clusters/platforms/kubernetes.rb
View file @
0d95ce51
...
@@ -44,12 +44,6 @@ module Clusters
...
@@ -44,12 +44,6 @@ module Clusters
delegate
:project
,
to: :cluster
,
allow_nil:
true
delegate
:project
,
to: :cluster
,
allow_nil:
true
delegate
:enabled?
,
to: :cluster
,
allow_nil:
true
delegate
:enabled?
,
to: :cluster
,
allow_nil:
true
class
<<
self
def
namespace_for_project
(
project
)
"
#{
project
.
path
}
-
#{
project
.
id
}
"
end
end
def
actual_namespace
def
actual_namespace
if
namespace
.
present?
if
namespace
.
present?
namespace
namespace
...
@@ -58,10 +52,6 @@ module Clusters
...
@@ -58,10 +52,6 @@ module Clusters
end
end
end
end
def
default_namespace
self
.
class
.
namespace_for_project
(
project
)
if
project
end
def
predefined_variables
def
predefined_variables
config
=
YAML
.
dump
(
kubeconfig
)
config
=
YAML
.
dump
(
kubeconfig
)
...
@@ -101,41 +91,6 @@ module Clusters
...
@@ -101,41 +91,6 @@ module Clusters
{
pods:
read_pods
}
{
pods:
read_pods
}
end
end
def
kubeconfig
to_kubeconfig
(
url:
api_url
,
namespace:
actual_namespace
,
token:
token
,
ca_pem:
ca_pem
)
end
def
read_secrets
kubeclient
=
build_kubeclient!
kubeclient
.
get_secrets
.
as_json
end
# Returns a hash of all pods in the namespace
def
read_pods
kubeclient
=
build_kubeclient!
kubeclient
.
get_pods
(
namespace:
actual_namespace
).
as_json
rescue
KubeException
=>
err
raise
err
unless
err
.
error_code
==
404
[]
end
def
kubeclient_ssl_options
opts
=
{
verify_ssl:
OpenSSL
::
SSL
::
VERIFY_PEER
}
if
ca_pem
.
present?
opts
[
:cert_store
]
=
OpenSSL
::
X509
::
Store
.
new
opts
[
:cert_store
].
add_cert
(
OpenSSL
::
X509
::
Certificate
.
new
(
ca_pem
))
end
opts
end
def
kubeclient
def
kubeclient
@kubeclient
||=
kubernetes_service
.
kubeclient
if
manages_kubernetes_service?
@kubeclient
||=
kubernetes_service
.
kubeclient
if
manages_kubernetes_service?
end
end
...
@@ -161,29 +116,19 @@ module Clusters
...
@@ -161,29 +116,19 @@ module Clusters
private
private
def
enforce_namespace_to_lower_case
def
kubeconfig
self
.
namespace
=
self
.
namespace
&
.
downcase
to_kubeconfig
(
end
url:
api_url
,
namespace:
actual_namespace
,
# TODO: glue code till we migrate Kubernetes Service into Platforms::Kubernetes class
token:
token
,
def
manages_kubernetes_service?
ca_pem:
ca_pem
)
return
true
unless
kubernetes_service
&
.
active?
kubernetes_service
.
api_url
==
api_url
end
def
destroy_kubernetes_integration!
return
unless
manages_kubernetes_service?
kubernetes_service
&
.
destroy!
end
end
def
kubernetes_service
def
default_namespace
@kubernetes_service
||=
project
&
.
kubernetes_service
return
unless
project
end
def
ensure_kubernetes_servic
e
slug
=
"
#{
project
.
path
}
-
#{
project
.
id
}
"
.
downcas
e
@kubernetes_service
||=
kubernetes_service
||
project
&
.
build_kubernetes_service
slug
.
gsub
(
/[^-a-z0-9]/
,
'-'
).
gsub
(
/^-+/
,
''
)
end
end
def
build_kubeclient!
(
api_path:
'api'
,
api_version:
'v1'
)
def
build_kubeclient!
(
api_path:
'api'
,
api_version:
'v1'
)
...
@@ -202,9 +147,29 @@ module Clusters
...
@@ -202,9 +147,29 @@ module Clusters
)
)
end
end
# Returns a hash of all pods in the namespace
def
read_pods
kubeclient
=
build_kubeclient!
kubeclient
.
get_pods
(
namespace:
actual_namespace
).
as_json
rescue
KubeException
=>
err
raise
err
unless
err
.
error_code
==
404
[]
end
def
kubeclient_ssl_options
opts
=
{
verify_ssl:
OpenSSL
::
SSL
::
VERIFY_PEER
}
if
ca_pem
.
present?
opts
[
:cert_store
]
=
OpenSSL
::
X509
::
Store
.
new
opts
[
:cert_store
].
add_cert
(
OpenSSL
::
X509
::
Certificate
.
new
(
ca_pem
))
end
opts
end
def
kubeclient_auth_options
def
kubeclient_auth_options
return
{
username:
username
,
password:
password
}
if
username
&&
password
{
bearer_token:
token
}
return
{
bearer_token:
token
}
if
token
end
end
def
join_api_url
(
api_path
)
def
join_api_url
(
api_path
)
...
@@ -227,6 +192,31 @@ module Clusters
...
@@ -227,6 +192,31 @@ module Clusters
def
enforce_namespace_to_lower_case
def
enforce_namespace_to_lower_case
self
.
namespace
=
self
.
namespace
&
.
downcase
self
.
namespace
=
self
.
namespace
&
.
downcase
end
end
def
enforce_namespace_to_lower_case
self
.
namespace
=
self
.
namespace
&
.
downcase
end
# TODO: glue code till we migrate Kubernetes Service into Platforms::Kubernetes class
def
manages_kubernetes_service?
return
true
unless
kubernetes_service
&
.
active?
kubernetes_service
.
api_url
==
api_url
end
def
destroy_kubernetes_integration!
return
unless
manages_kubernetes_service?
kubernetes_service
&
.
destroy!
end
def
kubernetes_service
@kubernetes_service
||=
project
&
.
kubernetes_service
end
def
ensure_kubernetes_service
@kubernetes_service
||=
kubernetes_service
||
project
&
.
build_kubernetes_service
end
end
end
end
end
end
end
app/models/project_services/kubernetes_service.rb
View file @
0d95ce51
##
# NOTE:
# We'll move this class to Clusters::Platforms::Kubernetes, which contains exactly the same logic.
# After we've migrated data, we'll remove KubernetesService. This would happen in a few months.
# If you're modyfiyng this class, please note that you should update the same change in Clusters::Platforms::Kubernetes.
class
KubernetesService
<
DeploymentService
class
KubernetesService
<
DeploymentService
include
Gitlab
::
CurrentSettings
include
Gitlab
::
CurrentSettings
include
Gitlab
::
Kubernetes
include
Gitlab
::
Kubernetes
...
...
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