diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-19 10:33:21 +0300 |
commit | 36a59d088eca61b834191dacea009677a96c052f (patch) | |
tree | e4f33972dab5d8ef79e3944a9f403035fceea43f /app/models/clusters/platforms | |
parent | a1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff) |
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'app/models/clusters/platforms')
-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..9d4f0a89403 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.try(: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 |