[entrypoint] Add options to specify logfile & loglevel in entrypoint (#280)

This commit is contained in:
Doug Smith
2019-03-07 11:01:03 -05:00
committed by dougbtv
parent 1e4fe4f837
commit 4aecbd2133

View File

@@ -10,6 +10,8 @@ MULTUS_CONF_FILE="/usr/src/multus-cni/images/70-multus.conf"
MULTUS_BIN_FILE="/usr/src/multus-cni/bin/multus" MULTUS_BIN_FILE="/usr/src/multus-cni/bin/multus"
MULTUS_KUBECONFIG_FILE_HOST="/etc/cni/net.d/multus.d/multus.kubeconfig" MULTUS_KUBECONFIG_FILE_HOST="/etc/cni/net.d/multus.d/multus.kubeconfig"
MULTUS_NAMESPACE_ISOLATION=false MULTUS_NAMESPACE_ISOLATION=false
MULTUS_LOG_LEVEL=""
MULTUS_LOG_FILE=""
# Give help text for parameters. # Give help text for parameters.
function usage() function usage()
@@ -17,7 +19,7 @@ function usage()
echo -e "This is an entrypoint script for Multus CNI to overlay its binary and " echo -e "This is an entrypoint script for Multus CNI to overlay its binary and "
echo -e "configuration into locations in a filesystem. The configuration & binary file " echo -e "configuration into locations in a filesystem. The configuration & binary file "
echo -e "will be copied to the corresponding configuration directory. When " echo -e "will be copied to the corresponding configuration directory. When "
echo -e "`--multus-conf-file=auto` is used, 00-multus.conf will be automatically " echo -e "'--multus-conf-file=auto' is used, 00-multus.conf will be automatically "
echo -e "generated from the CNI configuration file of the master plugin (the first file " echo -e "generated from the CNI configuration file of the master plugin (the first file "
echo -e "in lexicographical order in cni-conf-dir)." echo -e "in lexicographical order in cni-conf-dir)."
echo -e "" echo -e ""
@@ -29,6 +31,8 @@ function usage()
echo -e "\t--multus-bin-file=$MULTUS_BIN_FILE" echo -e "\t--multus-bin-file=$MULTUS_BIN_FILE"
echo -e "\t--multus-kubeconfig-file-host=$MULTUS_KUBECONFIG_FILE_HOST" echo -e "\t--multus-kubeconfig-file-host=$MULTUS_KUBECONFIG_FILE_HOST"
echo -e "\t--namespace-isolation=$MULTUS_NAMESPACE_ISOLATION" echo -e "\t--namespace-isolation=$MULTUS_NAMESPACE_ISOLATION"
echo -e "\t--multus-log-level=$MULTUS_LOG_LEVEL (empty by default, used only with --multus-conf-file=auto)"
echo -e "\t--multus-log-file=$MULTUS_LOG_FILE (empty by default, used only with --multus-conf-file=auto)"
} }
# Parse parameters given as arguments to this script. # Parse parameters given as arguments to this script.
@@ -58,10 +62,14 @@ while [ "$1" != "" ]; do
--namespace-isolation) --namespace-isolation)
MULTUS_NAMESPACE_ISOLATION=$VALUE MULTUS_NAMESPACE_ISOLATION=$VALUE
;; ;;
--multus-log-level)
MULTUS_LOG_LEVEL=$VALUE
;;
--multus-log-file)
MULTUS_LOG_FILE=$VALUE
;;
*) *)
echo "ERROR: unknown parameter \"$PARAM\"" echo "WARNING: unknown parameter \"$PARAM\""
usage
exit 1
;; ;;
esac esac
shift shift
@@ -71,7 +79,7 @@ done
# Create array of known locations # Create array of known locations
declare -a arr=($CNI_CONF_DIR $CNI_BIN_DIR $MULTUS_BIN_FILE) declare -a arr=($CNI_CONF_DIR $CNI_BIN_DIR $MULTUS_BIN_FILE)
if [ "$MULTUS_CONF_FILE" != "auto" ]; then if [ "$MULTUS_CONF_FILE" != "auto" ]; then
arr+=($MULTUS_BIN_FILE) arr+=($MULTUS_CONF_FILE)
fi fi
@@ -157,30 +165,73 @@ fi
if [ "$MULTUS_CONF_FILE" == "auto" ]; then if [ "$MULTUS_CONF_FILE" == "auto" ]; then
echo "Generating Multus configuration file ..." echo "Generating Multus configuration file ..."
MASTER_PLUGIN="$(ls $CNI_CONF_DIR | grep -E '\.conf(list)?$' | grep -Ev '00-multus\.conf' | head -1)" found_master=false
if [ "$MASTER_PLUGIN" == "" ]; then tries=0
echo "Error: Multus could not be configured: no master plugin was found." while [ $found_master == false ]; do
exit 1; MASTER_PLUGIN="$(ls $CNI_CONF_DIR | grep -E '\.conf(list)?$' | grep -Ev '00-multus\.conf' | head -1)"
else if [ "$MASTER_PLUGIN" == "" ]; then
ISOLATION_STRING="" if [ $tries -lt 600 ]; then
if [ "$MULTUS_NAMESPACE_ISOLATION" == true ]; then if ! (($tries % 5)); then
ISOLATION_STRING="\"namespaceIsolation\": true," echo "Attemping to find master plugin configuration, attempt $tries"
fi
let "tries+=1"
sleep 1;
else
echo "Error: Multus could not be configured: no master plugin was found."
exit 1;
fi
else
found_master=true
ISOLATION_STRING=""
if [ "$MULTUS_NAMESPACE_ISOLATION" == true ]; then
ISOLATION_STRING="\"namespaceIsolation\": true,"
fi
LOG_LEVEL_STRING=""
if [ ! -z "${MULTUS_LOG_LEVEL// }" ]; then
case "$MULTUS_LOG_LEVEL" in
debug)
;;
error)
;;
panic)
;;
verbose)
;;
*)
echo "ERROR: Log levels should be one of: debug/verbose/error/panic, did not understand $MULTUS_LOG_LEVEL"
usage
exit 1
esac
LOG_LEVEL_STRING="\"logLevel\": \"$MULTUS_LOG_LEVEL\","
fi
LOG_FILE_STRING=""
if [ ! -z "${MULTUS_LOG_FILE// }" ]; then
LOG_FILE_STRING="\"logFile\": \"$MULTUS_LOG_FILE\","
fi
MASTER_PLUGIN_JSON="$(cat $CNI_CONF_DIR/$MASTER_PLUGIN)"
CONF=$(cat <<-EOF
{
"name": "multus-cni-network",
"type": "multus",
$ISOLATION_STRING
$LOG_LEVEL_STRING
$LOG_FILE_STRING
"kubeconfig": "$MULTUS_KUBECONFIG_FILE_HOST",
"delegates": [
$MASTER_PLUGIN_JSON
]
}
EOF
)
echo $CONF > $CNI_CONF_DIR/00-multus.conf
echo "Config file created @ $CNI_CONF_DIR/00-multus.conf"
fi fi
MASTER_PLUGIN_JSON="$(cat $CNI_CONF_DIR/$MASTER_PLUGIN)" done
CONF=$(cat <<-EOF
{
"name": "multus-cni-network",
"type": "multus",
$ISOLATION_STRING
"kubeconfig": "$MULTUS_KUBECONFIG_FILE_HOST",
"delegates": [
$MASTER_PLUGIN_JSON
]
}
EOF
)
echo $CONF > $CNI_CONF_DIR/00-multus.conf
fi
fi fi
# ---------------------- end Generate "00-multus.conf". # ---------------------- end Generate "00-multus.conf".