diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 15:09:35 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-04-20 15:09:35 +0300 |
commit | 76e4e8f1b0629f8af2c627ae34901df77073e3c9 (patch) | |
tree | f5744161137b5e8c5d0de992c7585828ce52676c /app/models/clusters | |
parent | 79347b42ae647fca1c1b2e514a93d36d422068d3 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/clusters')
-rw-r--r-- | app/models/clusters/platforms/kubernetes.rb | 46 |
1 files changed, 43 insertions, 3 deletions
diff --git a/app/models/clusters/platforms/kubernetes.rb b/app/models/clusters/platforms/kubernetes.rb index 1bd8e8b44cb..66bce755598 100644 --- a/app/models/clusters/platforms/kubernetes.rb +++ b/app/models/clusters/platforms/kubernetes.rb @@ -11,6 +11,16 @@ module Clusters RESERVED_NAMESPACES = %w(gitlab-managed-apps).freeze + IGNORED_CONNECTION_EXCEPTIONS = [ + Gitlab::UrlBlocker::BlockedUrlError, + Kubeclient::HttpError, + Errno::ECONNREFUSED, + URI::InvalidURIError, + Errno::EHOSTUNREACH, + OpenSSL::X509::StoreError, + OpenSSL::SSL::SSLError + ].freeze + self.table_name = 'cluster_platforms_kubernetes' self.reactive_cache_work_type = :external_dependency @@ -102,10 +112,23 @@ module Clusters def calculate_reactive_cache_for(environment) return unless enabled? - pods = read_pods(environment.deployment_namespace) - deployments = read_deployments(environment.deployment_namespace) + pods = [] + deployments = [] + ingresses = [] + + begin + pods = read_pods(environment.deployment_namespace) + deployments = read_deployments(environment.deployment_namespace) + + ingresses = read_ingresses(environment.deployment_namespace) + rescue *IGNORED_CONNECTION_EXCEPTIONS => e + log_kube_connection_error(e) - ingresses = read_ingresses(environment.deployment_namespace) + # Return hash with default values so that it is cached. + return { + pods: pods, deployments: deployments, ingresses: ingresses + } + end # extract only the data required for display to avoid unnecessary caching { @@ -292,6 +315,23 @@ module Clusters } end end + + def log_kube_connection_error(error) + logger.error({ + exception: { + class: error.class.name, + message: error.message + }, + status_code: error.error_code, + namespace: self.namespace, + class_name: self.class.name, + event: :kube_connection_error + }) + end + + def logger + @logger ||= Gitlab::Kubernetes::Logger.build + end end end end |