Skip to content

Commit

Permalink
salt: Make Pod network mtu configurable
Browse files Browse the repository at this point in the history
Add a `mtu` key in bootstrap configuration to configure the value for
MTU on Pod network, this value is used by calico to create the
interface for Pod network.
NOTE: We set the calico MTU to the workload MTU - 20 so that if IPinIP
is enabled the MTU is still valid

Fixes: #1095
  • Loading branch information
TeddyAndrieux committed Jul 31, 2020
1 parent 1878161 commit 3be7abc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions salt/_pillar/metalk8s.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

DEFAULT_POD_NETWORK = '10.233.0.0/16'
DEFAULT_SERVICE_NETWORK = '10.96.0.0/12'
DEFAULT_MTU = 1460


def _load_config(path):
Expand Down Expand Up @@ -101,6 +102,9 @@ def _load_networks(config_data):
if errors:
return __utils__['pillar_utils.errors_to_dict'](errors)

if 'mtu' not in networks_data['workloadPlane']:
networks_data['workloadPlane']['mtu'] = DEFAULT_MTU

return {
'control_plane': networks_data['controlPlane'],
'workload_plane': networks_data['workloadPlane'],
Expand Down
11 changes: 10 additions & 1 deletion salt/metalk8s/kubernetes/cni/calico/configured.sls
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
{%- from "metalk8s/map.jinja" import kube_api with context %}
{%- from "metalk8s/map.jinja" import kubernetes with context %}
{%- from "metalk8s/map.jinja" import networks with context %}
{%- set kubernetes_service_ip = salt.metalk8s_network.get_kubernetes_service_ip() %}
{#- Check that workload MTU configured is smaller than the local workload interface one #}
{%- set workload_local_mtu = salt.metalk8s_network.get_mtu_from_ip(grains.metalk8s.workload_plane_ip) %}
{%- if networks.workload_plane.mtu > workload_local_mtu %}
{{ raise('Trying to configure CNI with ' ~ networks.workload_plane.mtu
~ ' MTU but local workload interface MTU is smaller: ' ~ workload_local_mtu) }}
{%- endif %}
include:
- metalk8s.internal.m2crypto
Expand Down Expand Up @@ -36,7 +44,8 @@ Create CNI calico configuration file:
log_level: "info"
datastore_type: "kubernetes"
nodename: {{ grains.id }}
mtu: 1440
# NOTE: MTU for calico = workload MTU - 20 (for IPinIP header)
mtu: {{ networks.workload_plane.mtu - 20 }}
ipam:
type: "calico-ipam"
policy:
Expand Down
3 changes: 2 additions & 1 deletion salt/metalk8s/kubernetes/cni/calico/deployed.sls
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ data:
calico_backend: "bird"
# Configure the MTU to use
veth_mtu: "1440"
# NOTE: MTU for calico = workload MTU - 20 (for IPinIP header)
veth_mtu: "{{ networks.workload_plane.mtu - 20 }}"
# The CNI network configuration to install on each node. The special
# values in this config will be automatically populated.
Expand Down

0 comments on commit 3be7abc

Please sign in to comment.