debian-mirror-gitlab/app/models/clusters/applications/elastic_stack.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

114 lines
3.4 KiB
Ruby
Raw Normal View History

2019-12-26 22:10:19 +05:30
# frozen_string_literal: true
module Clusters
module Applications
class ElasticStack < ApplicationRecord
2021-06-08 01:23:25 +05:30
include ::Clusters::Concerns::ElasticsearchClient
2019-12-26 22:10:19 +05:30
2021-06-08 01:23:25 +05:30
VERSION = '3.0.0'
2019-12-26 22:10:19 +05:30
self.table_name = 'clusters_applications_elastic_stacks'
include ::Clusters::Concerns::ApplicationCore
include ::Clusters::Concerns::ApplicationStatus
include ::Clusters::Concerns::ApplicationVersion
include ::Clusters::Concerns::ApplicationData
2020-03-13 15:44:24 +05:30
default_value_for :version, VERSION
2019-12-26 22:10:19 +05:30
2021-06-08 01:23:25 +05:30
after_destroy do
cluster&.find_or_build_integration_elastic_stack&.update(enabled: false, chart_version: nil)
end
state_machine :status do
after_transition any => [:installed] do |application|
application.cluster&.find_or_build_integration_elastic_stack&.update(enabled: true, chart_version: application.version)
end
after_transition any => [:uninstalled] do |application|
application.cluster&.find_or_build_integration_elastic_stack&.update(enabled: false, chart_version: nil)
end
end
2019-12-26 22:10:19 +05:30
def chart
2020-05-24 23:13:21 +05:30
'elastic-stack/elastic-stack'
end
def repository
'https://charts.gitlab.io'
2019-12-26 22:10:19 +05:30
end
def install_command
2021-01-29 00:20:46 +05:30
helm_command_module::InstallCommand.new(
2019-12-26 22:10:19 +05:30
name: 'elastic-stack',
version: VERSION,
rbac: cluster.platform_kubernetes_rbac?,
chart: chart,
2020-05-24 23:13:21 +05:30
repository: repository,
2020-03-13 15:44:24 +05:30
files: files,
2020-05-24 23:13:21 +05:30
preinstall: migrate_to_3_script,
2020-10-24 23:57:45 +05:30
postinstall: post_install_script
2019-12-26 22:10:19 +05:30
)
end
def uninstall_command
2021-01-29 00:20:46 +05:30
helm_command_module::DeleteCommand.new(
2019-12-26 22:10:19 +05:30
name: 'elastic-stack',
rbac: cluster.platform_kubernetes_rbac?,
files: files,
2020-10-24 23:57:45 +05:30
postdelete: post_delete_script
2019-12-26 22:10:19 +05:30
)
end
2020-03-13 15:44:24 +05:30
def files
super.merge('wait-for-elasticsearch.sh': File.read("#{Rails.root}/vendor/elastic_stack/wait-for-elasticsearch.sh"))
end
2020-05-24 23:13:21 +05:30
def chart_above_v2?
Gem::Version.new(version) >= Gem::Version.new('2.0.0')
end
def chart_above_v3?
Gem::Version.new(version) >= Gem::Version.new('3.0.0')
end
2019-12-26 22:10:19 +05:30
private
2020-05-24 23:13:21 +05:30
def service_name
chart_above_v3? ? 'elastic-stack-elasticsearch-master' : 'elastic-stack-elasticsearch-client'
end
def pvc_selector
chart_above_v3? ? "app=elastic-stack-elasticsearch-master" : "release=elastic-stack"
end
2020-03-13 15:44:24 +05:30
def post_install_script
[
2021-01-29 00:20:46 +05:30
"timeout 60 sh /data/helm/elastic-stack/config/wait-for-elasticsearch.sh http://elastic-stack-elasticsearch-master:9200"
2020-03-13 15:44:24 +05:30
]
2019-12-26 22:10:19 +05:30
end
def post_delete_script
[
2020-05-24 23:13:21 +05:30
Gitlab::Kubernetes::KubectlCmd.delete("pvc", "--selector", pvc_selector, "--namespace", Gitlab::Kubernetes::Helm::NAMESPACE)
2020-03-13 15:44:24 +05:30
]
2019-12-26 22:10:19 +05:30
end
2020-05-24 23:13:21 +05:30
def migrate_to_3_script
return [] if !updating? || chart_above_v3?
# Chart version 3.0.0 moves to our own chart at https://gitlab.com/gitlab-org/charts/elastic-stack
# and is not compatible with pre-existing resources. We first remove them.
[
2021-01-29 00:20:46 +05:30
helm_command_module::DeleteCommand.new(
2020-05-24 23:13:21 +05:30
name: 'elastic-stack',
rbac: cluster.platform_kubernetes_rbac?,
2020-10-24 23:57:45 +05:30
files: files
2020-05-24 23:13:21 +05:30
).delete_command,
Gitlab::Kubernetes::KubectlCmd.delete("pvc", "--selector", "release=elastic-stack", "--namespace", Gitlab::Kubernetes::Helm::NAMESPACE)
]
end
2019-12-26 22:10:19 +05:30
end
end
end