Skip to content

Commit

Permalink
Pull underlying capabilities up to 00-multus.conf
Browse files Browse the repository at this point in the history
Using Python, we analyze the content of the master plugin configuration,
and we integrate any capabilities from the chained plugins declaration.
This way, we can for example have the  portMapping capability ( declared
for the `portmap` chained plugin) that will be included in the top-level
CNI configuration file, `00-multus.conf`, and the container runtime will
correctly send `runtimeConfig` attributes based on the capabilities.
The script is compatbile with Python 2 and Python 3, it could be a bit
shorter if I used only Python 3 syntax.

Fixes #544

Signed-off-by: <clement.nussbaumer@swisscom.com>
  • Loading branch information
clementnuss committed Aug 5, 2020
1 parent e15f978 commit 9d5c91d
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions images/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,25 @@ if [ "$MULTUS_CONF_FILE" == "auto" ]; then
MASTER_PLUGIN_NET_NAME="multus-cni-network"
fi

capabilities_python_filter_tmpfile=$(mktemp)
cat << EOF > $capabilities_python_filter_tmpfile
import json,sys
conf = json.load(sys.stdin)
capabilities = {}
for capa in [p['capabilities'] for p in conf['plugins'] if 'capabilities' in p]:
capabilities.update(capa)
enabled_capa = {capa:enabled for (capa,enabled) in capabilities.items() if enabled}
if len(enabled_capa) > 0:
print("""\"capabilities\": """ + json.dumps(enabled_capa) + ",")
else:
print("")
EOF

NESTED_CAPABILITIES_STRING="$(cat $MULTUS_AUTOCONF_DIR/$MASTER_PLUGIN | \
python $capabilities_python_filter_tmpfile)"
rm $capabilities_python_filter_tmpfile
log "Nested capabilities string: $NESTED_CAPABILITIES_STRING"

MASTER_PLUGIN_LOCATION=$MULTUS_AUTOCONF_DIR/$MASTER_PLUGIN
MASTER_PLUGIN_JSON="$(cat $MASTER_PLUGIN_LOCATION)"
log "Using $MASTER_PLUGIN_LOCATION as a source to generate the Multus configuration"
Expand All @@ -311,6 +330,7 @@ if [ "$MULTUS_CONF_FILE" == "auto" ]; then
"name": "$MASTER_PLUGIN_NET_NAME",
"type": "multus",
$ISOLATION_STRING
$NESTED_CAPABILITIES_STRING
$LOG_LEVEL_STRING
$LOG_FILE_STRING
$ADDITIONAL_BIN_DIR_STRING
Expand Down

0 comments on commit 9d5c91d

Please sign in to comment.