Class: Gitlab::Kubernetes::Deployment

Inherits:
Object
  • Object
show all
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/kubernetes/deployment.rb

Constant Summary collapse

STABLE_TRACK_VALUE =
'stable'

Instance Method Summary collapse

Methods included from Utils::StrongMemoize

#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

#annotationsObject


23
24
25
# File 'lib/gitlab/kubernetes/deployment.rb', line 23

def annotations
  .fetch('annotations', {})
end

#created_instancesObject


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.fetch('metadata', {})
    pod_name = ['name'] || ['generateName']
    pod_status = pod.dig('status', 'phase')

    deployment_instance(pod_name: pod_name, pod_status: pod_status)
  end
end

#filtered_pods_by_trackObject


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

#instancesObject


74
75
76
# File 'lib/gitlab/kubernetes/deployment.rb', line 74

def instances
  created_instances + not_created_instances
end

#labelsObject


19
20
21
# File 'lib/gitlab/kubernetes/deployment.rb', line 19

def labels
  .fetch('labels', {})
end

#nameObject


15
16
17
# File 'lib/gitlab/kubernetes/deployment.rb', line 15

def name
  ['name'] || 'unknown'
end

#not_created_instancesObject

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

#orderObject


35
36
37
# File 'lib/gitlab/kubernetes/deployment.rb', line 35

def order
  stable? ? 1 : 0
end

#outdated?Boolean

Returns:

  • (Boolean)

39
40
41
# File 'lib/gitlab/kubernetes/deployment.rb', line 39

def outdated?
  observed_generation < generation
end

#stable?Boolean

Returns:

  • (Boolean)

31
32
33
# File 'lib/gitlab/kubernetes/deployment.rb', line 31

def stable?
  track == 'stable'
end

#trackObject


27
28
29
# File 'lib/gitlab/kubernetes/deployment.rb', line 27

def track
  labels.fetch('track', STABLE_TRACK_VALUE)
end

#wanted_instancesObject


43
44
45
# File 'lib/gitlab/kubernetes/deployment.rb', line 43

def wanted_instances
  spec.fetch('replicas', 0)
end