Commit da75f91b authored by Zamir Martins Filho's avatar Zamir Martins Filho Committed by Ash McKenzie

Add Cilium support into kube_client

Cilium apis will be used in the
following MRs which will be adding
CiliumNetworkPolicy.
parent fb02ab6a
---
title: Add Cilium APIs as part of kube_client
merge_request: 37526
author:
type: changed
...@@ -21,7 +21,8 @@ module Gitlab ...@@ -21,7 +21,8 @@ module Gitlab
istio: { group: 'apis/networking.istio.io', version: 'v1alpha3' }, istio: { group: 'apis/networking.istio.io', version: 'v1alpha3' },
knative: { group: 'apis/serving.knative.dev', version: 'v1alpha1' }, knative: { group: 'apis/serving.knative.dev', version: 'v1alpha1' },
metrics: { group: 'apis/metrics.k8s.io', version: 'v1beta1' }, metrics: { group: 'apis/metrics.k8s.io', version: 'v1beta1' },
networking: { group: 'apis/networking.k8s.io', version: 'v1' } networking: { group: 'apis/networking.k8s.io', version: 'v1' },
cilium_networking: { group: 'apis/cilium.io', version: 'v2' }
}.freeze }.freeze
SUPPORTED_API_GROUPS.each do |name, params| SUPPORTED_API_GROUPS.each do |name, params|
...@@ -95,6 +96,14 @@ module Gitlab ...@@ -95,6 +96,14 @@ module Gitlab
:delete_network_policy, :delete_network_policy,
to: :networking_client to: :networking_client
# CiliumNetworkPolicy methods delegate to the apis/cilium.io api
# group client
delegate :create_cilium_network_policy,
:get_cilium_network_policies,
:update_cilium_network_policy,
:delete_cilium_network_policy,
to: :cilium_networking_client
attr_reader :api_prefix, :kubeclient_options attr_reader :api_prefix, :kubeclient_options
DEFAULT_KUBECLIENT_OPTIONS = { DEFAULT_KUBECLIENT_OPTIONS = {
......
...@@ -227,6 +227,20 @@ RSpec.describe Gitlab::Kubernetes::KubeClient do ...@@ -227,6 +227,20 @@ RSpec.describe Gitlab::Kubernetes::KubeClient do
end end
end end
describe '#cilium_networking_client' do
subject { client.cilium_networking_client }
it_behaves_like 'a Kubeclient'
it 'has the cilium API group endpoint' do
expect(subject.api_endpoint.to_s).to match(%r{\/apis\/cilium.io\Z})
end
it 'has the api_version' do
expect(subject.instance_variable_get(:@api_version)).to eq('v2')
end
end
describe '#metrics_client' do describe '#metrics_client' do
subject { client.metrics_client } subject { client.metrics_client }
...@@ -380,6 +394,30 @@ RSpec.describe Gitlab::Kubernetes::KubeClient do ...@@ -380,6 +394,30 @@ RSpec.describe Gitlab::Kubernetes::KubeClient do
end end
end end
describe 'cilium API group' do
let(:cilium_networking_client) { client.cilium_networking_client }
[
:create_cilium_network_policy,
:get_cilium_network_policies,
:update_cilium_network_policy,
:delete_cilium_network_policy
].each do |method|
describe "##{method}" do
include_examples 'redirection not allowed', method
include_examples 'dns rebinding not allowed', method
it 'delegates to the cilium client' do
expect(client).to delegate_method(method).to(:cilium_networking_client)
end
it 'responds to the method' do
expect(client).to respond_to method
end
end
end
end
describe 'non-entity methods' do describe 'non-entity methods' do
it 'does not proxy for non-entity methods' do it 'does not proxy for non-entity methods' do
expect(client).not_to respond_to :proxy_url expect(client).not_to respond_to :proxy_url
......
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