blob: d5a753f67045f210d0cff5aa4e7fe23cd90c1312 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# frozen_string_literal: true
module Clusters
class VerifyService
attr_reader :cluster
def initialize(cluster)
@cluster = cluster
end
def execute
verify_connection!
rescue *Gitlab::Kubernetes::Errors::CONNECTION
:unreachable
rescue *Gitlab::Kubernetes::Errors::AUTHENTICATION
:authentication_failure
rescue Kubeclient::HttpError => e
kubeclient_error_status(e)
rescue => e
Gitlab::Sentry.track_acceptable_exception(e, extra: { cluster_id: cluster.id })
:unknown_failure
else
:connected
end
private
def verify_connection!
cluster.kubeclient.core_client.discover
end
# KubeClient uses the same error class
# For connection errors (eg. timeout) and
# for Kubernetes errors.
def kubeclient_error_status(error)
if timeout?(error.message)
:unreachable
else
:authentication_failure
end
end
def timeout?(message)
message&.match?(/timed out|timeout/i)
end
end
end
|