Skip to content
This repository was archived by the owner on Aug 26, 2022. It is now read-only.

Commit bd40001

Browse files
mkochanowskiryandgoulding
authored andcommitted
Add network mode settings to run-container.sh
This change adds an optional -n parameter to run-container.sh allowing to set network settings consumed by a `--network` parameter of the `docker run` command responsible for creating the TNF container. The network mode defaults to `bridge`, consistent with the equivalent setting provided by the `docker run` command. The documentation, and the usage prompt have been updated to explain the usage of the -n parameter. Due to the increase in the number of options available, the list of optional arguments in the documentation is now sorted alphabetically. Signed-off-by: Marek Kochanowski <[email protected]>
1 parent ec9bdbd commit bd40001

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ To pull the latest container and run the tests you use the following command. Th
2222

2323
Optional arguments are:
2424

25-
* `-k` gives a path to one or more kubeconfig files to be used by the container to authenticate with the cluster. Paths must be separated by a colon.
2625
* `-i` gives a name to a custom TNF container image. Supports local images, as well as images from external registries.
26+
* `-k` gives a path to one or more kubeconfig files to be used by the container to authenticate with the cluster. Paths must be separated by a colon.
27+
* `-n` gives the network mode of the container. Defaults to `bridge`. See the [docker run --network parameter reference](https://docs.docker.com/engine/reference/run/#network-settings) for more information on how to configure network settings.
2728

2829
If `-k` is not specified, autodiscovery is performed.
2930
The autodiscovery first looks for paths in the `$KUBECONFIG` environment variable on the host system, and if the variable is not set or is empty, the default configuration stored in `$HOME/.kube/config` is checked.

run-container.sh

+15-3
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,24 @@ TNF_OFFICIAL_IMAGE="${TNF_OFFICIAL_ORG}${TNF_IMAGE_NAME}:${TNF_IMAGE_TAG}"
2727

2828
CONTAINER_TNF_DIR=/usr/tnf
2929
CONTAINER_TNF_KUBECONFIG_FILE_BASE_PATH="$CONTAINER_TNF_DIR/kubeconfig/config"
30+
CONTAINER_DEFAULT_NETWORK_MODE=bridge
3031

3132
usage() {
3233
read -d '' usage_prompt <<- EOF
33-
Usage: $0 -t TNFCONFIG -o OUTPUT_LOC [ -k KUBECONFIG ] [-i IMAGE ] SUITE [ ... SUITE ]
34+
Usage: $0 -t TNFCONFIG -o OUTPUT_LOC [-i IMAGE] [-k KUBECONFIG] [-n NETWORK_MODE] SUITE [... SUITE]
3435
3536
Configure and run the containerised TNF test offering.
3637
37-
Options
38+
Options (required)
3839
-t: set the directory containing TNF config files set up for the test.
3940
-o: set the output location for the test results.
41+
42+
Options (optional)
43+
-i: set the TNF container image. Supports local images, as well as images from external registries.
4044
-k: set path to one or more local kubeconfigs, separated by a colon.
4145
The -k option takes precedence, overwriting the results of local kubeconfig autodiscovery.
4246
See the 'Kubeconfig lookup order' section below for more details.
43-
-i: set the TNF container image. Supports local images, as well as images from external registries.
47+
-n: set the network mode of the container.
4448
4549
Kubeconfig lookup order
4650
1. If -k is specified, use the paths provided with the -k option.
@@ -185,6 +189,12 @@ while [[ $1 == -* ]]; do
185189
echo "-i requires an argument" 1>&2
186190
exit 1
187191
fi ;;
192+
-n) if (($# > 1)); then
193+
CONTAINER_NETWORK_MODE=$2; shift 2
194+
else
195+
echo "-n requires an argument" 1>&2
196+
exit 1
197+
fi ;;
188198
--) shift; break;;
189199
-*) echo "invalid option: $1" 1>&2; usage_error;;
190200
esac
@@ -210,6 +220,7 @@ for local_path_index in "${!local_kubeconfig_paths[@]}"; do
210220
done
211221

212222
TNF_IMAGE="${TNF_IMAGE:-$TNF_OFFICIAL_IMAGE}"
223+
CONTAINER_NETWORK_MODE="${CONTAINER_NETWORK_MODE:-$CONTAINER_DEFAULT_NETWORK_MODE}"
213224

214225
display_config_summary
215226

@@ -221,6 +232,7 @@ container_tnf_kubeconfig_volumes_cmd_args=$(printf -- "-v %s " "${container_tnf_
221232

222233
set -x
223234
docker run --rm \
235+
--network $CONTAINER_NETWORK_MODE \
224236
${container_tnf_kubeconfig_volumes_cmd_args[@]} \
225237
-v $LOCAL_TNF_CONFIG:$CONTAINER_TNF_DIR/config \
226238
-v $OUTPUT_LOC:$CONTAINER_TNF_DIR/claim \

0 commit comments

Comments
 (0)