diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 18:42:06 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 18:42:06 +0000 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /app/models/clusters | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) | |
download | gitlab-ce-6e4e1050d9dba2b7b2523fdd1768823ab85feef4.tar.gz |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'app/models/clusters')
-rw-r--r-- | app/models/clusters/agent.rb | 20 | ||||
-rw-r--r-- | app/models/clusters/agent_token.rb | 14 | ||||
-rw-r--r-- | app/models/clusters/applications/cert_manager.rb | 6 | ||||
-rw-r--r-- | app/models/clusters/applications/crossplane.rb | 3 | ||||
-rw-r--r-- | app/models/clusters/applications/elastic_stack.rb | 9 | ||||
-rw-r--r-- | app/models/clusters/applications/fluentd.rb | 3 | ||||
-rw-r--r-- | app/models/clusters/applications/helm.rb | 6 | ||||
-rw-r--r-- | app/models/clusters/applications/ingress.rb | 5 | ||||
-rw-r--r-- | app/models/clusters/applications/jupyter.rb | 3 | ||||
-rw-r--r-- | app/models/clusters/applications/knative.rb | 6 | ||||
-rw-r--r-- | app/models/clusters/applications/prometheus.rb | 9 | ||||
-rw-r--r-- | app/models/clusters/applications/runner.rb | 5 | ||||
-rw-r--r-- | app/models/clusters/cluster.rb | 31 | ||||
-rw-r--r-- | app/models/clusters/concerns/application_core.rb | 2 | ||||
-rw-r--r-- | app/models/clusters/concerns/application_data.rb | 17 | ||||
-rw-r--r-- | app/models/clusters/concerns/application_status.rb | 20 | ||||
-rw-r--r-- | app/models/clusters/providers/aws.rb | 3 |
17 files changed, 82 insertions, 80 deletions
diff --git a/app/models/clusters/agent.rb b/app/models/clusters/agent.rb new file mode 100644 index 00000000000..c21759a3c3b --- /dev/null +++ b/app/models/clusters/agent.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module Clusters + class Agent < ApplicationRecord + self.table_name = 'cluster_agents' + + belongs_to :project, class_name: '::Project' # Otherwise, it will load ::Clusters::Project + + has_many :agent_tokens, class_name: 'Clusters::AgentToken' + + validates :name, + presence: true, + length: { maximum: 63 }, + uniqueness: { scope: :project_id }, + format: { + with: Gitlab::Regex.cluster_agent_name_regex, + message: Gitlab::Regex.cluster_agent_name_regex_message + } + end +end diff --git a/app/models/clusters/agent_token.rb b/app/models/clusters/agent_token.rb new file mode 100644 index 00000000000..e9f1ee4e033 --- /dev/null +++ b/app/models/clusters/agent_token.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Clusters + class AgentToken < ApplicationRecord + include TokenAuthenticatable + add_authentication_token_field :token, encrypted: :required + + self.table_name = 'cluster_agent_tokens' + + belongs_to :agent, class_name: 'Clusters::Agent' + + before_save :ensure_token + end +end diff --git a/app/models/clusters/applications/cert_manager.rb b/app/models/clusters/applications/cert_manager.rb index 53c90fa56d5..1efa44c39c5 100644 --- a/app/models/clusters/applications/cert_manager.rb +++ b/app/models/clusters/applications/cert_manager.rb @@ -38,8 +38,7 @@ module Clusters chart: chart, files: files.merge(cluster_issuer_file), preinstall: pre_install_script, - postinstall: post_install_script, - local_tiller_enabled: cluster.local_tiller_enabled? + postinstall: post_install_script ) end @@ -48,8 +47,7 @@ module Clusters name: 'certmanager', rbac: cluster.platform_kubernetes_rbac?, files: files, - postdelete: post_delete_script, - local_tiller_enabled: cluster.local_tiller_enabled? + postdelete: post_delete_script ) end diff --git a/app/models/clusters/applications/crossplane.rb b/app/models/clusters/applications/crossplane.rb index 2e5a8210b3c..420e56c1742 100644 --- a/app/models/clusters/applications/crossplane.rb +++ b/app/models/clusters/applications/crossplane.rb @@ -35,8 +35,7 @@ module Clusters version: VERSION, rbac: cluster.platform_kubernetes_rbac?, chart: chart, - files: files, - local_tiller_enabled: cluster.local_tiller_enabled? + files: files ) end diff --git a/app/models/clusters/applications/elastic_stack.rb b/app/models/clusters/applications/elastic_stack.rb index 58ac0c1f188..77996748b81 100644 --- a/app/models/clusters/applications/elastic_stack.rb +++ b/app/models/clusters/applications/elastic_stack.rb @@ -34,8 +34,7 @@ module Clusters repository: repository, files: files, preinstall: migrate_to_3_script, - postinstall: post_install_script, - local_tiller_enabled: cluster.local_tiller_enabled? + postinstall: post_install_script ) end @@ -44,8 +43,7 @@ module Clusters name: 'elastic-stack', rbac: cluster.platform_kubernetes_rbac?, files: files, - postdelete: post_delete_script, - local_tiller_enabled: cluster.local_tiller_enabled? + postdelete: post_delete_script ) end @@ -121,8 +119,7 @@ module Clusters Gitlab::Kubernetes::Helm::DeleteCommand.new( name: 'elastic-stack', rbac: cluster.platform_kubernetes_rbac?, - files: files, - local_tiller_enabled: cluster.local_tiller_enabled? + files: files ).delete_command, Gitlab::Kubernetes::KubectlCmd.delete("pvc", "--selector", "release=elastic-stack", "--namespace", Gitlab::Kubernetes::Helm::NAMESPACE) ] diff --git a/app/models/clusters/applications/fluentd.rb b/app/models/clusters/applications/fluentd.rb index 1bcd39618f6..3fd6e870edc 100644 --- a/app/models/clusters/applications/fluentd.rb +++ b/app/models/clusters/applications/fluentd.rb @@ -32,8 +32,7 @@ module Clusters version: VERSION, rbac: cluster.platform_kubernetes_rbac?, chart: chart, - files: files, - local_tiller_enabled: cluster.local_tiller_enabled? + files: files ) end diff --git a/app/models/clusters/applications/helm.rb b/app/models/clusters/applications/helm.rb index 226a9c26db0..4a1bcac4bb7 100644 --- a/app/models/clusters/applications/helm.rb +++ b/app/models/clusters/applications/helm.rb @@ -52,8 +52,7 @@ module Clusters Gitlab::Kubernetes::Helm::InitCommand.new( name: name, files: files, - rbac: cluster.platform_kubernetes_rbac?, - local_tiller_enabled: cluster.local_tiller_enabled? + rbac: cluster.platform_kubernetes_rbac? ) end @@ -61,8 +60,7 @@ module Clusters Gitlab::Kubernetes::Helm::ResetCommand.new( name: name, files: files, - rbac: cluster.platform_kubernetes_rbac?, - local_tiller_enabled: cluster.local_tiller_enabled? + rbac: cluster.platform_kubernetes_rbac? ) end diff --git a/app/models/clusters/applications/ingress.rb b/app/models/clusters/applications/ingress.rb index a44450ec7a9..1d08f38a2f1 100644 --- a/app/models/clusters/applications/ingress.rb +++ b/app/models/clusters/applications/ingress.rb @@ -3,7 +3,7 @@ module Clusters module Applications class Ingress < ApplicationRecord - VERSION = '1.29.7' + VERSION = '1.40.2' INGRESS_CONTAINER_NAME = 'nginx-ingress-controller' MODSECURITY_LOG_CONTAINER_NAME = 'modsecurity-log' MODSECURITY_MODE_LOGGING = "DetectionOnly" @@ -63,8 +63,7 @@ module Clusters version: VERSION, rbac: cluster.platform_kubernetes_rbac?, chart: chart, - files: files, - local_tiller_enabled: cluster.local_tiller_enabled? + files: files ) end diff --git a/app/models/clusters/applications/jupyter.rb b/app/models/clusters/applications/jupyter.rb index b737f0f962f..056ea355de6 100644 --- a/app/models/clusters/applications/jupyter.rb +++ b/app/models/clusters/applications/jupyter.rb @@ -45,8 +45,7 @@ module Clusters rbac: cluster.platform_kubernetes_rbac?, chart: chart, files: files, - repository: repository, - local_tiller_enabled: cluster.local_tiller_enabled? + repository: repository ) end diff --git a/app/models/clusters/applications/knative.rb b/app/models/clusters/applications/knative.rb index b55fc3c45fc..3047da12dd9 100644 --- a/app/models/clusters/applications/knative.rb +++ b/app/models/clusters/applications/knative.rb @@ -77,8 +77,7 @@ module Clusters chart: chart, files: files, repository: REPOSITORY, - postinstall: install_knative_metrics, - local_tiller_enabled: cluster.local_tiller_enabled? + postinstall: install_knative_metrics ) end @@ -100,8 +99,7 @@ module Clusters rbac: cluster.platform_kubernetes_rbac?, files: files, predelete: delete_knative_services_and_metrics, - postdelete: delete_knative_istio_leftovers, - local_tiller_enabled: cluster.local_tiller_enabled? + postdelete: delete_knative_istio_leftovers ) end diff --git a/app/models/clusters/applications/prometheus.rb b/app/models/clusters/applications/prometheus.rb index 101d782db3a..216bbbc1c5a 100644 --- a/app/models/clusters/applications/prometheus.rb +++ b/app/models/clusters/applications/prometheus.rb @@ -69,8 +69,7 @@ module Clusters rbac: cluster.platform_kubernetes_rbac?, chart: chart, files: files, - postinstall: install_knative_metrics, - local_tiller_enabled: cluster.local_tiller_enabled? + postinstall: install_knative_metrics ) end @@ -80,8 +79,7 @@ module Clusters version: version, rbac: cluster.platform_kubernetes_rbac?, chart: chart, - files: files_with_replaced_values(values), - local_tiller_enabled: cluster.local_tiller_enabled? + files: files_with_replaced_values(values) ) end @@ -90,8 +88,7 @@ module Clusters name: name, rbac: cluster.platform_kubernetes_rbac?, files: files, - predelete: delete_knative_istio_metrics, - local_tiller_enabled: cluster.local_tiller_enabled? + predelete: delete_knative_istio_metrics ) end diff --git a/app/models/clusters/applications/runner.rb b/app/models/clusters/applications/runner.rb index 3f0b4edde35..c041f605e6c 100644 --- a/app/models/clusters/applications/runner.rb +++ b/app/models/clusters/applications/runner.rb @@ -3,7 +3,7 @@ module Clusters module Applications class Runner < ApplicationRecord - VERSION = '0.18.2' + VERSION = '0.19.2' self.table_name = 'clusters_applications_runners' @@ -36,8 +36,7 @@ module Clusters rbac: cluster.platform_kubernetes_rbac?, chart: chart, files: files, - repository: repository, - local_tiller_enabled: cluster.local_tiller_enabled? + repository: repository ) end diff --git a/app/models/clusters/cluster.rb b/app/models/clusters/cluster.rb index 7641b6d2a4b..63aebdf1bdb 100644 --- a/app/models/clusters/cluster.rb +++ b/app/models/clusters/cluster.rb @@ -218,6 +218,24 @@ module Clusters provider&.status_name || connection_status.presence || :created end + def connection_error + with_reactive_cache do |data| + data[:connection_error] + end + end + + def node_connection_error + with_reactive_cache do |data| + data[:node_connection_error] + end + end + + def metrics_connection_error + with_reactive_cache do |data| + data[:metrics_connection_error] + end + end + def connection_status with_reactive_cache do |data| data[:connection_status] @@ -233,9 +251,7 @@ module Clusters def calculate_reactive_cache return unless enabled? - gitlab_kubernetes_nodes = Gitlab::Kubernetes::Node.new(self) - - { connection_status: retrieve_connection_status, nodes: gitlab_kubernetes_nodes.all.presence } + connection_data.merge(Gitlab::Kubernetes::Node.new(self).all) end def persisted_applications @@ -341,10 +357,6 @@ module Clusters end end - def local_tiller_enabled? - Feature.enabled?(:managed_apps_local_tiller, clusterable, default_enabled: true) - end - def prometheus_adapter application_prometheus end @@ -395,9 +407,10 @@ module Clusters @instance_domain ||= Gitlab::CurrentSettings.auto_devops_domain end - def retrieve_connection_status + def connection_data result = ::Gitlab::Kubernetes::KubeClient.graceful_request(id) { kubeclient.core_client.discover } - result[:status] + + { connection_status: result[:status], connection_error: result[:connection_error] }.compact end # To keep backward compatibility with AUTO_DEVOPS_DOMAIN diff --git a/app/models/clusters/concerns/application_core.rb b/app/models/clusters/concerns/application_core.rb index c1f63758906..760576ea1eb 100644 --- a/app/models/clusters/concerns/application_core.rb +++ b/app/models/clusters/concerns/application_core.rb @@ -15,7 +15,7 @@ module Clusters def set_initial_status return unless not_installable? - self.status = status_states[:installable] if cluster&.application_helm_available? || cluster&.local_tiller_enabled? + self.status = status_states[:installable] end def can_uninstall? diff --git a/app/models/clusters/concerns/application_data.rb b/app/models/clusters/concerns/application_data.rb index ade27e69642..22e597e9747 100644 --- a/app/models/clusters/concerns/application_data.rb +++ b/app/models/clusters/concerns/application_data.rb @@ -7,8 +7,7 @@ module Clusters Gitlab::Kubernetes::Helm::DeleteCommand.new( name: name, rbac: cluster.platform_kubernetes_rbac?, - files: files, - local_tiller_enabled: cluster.local_tiller_enabled? + files: files ) end @@ -21,23 +20,11 @@ module Clusters end def files - @files ||= begin - files = { 'values.yaml': values } - - files.merge!(certificate_files) if use_tiller_ssl? - - files - end + @files ||= { 'values.yaml': values } end private - def use_tiller_ssl? - return false if cluster.local_tiller_enabled? - - cluster.application_helm.has_ssl? - end - def certificate_files { 'ca.pem': ca_cert, diff --git a/app/models/clusters/concerns/application_status.rb b/app/models/clusters/concerns/application_status.rb index 86d74ed7b1c..95ac95448dd 100644 --- a/app/models/clusters/concerns/application_status.rb +++ b/app/models/clusters/concerns/application_status.rb @@ -79,7 +79,7 @@ module Clusters transition [:scheduled] => :uninstalling end - before_transition any => [:scheduled] do |application, _| + before_transition any => [:scheduled, :installed, :uninstalled] do |application, _| application.status_reason = nil end @@ -97,24 +97,6 @@ module Clusters application.status_reason = status_reason if status_reason end - before_transition any => [:installed, :updated] do |application, transition| - unless application.cluster.local_tiller_enabled? || application.is_a?(Clusters::Applications::Helm) - if transition.event == :make_externally_installed - # If an application is externally installed - # We assume the helm application is externally installed too - helm = application.cluster.application_helm || application.cluster.build_application_helm - - helm.make_externally_installed! - else - # When installing any application we are also performing an update - # of tiller (see Gitlab::Kubernetes::Helm::ClientCommand) so - # therefore we need to reflect that in the database. - - application.cluster.application_helm.update!(version: Gitlab::Kubernetes::Helm::HELM_VERSION) - end - end - end - after_transition any => [:uninstalling], :use_transactions => false do |application, _| application.prepare_uninstall end diff --git a/app/models/clusters/providers/aws.rb b/app/models/clusters/providers/aws.rb index faf587fb83d..86869361ed8 100644 --- a/app/models/clusters/providers/aws.rb +++ b/app/models/clusters/providers/aws.rb @@ -5,6 +5,9 @@ module Clusters class Aws < ApplicationRecord include Gitlab::Utils::StrongMemoize include Clusters::Concerns::ProviderStatus + include IgnorableColumns + + ignore_column :created_by_user_id, remove_with: '13.4', remove_after: '2020-08-22' self.table_name = 'cluster_providers_aws' |