Commit 2e7fd966 authored by Zamir Martins Filho's avatar Zamir Martins Filho

Add guard condition for when cilium

is not installed but there NetworkPolicies.
Payload will be returned while the error
message related to CiliumNetworkPolicy is kept.

Changelog: fixed
MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/63258
EE: true
parent ba1f6f13
......@@ -18,7 +18,7 @@ module NetworkPolicies
@kubeclient_info.each do |platform, namespace|
policies_per_environment, error_per_environment = execute_per_environment(platform, namespace)
policies += policies_per_environment
policies += policies_per_environment if policies_per_environment
errors << error_per_environment if error_per_environment
end
errors.empty? ? ServiceResponse.success(payload: policies) : kubernetes_error_response(errors.join, policies)
......@@ -35,7 +35,7 @@ module NetworkPolicies
.map { |resource| Gitlab::Kubernetes::CiliumNetworkPolicy.from_resource(resource) }
[policies, nil]
rescue Kubeclient::HttpError => e
[[], e]
[policies, e]
end
def has_deployment_platform?(kubeclient_info)
......
......@@ -56,7 +56,7 @@ RSpec.describe NetworkPolicies::ResourcesService do
end
end
context 'with Kubeclient::HttpError' do
context 'with Kubeclient::HttpError related to network policies' do
before do
allow(kubeclient).to receive(:get_network_policies).and_raise(Kubeclient::HttpError.new(500, 'system failure', nil))
end
......@@ -69,6 +69,20 @@ RSpec.describe NetworkPolicies::ResourcesService do
end
end
context 'with Kubeclient::HttpError related to cilium network policies' do
before do
allow(kubeclient).to receive(:get_network_policies) { [policy.generate] }
allow(kubeclient).to receive(:get_cilium_network_policies).and_raise(Kubeclient::HttpError.new(400, 'not found', nil))
end
it 'returns error response' do
expect(subject).to be_error
expect(subject.http_status).to eq(:bad_request)
expect(subject.message).not_to be_nil
expect(subject.payload.first.as_json).to eq(policy.as_json)
end
end
context 'without environment_id' do
let(:environment_id) { nil }
let(:cluster_2) { create(:cluster, :project) }
......
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