diff options
Diffstat (limited to 'spec/models/clusters/platforms/kubernetes_spec.rb')
-rw-r--r-- | spec/models/clusters/platforms/kubernetes_spec.rb | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/spec/models/clusters/platforms/kubernetes_spec.rb b/spec/models/clusters/platforms/kubernetes_spec.rb index b298bf2c8bb..a0ede9fb0d9 100644 --- a/spec/models/clusters/platforms/kubernetes_spec.rb +++ b/spec/models/clusters/platforms/kubernetes_spec.rb @@ -450,6 +450,42 @@ RSpec.describe Clusters::Platforms::Kubernetes do it { is_expected.to be_nil } end + context 'when there are ignored K8s connections errors' do + described_class::IGNORED_CONNECTION_EXCEPTIONS.each do |exception| + context "#{exception}" do + before do + exception_args = ['arg1'] + exception_args.push('arg2', 'arg3') if exception.name == 'Kubeclient::HttpError' + exception_instance = exception.new(*exception_args) + + allow_next_instance_of(Gitlab::Kubernetes::KubeClient) do |kube_client| + allow(kube_client).to receive(:get_pods).with(namespace: namespace).and_raise(exception_instance) + allow(kube_client).to receive(:get_deployments).with(namespace: namespace).and_raise(exception_instance) + allow(kube_client).to receive(:get_ingresses).with(namespace: namespace).and_raise(exception_instance) + end + end + + it 'does not raise error' do + expect { subject }.not_to raise_error + end + + it 'returns empty array for the K8s component keys' do + expect(subject).to include({ pods: [], deployments: [], ingresses: [] }) + end + + it 'logs the error' do + expect_next_instance_of(Gitlab::Kubernetes::Logger) do |logger| + expect(logger).to receive(:error) + .with(hash_including(event: :kube_connection_error)) + .and_call_original + end + + subject + end + end + end + end + context 'when kubernetes responds with 500s' do before do stub_kubeclient_pods(namespace, status: 500) @@ -457,7 +493,9 @@ RSpec.describe Clusters::Platforms::Kubernetes do stub_kubeclient_ingresses(namespace, status: 500) end - it { expect { subject }.to raise_error(Kubeclient::HttpError) } + it 'does not raise kubeclient http error' do + expect { subject }.not_to raise_error + end end context 'when kubernetes responds with 404s' do @@ -755,6 +793,18 @@ RSpec.describe Clusters::Platforms::Kubernetes do expect(rollout_status.instances.map { |p| p[:pod_name] }).to eq(['pod-a-1', 'pod-a-2', 'pod-b-1', 'pod-b-2']) end end + + # Scenario when there are K8s connection errors. + context 'when cache keys are defaulted' do + let(:cache_data) { Hash(deployments: [], pods: [], ingresses: []) } + + it 'does not raise error' do + expect { rollout_status }.not_to raise_error + + expect(rollout_status).to be_kind_of(::Gitlab::Kubernetes::RolloutStatus) + expect(rollout_status).to be_not_found + end + end end describe '#ingresses' do |