Commit 1f3969a5 authored by Z.J. van de Weg's avatar Z.J. van de Weg

Detect invalid roll out status requests

Basically, if we can't find a pod with the given filter, we know the
status is invallid, so the exposed 'valid' flag will be false.

By @ayufan dupped as 'case 2', the last case to cover before the release
will be done in a seperate MR.
parent 388488fd
......@@ -3,6 +3,7 @@ class RolloutStatusEntity < Grape::Entity
expose :instances
expose :completion
expose :valid?, as: :valid
expose :is_completed do |rollout_status|
rollout_status.complete?
......
---
title: Set deployment status invalid when the environments does not match a k8s label
merge_request:
author:
......@@ -12,20 +12,27 @@ module Gitlab
completion == 100
end
def valid?
@valid
end
def self.from_specs(*specs)
return new([], valid: false) if specs.empty?
deployments = specs.map { |spec| ::Gitlab::Kubernetes::Deployment.new(spec) }
new(deployments)
end
def initialize(deployments)
@deployments = deployments
@instances = deployments.flat_map(&:instances)
def initialize(deployments, valid: true)
@valid = valid
@deployments = deployments
@instances = deployments.flat_map(&:instances)
@completion =
if @instances.empty?
100
else
finished = @instances.select {|instance| instance[:status] == 'finished' }.count
finished = @instances.select { |instance| instance[:status] == 'finished' }.count
(finished / @instances.count.to_f * 100).to_i
end
......
......@@ -11,6 +11,8 @@ describe Gitlab::Kubernetes::RolloutStatus do
end
let(:specs) { specs_all_finished }
let(:specs_none) { [] }
subject(:rollout_status) { described_class.from_specs(*specs) }
describe '#deployments' do
......@@ -61,4 +63,16 @@ describe Gitlab::Kubernetes::RolloutStatus do
it { is_expected.to be_falsy}
end
end
describe '#valid?' do
context 'when the specs are passed' do
it { is_expected.to be_valid }
end
context 'when no specs are passed' do
let(:specs) { specs_none }
it { is_expected.not_to be_valid }
end
end
end
......@@ -13,4 +13,5 @@ describe RolloutStatusEntity do
it { is_expected.to have_key(:instances) }
it { is_expected.to have_key(:completion) }
it { is_expected.to have_key(:is_completed) }
it { is_expected.to have_key(:valid) }
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment