-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from appuio/feat/egress-interfaces
Add support for deploying a systemd service which configures egress dummy interfaces
- Loading branch information
Showing
9 changed files
with
225 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
local common = import 'common.libsonnet'; | ||
local com = import 'lib/commodore.libjsonnet'; | ||
local kap = import 'lib/kapitan.libjsonnet'; | ||
local kube = import 'lib/kube.libjsonnet'; | ||
local inv = kap.inventory(); | ||
|
||
local params = inv.parameters.openshift4_nodes; | ||
|
||
local script = (importstr 'scripts/create-egress-interfaces.sh') % { | ||
kubelet_kubeconfig: params.egressInterfaces.nodeKubeconfig, | ||
cm_namespace: params.egressInterfaces.shadowRangeConfigMap.namespace, | ||
cm_name: params.egressInterfaces.shadowRangeConfigMap.name, | ||
}; | ||
|
||
local configs = [ | ||
common.MachineConfig( | ||
'%s-egress-interfaces' % | ||
poolname | ||
) { | ||
metadata+: { | ||
annotations+: { | ||
'inline-contents.machineconfig.syn.tools/create-egress-interfaces.sh': script, | ||
}, | ||
labels+: { | ||
'machineconfiguration.openshift.io/role': poolname, | ||
}, | ||
}, | ||
spec+: { | ||
config: { | ||
storage: { | ||
files: [ | ||
{ | ||
path: '/usr/local/bin/appuio-create-egress-interfaces.sh', | ||
mode: std.parseOctal('0755'), | ||
contents: | ||
'data:text/plain;charset=utf-8;base64,%s' % | ||
std.base64(script), | ||
}, | ||
], | ||
systemd: { | ||
units: [ | ||
{ | ||
name: 'appuio-create-egress-interfaces.service', | ||
enabled: true, | ||
contents: ||| | ||
[Unit] | ||
Description=Assign egress IPs to node interface | ||
After=NetworkManager-wait-online.service | ||
Before=kubelet-dependencies.target | ||
[Service] | ||
ExecStart=/usr/local/bin/appuio-create-egress-interfaces.sh | ||
Type=oneshot | ||
[Install] | ||
WantedBy=kubelet-dependencies.target | ||
|||, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
for poolname in com.renderArray(params.egressInterfaces.machineConfigPools) | ||
]; | ||
|
||
{ | ||
[if std.length(configs) > 0 then '30_egress_interfaces']: configs, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
|
||
set -eo pipefail | ||
|
||
export KUBECONFIG="%(kubelet_kubeconfig)s" | ||
|
||
readonly shadow_data=$(kubectl -n "%(cm_namespace)s" get configmap "%(cm_name)s" -ojsonpath="{.data.${HOSTNAME}}") | ||
|
||
for prefix in $(echo "$shadow_data" | jq -r '.|keys[]'); do | ||
base=$(echo "$shadow_data" | jq -r ".${prefix}.base") | ||
from=$(echo "$shadow_data" | jq -r ".${prefix}.from") | ||
to=$(echo "$shadow_data" | jq -r ".${prefix}.to") | ||
echo "Configuring dummy interfaces for egress range ${prefix}: base=${base}, from=${from}, to=${to}" | ||
for suffix in $(seq "$from" "$to"); do | ||
idx=$(("$suffix" - "$from")) | ||
iface="${prefix}_${idx}" | ||
ip l del "$iface" 2>/dev/null || true | ||
ip l add "$iface" type dummy | ||
ip a add "${base}.${suffix}" dev "$iface" | ||
done | ||
done | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
tests/golden/machineconfig/openshift4-nodes/openshift4-nodes/30_egress_interfaces.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
apiVersion: machineconfiguration.openshift.io/v1 | ||
kind: MachineConfig | ||
metadata: | ||
annotations: | ||
inline-contents.machineconfig.syn.tools/create-egress-interfaces.sh: | | ||
#!/bin/bash | ||
set -eo pipefail | ||
export KUBECONFIG="/var/lib/kubelet/kubeconfig" | ||
readonly shadow_data=$(kubectl -n "cilium" get configmap "eip-shadow-ranges" -ojsonpath="{.data.${HOSTNAME}}") | ||
for prefix in $(echo "$shadow_data" | jq -r '.|keys[]'); do | ||
base=$(echo "$shadow_data" | jq -r ".${prefix}.base") | ||
from=$(echo "$shadow_data" | jq -r ".${prefix}.from") | ||
to=$(echo "$shadow_data" | jq -r ".${prefix}.to") | ||
echo "Configuring dummy interfaces for egress range ${prefix}: base=${base}, from=${from}, to=${to}" | ||
for suffix in $(seq "$from" "$to"); do | ||
idx=$(("$suffix" - "$from")) | ||
iface="${prefix}_${idx}" | ||
ip l del "$iface" 2>/dev/null || true | ||
ip l add "$iface" type dummy | ||
ip a add "${base}.${suffix}" dev "$iface" | ||
done | ||
done | ||
exit 0 | ||
labels: | ||
app.kubernetes.io/component: openshift4-nodes | ||
app.kubernetes.io/managed-by: commodore | ||
app.kubernetes.io/name: openshift4-nodes | ||
machineconfiguration.openshift.io/role: infra | ||
name: 99x-infra-egress-interfaces | ||
name: 99x-infra-egress-interfaces | ||
spec: | ||
config: | ||
storage: | ||
files: | ||
- contents: data:text/plain;charset=utf-8;base64,IyEvYmluL2Jhc2gKCnNldCAtZW8gcGlwZWZhaWwKCmV4cG9ydCBLVUJFQ09ORklHPSIvdmFyL2xpYi9rdWJlbGV0L2t1YmVjb25maWciCgpyZWFkb25seSBzaGFkb3dfZGF0YT0kKGt1YmVjdGwgLW4gImNpbGl1bSIgZ2V0IGNvbmZpZ21hcCAiZWlwLXNoYWRvdy1yYW5nZXMiIC1vanNvbnBhdGg9InsuZGF0YS4ke0hPU1ROQU1FfX0iKQoKZm9yIHByZWZpeCBpbiAkKGVjaG8gIiRzaGFkb3dfZGF0YSIgfCBqcSAtciAnLnxrZXlzW10nKTsgZG8KICBiYXNlPSQoZWNobyAiJHNoYWRvd19kYXRhIiB8IGpxIC1yICIuJHtwcmVmaXh9LmJhc2UiKQogIGZyb209JChlY2hvICIkc2hhZG93X2RhdGEiIHwganEgLXIgIi4ke3ByZWZpeH0uZnJvbSIpCiAgdG89JChlY2hvICIkc2hhZG93X2RhdGEiIHwganEgLXIgIi4ke3ByZWZpeH0udG8iKQogIGVjaG8gIkNvbmZpZ3VyaW5nIGR1bW15IGludGVyZmFjZXMgZm9yIGVncmVzcyByYW5nZSAke3ByZWZpeH06IGJhc2U9JHtiYXNlfSwgZnJvbT0ke2Zyb219LCB0bz0ke3RvfSIKICBmb3Igc3VmZml4IGluICQoc2VxICIkZnJvbSIgIiR0byIpOyBkbwogICAgaWR4PSQoKCIkc3VmZml4IiAtICIkZnJvbSIpKQogICAgaWZhY2U9IiR7cHJlZml4fV8ke2lkeH0iCiAgICBpcCBsIGRlbCAiJGlmYWNlIiAyPi9kZXYvbnVsbCB8fCB0cnVlCiAgICBpcCBsIGFkZCAiJGlmYWNlIiB0eXBlIGR1bW15CiAgICBpcCBhIGFkZCAiJHtiYXNlfS4ke3N1ZmZpeH0iIGRldiAiJGlmYWNlIgogIGRvbmUKZG9uZQoKZXhpdCAwCg== | ||
mode: 493 | ||
path: /usr/local/bin/appuio-create-egress-interfaces.sh | ||
systemd: | ||
units: | ||
- contents: | | ||
[Unit] | ||
Description=Assign egress IPs to node interface | ||
After=NetworkManager-wait-online.service | ||
Before=kubelet-dependencies.target | ||
[Service] | ||
ExecStart=/usr/local/bin/appuio-create-egress-interfaces.sh | ||
Type=oneshot | ||
[Install] | ||
WantedBy=kubelet-dependencies.target | ||
enabled: true | ||
name: appuio-create-egress-interfaces.service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters