Class: Clusters::KnativeServicesFinder
- Inherits:
-
Object
- Object
- Clusters::KnativeServicesFinder
show all
- Includes:
- Gitlab::Utils::StrongMemoize, ReactiveCaching
- Defined in:
- app/finders/clusters/knative_services_finder.rb
Constant Summary
collapse
- KNATIVE_STATES =
{
'checking' => 'checking',
'installed' => 'installed',
'not_found' => 'not_found'
}.freeze
ReactiveCaching::ExceededReactiveCacheLimit, ReactiveCaching::InvalidateReactiveCache, ReactiveCaching::WORK_TYPE
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of KnativeServicesFinder.
27
28
29
30
|
# File 'app/finders/clusters/knative_services_finder.rb', line 27
def initialize(cluster, environment)
@cluster = cluster
@environment = environment
end
|
Instance Attribute Details
#cluster ⇒ Object
Returns the value of attribute cluster.
18
19
20
|
# File 'app/finders/clusters/knative_services_finder.rb', line 18
def cluster
@cluster
end
|
#environment ⇒ Object
Returns the value of attribute environment.
18
19
20
|
# File 'app/finders/clusters/knative_services_finder.rb', line 18
def environment
@environment
end
|
Class Method Details
.from_cache(cluster_id, environment_id) ⇒ Object
20
21
22
23
24
25
|
# File 'app/finders/clusters/knative_services_finder.rb', line 20
def self.from_cache(cluster_id, environment_id)
cluster = Clusters::Cluster.find(cluster_id)
environment = Environment.find(environment_id)
new(cluster, environment)
end
|
Instance Method Details
#cache_args ⇒ Object
60
61
62
|
# File 'app/finders/clusters/knative_services_finder.rb', line 60
def cache_args
[cluster.id, environment.id]
end
|
#calculate_reactive_cache ⇒ Object
42
43
44
45
46
47
48
49
50
51
|
# File 'app/finders/clusters/knative_services_finder.rb', line 42
def calculate_reactive_cache(*)
ksvc = read_services
pods = knative_client.discovered ? read_pods : []
{ services: ksvc, pods: pods, knative_detected: knative_client.discovered }
end
|
#clear_cache! ⇒ Object
38
39
40
|
# File 'app/finders/clusters/knative_services_finder.rb', line 38
def clear_cache!
clear_reactive_cache!(*cache_args)
end
|
#knative_detected ⇒ Object
71
72
73
74
75
76
77
78
79
80
|
# File 'app/finders/clusters/knative_services_finder.rb', line 71
def knative_detected
cached_data = with_reactive_cache_memoized(*cache_args) { |data| data }
knative_state = cached_data.to_h[:knative_detected]
return KNATIVE_STATES['checking'] if knative_state.nil?
return KNATIVE_STATES['installed'] if knative_state
KNATIVE_STATES['uninstalled']
end
|
#model_name ⇒ Object
82
83
84
|
# File 'app/finders/clusters/knative_services_finder.rb', line 82
def model_name
::Gitlab::Utils.param_key(self.class)
end
|
#service_pod_details(service) ⇒ Object
64
65
66
67
68
69
|
# File 'app/finders/clusters/knative_services_finder.rb', line 64
def service_pod_details(service)
cached_data = with_reactive_cache_memoized(*cache_args) { |data| data }
cached_data.to_h.fetch(:pods, []).select do |pod|
filter_pods(pod, service)
end
end
|
#services ⇒ Object
53
54
55
56
57
58
|
# File 'app/finders/clusters/knative_services_finder.rb', line 53
def services
return [] unless search_namespace
cached_data = with_reactive_cache_memoized(*cache_args) { |data| data }
cached_data.to_h.fetch(:services, [])
end
|
#with_reactive_cache_memoized(*cache_args, &block) ⇒ Object
32
33
34
35
36
|
# File 'app/finders/clusters/knative_services_finder.rb', line 32
def with_reactive_cache_memoized(*cache_args, &block)
strong_memoize(:reactive_cache) do
with_reactive_cache(*cache_args, &block)
end
end
|