diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-05 18:08:48 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-05 18:08:48 +0300 |
commit | 205b6baf2677879c35968d2b659225b58e8a1227 (patch) | |
tree | 10ed06185aae2f6ed6e7c61349a92acab605daca /app/models/clusters | |
parent | f34077e88198da754b4efecd1ce1d996ce982286 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/clusters')
-rw-r--r-- | app/models/clusters/applications/elastic_stack.rb | 113 | ||||
-rw-r--r-- | app/models/clusters/cluster.rb | 21 | ||||
-rw-r--r-- | app/models/clusters/concerns/elasticsearch_client.rb | 38 | ||||
-rw-r--r-- | app/models/clusters/integrations/elastic_stack.rb | 40 |
4 files changed, 0 insertions, 212 deletions
diff --git a/app/models/clusters/applications/elastic_stack.rb b/app/models/clusters/applications/elastic_stack.rb deleted file mode 100644 index 73c731aab1a..00000000000 --- a/app/models/clusters/applications/elastic_stack.rb +++ /dev/null @@ -1,113 +0,0 @@ -# frozen_string_literal: true - -module Clusters - module Applications - class ElasticStack < ApplicationRecord - include ::Clusters::Concerns::ElasticsearchClient - - VERSION = '3.0.0' - - self.table_name = 'clusters_applications_elastic_stacks' - - include ::Clusters::Concerns::ApplicationCore - include ::Clusters::Concerns::ApplicationStatus - include ::Clusters::Concerns::ApplicationVersion - include ::Clusters::Concerns::ApplicationData - - default_value_for :version, VERSION - - 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 - - def chart - 'elastic-stack/elastic-stack' - end - - def repository - 'https://charts.gitlab.io' - end - - def install_command - helm_command_module::InstallCommand.new( - name: 'elastic-stack', - version: VERSION, - rbac: cluster.platform_kubernetes_rbac?, - chart: chart, - repository: repository, - files: files, - preinstall: migrate_to_3_script, - postinstall: post_install_script - ) - end - - def uninstall_command - helm_command_module::DeleteCommand.new( - name: 'elastic-stack', - rbac: cluster.platform_kubernetes_rbac?, - files: files, - postdelete: post_delete_script - ) - end - - def files - super.merge('wait-for-elasticsearch.sh': File.read("#{Rails.root}/vendor/elastic_stack/wait-for-elasticsearch.sh")) - end - - 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 - - private - - 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 - - def post_install_script - [ - "timeout 60 sh /data/helm/elastic-stack/config/wait-for-elasticsearch.sh http://elastic-stack-elasticsearch-master:9200" - ] - end - - def post_delete_script - [ - Gitlab::Kubernetes::KubectlCmd.delete("pvc", "--selector", pvc_selector, "--namespace", Gitlab::Kubernetes::Helm::NAMESPACE) - ] - end - - 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. - [ - helm_command_module::DeleteCommand.new( - name: 'elastic-stack', - rbac: cluster.platform_kubernetes_rbac?, - files: files - ).delete_command, - Gitlab::Kubernetes::KubectlCmd.delete("pvc", "--selector", "release=elastic-stack", "--namespace", Gitlab::Kubernetes::Helm::NAMESPACE) - ] - end - end - end -end diff --git a/app/models/clusters/cluster.rb b/app/models/clusters/cluster.rb index 014f7530357..ad1e7dc305f 100644 --- a/app/models/clusters/cluster.rb +++ b/app/models/clusters/cluster.rb @@ -20,7 +20,6 @@ module Clusters Clusters::Applications::Runner.application_name => Clusters::Applications::Runner, Clusters::Applications::Jupyter.application_name => Clusters::Applications::Jupyter, Clusters::Applications::Knative.application_name => Clusters::Applications::Knative, - Clusters::Applications::ElasticStack.application_name => Clusters::Applications::ElasticStack, Clusters::Applications::Cilium.application_name => Clusters::Applications::Cilium }.freeze DEFAULT_ENVIRONMENT = '*' @@ -51,7 +50,6 @@ module Clusters has_one :platform_kubernetes, class_name: 'Clusters::Platforms::Kubernetes', inverse_of: :cluster, autosave: true has_one :integration_prometheus, class_name: 'Clusters::Integrations::Prometheus', inverse_of: :cluster - has_one :integration_elastic_stack, class_name: 'Clusters::Integrations::ElasticStack', inverse_of: :cluster def self.has_one_cluster_application(name) # rubocop:disable Naming/PredicateName application = APPLICATIONS[name.to_s] @@ -66,7 +64,6 @@ module Clusters has_one_cluster_application :runner has_one_cluster_application :jupyter has_one_cluster_application :knative - has_one_cluster_application :elastic_stack has_one_cluster_application :cilium has_many :kubernetes_namespaces @@ -102,7 +99,6 @@ module Clusters delegate :available?, to: :application_helm, prefix: true, allow_nil: true delegate :available?, to: :application_ingress, prefix: true, allow_nil: true delegate :available?, to: :application_knative, prefix: true, allow_nil: true - delegate :available?, to: :integration_elastic_stack, prefix: true, allow_nil: true delegate :available?, to: :integration_prometheus, prefix: true, allow_nil: true delegate :external_ip, to: :application_ingress, prefix: true, allow_nil: true delegate :external_hostname, to: :application_ingress, prefix: true, allow_nil: true @@ -136,7 +132,6 @@ module Clusters scope :gcp_installed, -> { gcp_provided.joins(:provider_gcp).merge(Clusters::Providers::Gcp.with_status(:created)) } scope :aws_installed, -> { aws_provided.joins(:provider_aws).merge(Clusters::Providers::Aws.with_status(:created)) } - scope :with_available_elasticstack, -> { joins(:application_elastic_stack).merge(::Clusters::Applications::ElasticStack.available) } scope :distinct_with_deployed_environments, -> { joins(:environments).merge(::Deployment.success).distinct } scope :managed, -> { where(managed: true) } @@ -271,10 +266,6 @@ module Clusters integration_prometheus || build_integration_prometheus end - def find_or_build_integration_elastic_stack - integration_elastic_stack || build_integration_elastic_stack - end - def provider if gcp? provider_gcp @@ -309,18 +300,6 @@ module Clusters platform_kubernetes&.kubeclient if kubernetes? end - def elastic_stack_adapter - integration_elastic_stack - end - - def elasticsearch_client - elastic_stack_adapter&.elasticsearch_client - end - - def elastic_stack_available? - !!integration_elastic_stack_available? - end - def kubernetes_namespace_for(environment, deployable: environment.last_deployable) if deployable && environment.project_id != deployable.project_id raise ArgumentError, 'environment.project_id must match deployable.project_id' diff --git a/app/models/clusters/concerns/elasticsearch_client.rb b/app/models/clusters/concerns/elasticsearch_client.rb deleted file mode 100644 index e9aab7897a8..00000000000 --- a/app/models/clusters/concerns/elasticsearch_client.rb +++ /dev/null @@ -1,38 +0,0 @@ -# frozen_string_literal: true - -module Clusters - module Concerns - module ElasticsearchClient - include ::Gitlab::Utils::StrongMemoize - - ELASTICSEARCH_PORT = 9200 - ELASTICSEARCH_NAMESPACE = 'gitlab-managed-apps' - - def elasticsearch_client(timeout: nil) - strong_memoize(:elasticsearch_client) do - kube_client = cluster&.kubeclient&.core_client - next unless kube_client - - proxy_url = kube_client.proxy_url('service', service_name, ELASTICSEARCH_PORT, ELASTICSEARCH_NAMESPACE) - - Elasticsearch::Client.new(url: proxy_url, adapter: :net_http) do |faraday| - # ensures headers containing auth data are appended to original client options - faraday.headers.merge!(kube_client.headers) - # ensure TLS certs are properly verified - faraday.ssl[:verify] = kube_client.ssl_options[:verify_ssl] - faraday.ssl[:cert_store] = kube_client.ssl_options[:cert_store] - faraday.options.timeout = timeout unless timeout.nil? - end - - rescue Kubeclient::HttpError => error - # If users have mistakenly set parameters or removed the depended clusters, - # `proxy_url` could raise an exception because gitlab can not communicate with the cluster. - # We check for a nil client in downstream use and behaviour is equivalent to an empty state - log_exception(error, :failed_to_create_elasticsearch_client) - - nil - end - end - end - end -end diff --git a/app/models/clusters/integrations/elastic_stack.rb b/app/models/clusters/integrations/elastic_stack.rb deleted file mode 100644 index 97d73d252b9..00000000000 --- a/app/models/clusters/integrations/elastic_stack.rb +++ /dev/null @@ -1,40 +0,0 @@ -# frozen_string_literal: true - -module Clusters - module Integrations - class ElasticStack < ApplicationRecord - include ::Clusters::Concerns::ElasticsearchClient - include ::Clusters::Concerns::KubernetesLogger - - self.table_name = 'clusters_integration_elasticstack' - self.primary_key = :cluster_id - - belongs_to :cluster, class_name: 'Clusters::Cluster', foreign_key: :cluster_id - - validates :cluster, presence: true - validates :enabled, inclusion: { in: [true, false] } - - scope :enabled, -> { where(enabled: true) } - - def available? - enabled - end - - def service_name - chart_above_v3? ? 'elastic-stack-elasticsearch-master' : 'elastic-stack-elasticsearch-client' - end - - def chart_above_v2? - return true if chart_version.nil? - - Gem::Version.new(chart_version) >= Gem::Version.new('2.0.0') - end - - def chart_above_v3? - return true if chart_version.nil? - - Gem::Version.new(chart_version) >= Gem::Version.new('3.0.0') - end - end - end -end |