Class: Gitlab::Kubernetes::Deployment
- Inherits:
-
Object
- Object
- Gitlab::Kubernetes::Deployment
show all
- Includes:
- Utils::StrongMemoize
- Defined in:
- lib/gitlab/kubernetes/deployment.rb
Constant Summary
collapse
- STABLE_TRACK_VALUE =
'stable'
Instance Method Summary
collapse
#clear_memoization, #strong_memoize, #strong_memoized?
Constructor Details
#initialize(attributes = {}, pods: []) ⇒ Deployment
Returns a new instance of Deployment.
10
11
12
13
|
# File 'lib/gitlab/kubernetes/deployment.rb', line 10
def initialize(attributes = {}, pods: [])
@attributes = attributes
@pods = pods
end
|
Instance Method Details
#annotations ⇒ Object
23
24
25
|
# File 'lib/gitlab/kubernetes/deployment.rb', line 23
def annotations
metadata.fetch('annotations', {})
end
|
#created_instances ⇒ Object
47
48
49
50
51
52
53
54
55
|
# File 'lib/gitlab/kubernetes/deployment.rb', line 47
def created_instances
filtered_pods_by_track.map do |pod|
pod_metadata = pod.fetch('metadata', {})
pod_name = pod_metadata['name'] || pod_metadata['generateName']
pod_status = pod.dig('status', 'phase')
deployment_instance(pod_name: pod_name, pod_status: pod_status)
end
end
|
#filtered_pods_by_track ⇒ Object
68
69
70
71
72
|
# File 'lib/gitlab/kubernetes/deployment.rb', line 68
def filtered_pods_by_track
strong_memoize(:filtered_pods_by_track) do
@pods.select { |pod| has_same_track?(pod) }
end
end
|
#instances ⇒ Object
74
75
76
|
# File 'lib/gitlab/kubernetes/deployment.rb', line 74
def instances
created_instances + not_created_instances
end
|
#labels ⇒ Object
19
20
21
|
# File 'lib/gitlab/kubernetes/deployment.rb', line 19
def labels
metadata.fetch('labels', {})
end
|
#name ⇒ Object
15
16
17
|
# File 'lib/gitlab/kubernetes/deployment.rb', line 15
def name
metadata['name'] || 'unknown'
end
|
#not_created_instances ⇒ Object
These are replicas that did not get created yet, So they still do not have any associated pod, these are marked as pending instances.
60
61
62
63
64
65
66
|
# File 'lib/gitlab/kubernetes/deployment.rb', line 60
def not_created_instances
pending_instances_count = wanted_instances - filtered_pods_by_track.count
return [] if pending_instances_count <= 0
Array.new(pending_instances_count, deployment_instance(pod_name: 'Not provided', pod_status: 'Pending'))
end
|
#order ⇒ Object
35
36
37
|
# File 'lib/gitlab/kubernetes/deployment.rb', line 35
def order
stable? ? 1 : 0
end
|
#outdated? ⇒ Boolean
39
40
41
|
# File 'lib/gitlab/kubernetes/deployment.rb', line 39
def outdated?
observed_generation < generation
end
|
#stable? ⇒ Boolean
31
32
33
|
# File 'lib/gitlab/kubernetes/deployment.rb', line 31
def stable?
track == 'stable'
end
|
#track ⇒ Object
27
28
29
|
# File 'lib/gitlab/kubernetes/deployment.rb', line 27
def track
labels.fetch('track', STABLE_TRACK_VALUE)
end
|
#wanted_instances ⇒ Object
43
44
45
|
# File 'lib/gitlab/kubernetes/deployment.rb', line 43
def wanted_instances
spec.fetch('replicas', 0)
end
|