Skip to content

Commit

Permalink
f-145: corrects cilium BGP ip pools setting corrections
Browse files Browse the repository at this point in the history
Signed-off-by: Aleix Ramírez <aramirez@opennebula.io>
  • Loading branch information
aleixrm committed Dec 17, 2024
1 parent d6ea0d4 commit 4a58748
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 13 deletions.
7 changes: 5 additions & 2 deletions appliances/OneKE/cilium.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ def configure_cilium(manifest_dir = K8S_MANIFEST_DIR, endpoint = ONEAPP_K8S_CONT
if ONEAPP_K8S_CNI_CONFIG.nil?
msg :info, 'Create Cilium CRD config from user-provided ranges'

enable_bgp = ONEAPP_K8S_CILIUM_ENABLE_BGP \
|| (ONEAPP_K8S_CILIUM_ENABLE_BGP.nil? && !ONEAPP_K8S_CILIUM_RANGES.empty?)

documents = YAML.load_stream <<~MANIFEST
---
apiVersion: helm.cattle.io/v1
Expand All @@ -39,10 +42,10 @@ def configure_cilium(manifest_dir = K8S_MANIFEST_DIR, endpoint = ONEAPP_K8S_CONT
chainingMode: "none"
exclusive: false
bgpControlPlane:
enabled: #{ONEAPP_K8S_CILIUM_ENABLE_BGP}
enabled: #{enable_bgp}
MANIFEST

if ONEAPP_K8S_CILIUM_ENABLE_BGP and ONEAPP_K8S_CILIUM_RANGES.is_a?(Array)
if enable_bgp
documents += YAML.load_stream <<~MANIFEST
---
apiVersion: cilium.io/v2alpha1
Expand Down
59 changes: 49 additions & 10 deletions appliances/OneKE/cilium_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,10 @@
end

RSpec.describe 'configure_cilium' do
it 'should apply user-defined ranges (empty)' do
it 'should apply user-defined ranges' do
stub_const 'ONEAPP_K8S_CONTROL_PLANE_EP', '192.168.150.86:6443'
stub_const 'ONEAPP_K8S_CNI_PLUGIN', 'cilium'
stub_const 'ONEAPP_K8S_CNI_CONFIG', nil
stub_const 'ONEAPP_K8S_CILIUM_ENABLE_BGP', true
stub_const 'ONEAPP_K8S_CILIUM_RANGES', []
stub_const 'ONEAPP_K8S_CILIUM_RANGES', ['192.168.150.128/25', '10.11.12.0/24']
output = YAML.load_stream <<~MANIFEST
---
apiVersion: helm.cattle.io/v1
Expand All @@ -65,7 +63,9 @@
name: default
namespace: kube-system
spec:
blocks: {}
blocks:
- cidr: 192.168.150.128/25
- cidr: 10.11.12.0/24
allowFirstLastIPs: "No"
MANIFEST
Dir.mktmpdir do |temp_dir|
Expand All @@ -75,7 +75,37 @@
end
end

it 'should apply user-defined ranges' do
it 'should not define ip ranges when ONEAPP_K8S_CILIUM_ENABLE_BGP is false and ONEAPP_K8S_CILIUM_RANGES is not empty' do
stub_const 'ONEAPP_K8S_CONTROL_PLANE_EP', '192.168.150.86:6443'
stub_const 'ONEAPP_K8S_CNI_PLUGIN', 'cilium'
stub_const 'ONEAPP_K8S_CILIUM_ENABLE_BGP', false
stub_const 'ONEAPP_K8S_CILIUM_RANGES', ['192.168.150.128/25', '10.11.12.0/24']
output = YAML.load_stream <<~MANIFEST
---
apiVersion: helm.cattle.io/v1
kind: HelmChartConfig
metadata:
name: rke2-cilium
namespace: kube-system
spec:
valuesContent: |-
kubeProxyReplacement: true
k8sServiceHost: "192.168.150.86"
k8sServicePort: 6443
cni:
chainingMode: "none"
exclusive: false
bgpControlPlane:
enabled: false
MANIFEST
Dir.mktmpdir do |temp_dir|
configure_cilium temp_dir
result = YAML.load_stream File.read "#{temp_dir}/rke2-cilium-config.yaml"
expect(result).to eq output
end
end

it 'should define ip ranges when ONEAPP_K8S_CILIUM_ENABLE_BGP is true and ONEAPP_K8S_CILIUM_RANGES is not empty' do
stub_const 'ONEAPP_K8S_CONTROL_PLANE_EP', '192.168.150.86:6443'
stub_const 'ONEAPP_K8S_CNI_PLUGIN', 'cilium'
stub_const 'ONEAPP_K8S_CILIUM_ENABLE_BGP', true
Expand Down Expand Up @@ -116,11 +146,11 @@
end
end

it 'should disable bgpControlPlane and not define ip ranges when ONEAPP_K8S_CILIUM_ENABLE_BGP is false' do
it 'should define ip ranges when ONEAPP_K8S_CILIUM_ENABLE_BGP is true and ONEAPP_K8S_CILIUM_RANGES is empty' do
stub_const 'ONEAPP_K8S_CONTROL_PLANE_EP', '192.168.150.86:6443'
stub_const 'ONEAPP_K8S_CNI_PLUGIN', 'cilium'
stub_const 'ONEAPP_K8S_CILIUM_ENABLE_BGP', false
stub_const 'ONEAPP_K8S_CILIUM_RANGES', ['192.168.150.128/25', '10.11.12.0/24']
stub_const 'ONEAPP_K8S_CILIUM_ENABLE_BGP', true
stub_const 'ONEAPP_K8S_CILIUM_RANGES', []
output = YAML.load_stream <<~MANIFEST
---
apiVersion: helm.cattle.io/v1
Expand All @@ -137,7 +167,16 @@
chainingMode: "none"
exclusive: false
bgpControlPlane:
enabled: false
enabled: true
---
apiVersion: cilium.io/v2alpha1
kind: CiliumLoadBalancerIPPool
metadata:
name: default
namespace: kube-system
spec:
blocks: {}
allowFirstLastIPs: "No"
MANIFEST
Dir.mktmpdir do |temp_dir|
configure_cilium temp_dir
Expand Down
2 changes: 1 addition & 1 deletion appliances/OneKE/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

ONEAPP_K8S_CNI_PLUGIN = env :ONEAPP_K8S_CNI_PLUGIN, 'cilium'
ONEAPP_K8S_CNI_CONFIG = env :ONEAPP_K8S_CNI_CONFIG, nil
ONEAPP_K8S_CILIUM_ENABLE_BGP = env :ONEAPP_K8S_CILIUM_ENABLE_BGP, 'NO'
ONEAPP_K8S_CILIUM_ENABLE_BGP = env :ONEAPP_K8S_CILIUM_ENABLE_BGP, nil
ONEAPP_K8S_CILIUM_RANGES = ENV.select { |key, _| key.start_with? 'ONEAPP_K8S_CILIUM_RANGE' } .values

ONEAPP_K8S_LONGHORN_CHART_VERSION = env :ONEAPP_K8S_LONGHORN_CHART_VERSION, '1.7.2'
Expand Down

0 comments on commit 4a58748

Please sign in to comment.