summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShinya Maeda <shinya@gitlab.com>2017-11-21 22:03:07 +0900
committerShinya Maeda <shinya@gitlab.com>2017-11-28 20:47:59 +0900
commit0d95ce51be77d2a2a3e8421c56da6a8e5762a44f (patch)
tree8eb7dc298d806f699807f9275cdbe81dd9d596f6
parent8a55d2c5526ee5cb93bb40075dbbeaa6fcb01f91 (diff)
downloadgitlab-ce-0d95ce51be77d2a2a3e8421c56da6a8e5762a44f.tar.gz
Check diff between KubernetesService and Platforms::Kubernetes. Synchronize again.
-rw-r--r--app/models/clusters/platforms/kubernetes.rb124
-rw-r--r--app/models/project_services/kubernetes_service.rb5
2 files changed, 62 insertions, 67 deletions
diff --git a/app/models/clusters/platforms/kubernetes.rb b/app/models/clusters/platforms/kubernetes.rb
index a1e686d0d12..549b32ceef1 100644
--- a/app/models/clusters/platforms/kubernetes.rb
+++ b/app/models/clusters/platforms/kubernetes.rb
@@ -44,12 +44,6 @@ module Clusters
delegate :project, 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
if namespace.present?
namespace
@@ -58,10 +52,6 @@ module Clusters
end
end
- def default_namespace
- self.class.namespace_for_project(project) if project
- end
-
def predefined_variables
config = YAML.dump(kubeconfig)
@@ -101,41 +91,6 @@ module Clusters
{ pods: read_pods }
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
@kubeclient ||= kubernetes_service.kubeclient if manages_kubernetes_service?
end
@@ -161,29 +116,19 @@ module Clusters
private
- 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!
+ def kubeconfig
+ to_kubeconfig(
+ url: api_url,
+ namespace: actual_namespace,
+ token: token,
+ ca_pem: ca_pem)
end
- def kubernetes_service
- @kubernetes_service ||= project&.kubernetes_service
- end
+ def default_namespace
+ return unless project
- def ensure_kubernetes_service
- @kubernetes_service ||= kubernetes_service || project&.build_kubernetes_service
+ slug = "#{project.path}-#{project.id}".downcase
+ slug.gsub(/[^-a-z0-9]/, '-').gsub(/^-+/, '')
end
def build_kubeclient!(api_path: 'api', api_version: 'v1')
@@ -202,9 +147,29 @@ module Clusters
)
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
- return { username: username, password: password } if username && password
- return { bearer_token: token } if token
+ { bearer_token: token }
end
def join_api_url(api_path)
@@ -227,6 +192,31 @@ module Clusters
def enforce_namespace_to_lower_case
self.namespace = self.namespace&.downcase
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
diff --git a/app/models/project_services/kubernetes_service.rb b/app/models/project_services/kubernetes_service.rb
index bc62972dbb0..b82567ce2b3 100644
--- a/app/models/project_services/kubernetes_service.rb
+++ b/app/models/project_services/kubernetes_service.rb
@@ -1,3 +1,8 @@
+##
+# 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
include Gitlab::CurrentSettings
include Gitlab::Kubernetes