Class: Gitlab::Kubernetes::RolloutStatus

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/kubernetes/rollout_status.rb

Overview

Calculates the rollout status for a set of kubernetes deployments.

A GitLab environment may be composed of several Kubernetes deployments and other resources. The rollout status sums the Kubernetes deployments together.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(deployments, pods: [], ingresses: [], status: :found) ⇒ RolloutStatus

Returns a new instance of RolloutStatus.


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/gitlab/kubernetes/rollout_status.rb', line 54

def initialize(deployments, pods: [], ingresses: [], status: :found)
  @status       = status
  @deployments  = deployments
  @instances = RolloutInstances.new(deployments, pods).pod_instances
  @canary_ingress = ingresses.find(&:canary?)

  @completion =
    if @instances.empty?
      100
    else
      # We downcase the pod status in Gitlab::Kubernetes::Deployment#deployment_instance
      finished = @instances.count { |instance| instance[:status] == ::Gitlab::Kubernetes::Pod::RUNNING.downcase }

      (finished / @instances.count.to_f * 100).to_i
    end
end

Instance Attribute Details

#canary_ingressObject (readonly)

Returns the value of attribute canary_ingress.


11
12
13
# File 'lib/gitlab/kubernetes/rollout_status.rb', line 11

def canary_ingress
  @canary_ingress
end

#completionObject (readonly)

Returns the value of attribute completion.


11
12
13
# File 'lib/gitlab/kubernetes/rollout_status.rb', line 11

def completion
  @completion
end

#deploymentsObject (readonly)

Returns the value of attribute deployments.


11
12
13
# File 'lib/gitlab/kubernetes/rollout_status.rb', line 11

def deployments
  @deployments
end

#instancesObject (readonly)

Returns the value of attribute instances.


11
12
13
# File 'lib/gitlab/kubernetes/rollout_status.rb', line 11

def instances
  @instances
end

#statusObject (readonly)

Returns the value of attribute status.


11
12
13
# File 'lib/gitlab/kubernetes/rollout_status.rb', line 11

def status
  @status
end

Class Method Details

.from_deployments(*deployments_attrs, pods_attrs: [], ingresses: []) ⇒ Object


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/gitlab/kubernetes/rollout_status.rb', line 33

def self.from_deployments(*deployments_attrs, pods_attrs: [], ingresses: [])
  return new([], status: :not_found) if deployments_attrs.empty?

  deployments = deployments_attrs.map do |attrs|
    ::Gitlab::Kubernetes::Deployment.new(attrs, pods: pods_attrs)
  end
  deployments.sort_by!(&:order)

  pods = pods_attrs.map do |attrs|
    ::Gitlab::Kubernetes::Pod.new(attrs)
  end

  ingresses = ingresses.map { |ingress| ::Gitlab::Kubernetes::Ingress.new(ingress) }

  new(deployments, pods: pods, ingresses: ingresses)
end

.loadingObject


50
51
52
# File 'lib/gitlab/kubernetes/rollout_status.rb', line 50

def self.loading
  new([], status: :loading)
end

Instance Method Details

#canary_ingress_exists?Boolean

Returns:

  • (Boolean)

29
30
31
# File 'lib/gitlab/kubernetes/rollout_status.rb', line 29

def canary_ingress_exists?
  canary_ingress.present?
end

#complete?Boolean

Returns:

  • (Boolean)

13
14
15
# File 'lib/gitlab/kubernetes/rollout_status.rb', line 13

def complete?
  completion == 100
end

#found?Boolean

Returns:

  • (Boolean)

25
26
27
# File 'lib/gitlab/kubernetes/rollout_status.rb', line 25

def found?
  @status == :found
end

#loading?Boolean

Returns:

  • (Boolean)

17
18
19
# File 'lib/gitlab/kubernetes/rollout_status.rb', line 17

def loading?
  @status == :loading
end

#not_found?Boolean

Returns:

  • (Boolean)

21
22
23
# File 'lib/gitlab/kubernetes/rollout_status.rb', line 21

def not_found?
  @status == :not_found
end