BigW Consortium Gitlab

General cleanup

parent 30938b89
...@@ -9,7 +9,7 @@ module Clusters ...@@ -9,7 +9,7 @@ module Clusters
belongs_to :cluster, class_name: 'Clusters::Cluster', foreign_key: :cluster_id belongs_to :cluster, class_name: 'Clusters::Cluster', foreign_key: :cluster_id
default_value_for :version, Gitlab::Clusters::Helm::HELM_VERSION default_value_for :version, Gitlab::Kubernetes::Helm::HELM_VERSION
def name def name
NAME NAME
......
...@@ -17,7 +17,7 @@ module Clusters ...@@ -17,7 +17,7 @@ module Clusters
end end
def helm_api def helm_api
@helm ||= Gitlab::Clusters::Helm.new(kubeclient) @helm ||= Gitlab::Kubernetes::Helm.new(kubeclient)
end end
end end
end end
...@@ -15,7 +15,6 @@ module Clusters ...@@ -15,7 +15,6 @@ module Clusters
rescue KubeException => ke rescue KubeException => ke
app.make_errored!("Kubernetes error: #{ke.message}") app.make_errored!("Kubernetes error: #{ke.message}")
rescue StandardError => e rescue StandardError => e
Rails.logger.warn(e.message)
app.make_errored!("Can't start installation process") app.make_errored!("Can't start installation process")
end end
end end
......
module Clusters
class InstallTillerService < BaseService
def execute
ensure_namespace
install
end
private
def kubernetes_service
return @kubernetes_service if defined?(@kubernetes_service)
@kubernetes_service = project&.kubernetes_service
end
def ensure_namespace
kubernetes_service&.ensure_namespace!
end
def install
kubernetes_service&.helm_client&.init!
end
end
end
class CreateClustersKubernetesHelmApps < ActiveRecord::Migration class CreateClustersKubernetesHelmApps < ActiveRecord::Migration
include Gitlab::Database::MigrationHelpers
DOWNTIME = false
def change def change
create_table :clusters_applications_helm do |t| create_table :clusters_applications_helm do |t|
t.references :cluster, null: false, unique: true, foreign_key: { on_delete: :cascade } t.references :cluster, null: false, unique: true, foreign_key: { on_delete: :cascade }
......
module Gitlab module Gitlab
module Clusters module Kubernetes
class Helm class Helm
Error = Class.new(StandardError)
HELM_VERSION = '2.7.0'.freeze HELM_VERSION = '2.7.0'.freeze
NAMESPACE = 'gitlab-managed-apps'.freeze NAMESPACE = 'gitlab-managed-apps'.freeze
COMMAND_SCRIPT = <<-EOS.freeze COMMAND_SCRIPT = <<-EOS.freeze
...@@ -18,12 +17,11 @@ module Gitlab ...@@ -18,12 +17,11 @@ module Gitlab
end end
def init! def init!
ensure_namespace! install(OpenStruct.new(name: 'helm'))
@kubeclient.create_pod(pod_resource(OpenStruct.new(name: 'helm')))
end end
def install(app) def install(app)
ensure_namespace! create_namespace! unless has_namespace?
@kubeclient.create_pod(pod_resource(app)) @kubeclient.create_pod(pod_resource(app))
end end
...@@ -86,12 +84,19 @@ module Gitlab ...@@ -86,12 +84,19 @@ module Gitlab
"install #{app.chart} --name #{app.name} --namespace #{NAMESPACE}" "install #{app.chart} --name #{app.name} --namespace #{NAMESPACE}"
end end
def ensure_namespace! def has_namespace?
return @has_namespace if defined?(@has_namespace)
begin begin
@kubeclient.get_namespace(NAMESPACE) @kubeclient.get_namespace(NAMESPACE)
@has_namespace = true
rescue KubeException => ke rescue KubeException => ke
raise ke unless ke.error_code == 404 raise ke unless ke.error_code == 404
false
end
end
def create_namespace!
namespace_resource = ::Kubeclient::Resource.new namespace_resource = ::Kubeclient::Resource.new
namespace_resource.metadata = {} namespace_resource.metadata = {}
namespace_resource.metadata.name = NAMESPACE namespace_resource.metadata.name = NAMESPACE
...@@ -100,5 +105,4 @@ module Gitlab ...@@ -100,5 +105,4 @@ module Gitlab
end end
end end
end end
end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment