From d900efafcc681b4c0506c89a85bb5d88aa0da6b6 Mon Sep 17 00:00:00 2001 From: Achraf BOUAOUDA Date: Tue, 24 Sep 2024 00:25:41 +0200 Subject: [PATCH] feat(test-e2e): support custom network and subnet on remote e2e mode --- hack/make-rules/test-e2e-node.sh | 9 +++++++++ test/e2e_node/remote/gce/gce_runner.go | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/hack/make-rules/test-e2e-node.sh b/hack/make-rules/test-e2e-node.sh index 9cc11eacff8..1951c77f607 100755 --- a/hack/make-rules/test-e2e-node.sh +++ b/hack/make-rules/test-e2e-node.sh @@ -110,6 +110,8 @@ if [ "${remote}" = true ] && [ "${remote_mode}" = gce ] ; then gubernator=${GUBERNATOR:-"false"} instance_type=${INSTANCE_TYPE:-""} node_env="${NODE_ENV:-""}" + network="${NETWORK:-""}" + subnet="${SUBNET:-""}" image_config_file=${IMAGE_CONFIG_FILE:-""} image_config_dir=${IMAGE_CONFIG_DIR:-""} use_dockerized_build=${USE_DOCKERIZED_BUILD:-"false"} @@ -196,6 +198,12 @@ if [ "${remote}" = true ] && [ "${remote_mode}" = gce ] ; then if [[ -n ${instance_type} ]]; then echo "Instance Type: ${instance_type}" fi + if [[ -n ${network} ]]; then + echo "Network: ${network}" + fi + if [[ -n ${subnet} ]]; then + echo "Subnet: ${subnet}" + fi echo "Kubelet Config File: ${kubelet_config_file}" # Invoke the runner @@ -206,6 +214,7 @@ if [ "${remote}" = true ] && [ "${remote_mode}" = gce ] ; then --image-project="${image_project}" --instance-name-prefix="${instance_prefix}" \ --delete-instances="${delete_instances}" --test_args="${test_args}" --instance-metadata="${metadata}" \ --image-config-file="${image_config_file}" --system-spec-name="${system_spec_name}" \ + --network="${network}" --subnet="${subnet}" \ --runtime-config="${runtime_config}" --preemptible-instances="${preemptible_instances}" \ --ssh-user="${ssh_user}" --ssh-key="${ssh_key}" --ssh-options="${ssh_options}" \ --image-config-dir="${image_config_dir}" --node-env="${node_env}" \ diff --git a/test/e2e_node/remote/gce/gce_runner.go b/test/e2e_node/remote/gce/gce_runner.go index 2dcaf08dacb..97476fea978 100644 --- a/test/e2e_node/remote/gce/gce_runner.go +++ b/test/e2e_node/remote/gce/gce_runner.go @@ -75,6 +75,8 @@ var instanceMetadata = flag.String("instance-metadata", "", "key/value metadata var imageProject = flag.String("image-project", "", "gce project the hosts live in (gce)") var instanceType = flag.String("instance-type", "e2-medium", "GCP Machine type to use for test") var preemptibleInstances = flag.Bool("preemptible-instances", false, "If true, gce instances will be configured to be preemptible (gce)") +var network = flag.String("network", "", "Specifies the network that the VM instance are a part of") +var subnet = flag.String("subnet", "", "Specifies the subnet that the VM instance are a part of") func init() { flag.Var(&nodeEnvs, "node-env", "An environment variable passed to instance as metadata, e.g. when '--node-env=PATH=/usr/bin' is specified, there will be an extra instance metadata 'PATH=/usr/bin'.") @@ -512,6 +514,12 @@ func (g *GCERunner) createGCEInstance(imageConfig *internalGCEImage) (string, er createArgs = append(createArgs, "--machine-type="+g.machineType(imageConfig.machine)) createArgs = append(createArgs, "--create-disk="+strings.Join(diskArgs, ",")) createArgs = append(createArgs, "--service-account="+serviceAccount) + if len(*network) > 0 { + createArgs = append(createArgs, "--network="+*network) + } + if len(*subnet) > 0 { + createArgs = append(createArgs, "--subnet="+*subnet) + } if *preemptibleInstances { createArgs = append(createArgs, "--preemptible") }