diff --git a/cmd/e2e-test/main_test.go b/cmd/e2e-test/main_test.go index fe165ea788..3d973691eb 100644 --- a/cmd/e2e-test/main_test.go +++ b/cmd/e2e-test/main_test.go @@ -43,6 +43,7 @@ var ( kubeconfig string project string region string + network string seed int64 destroySandboxes bool handleSIGINT bool @@ -63,6 +64,7 @@ func init() { flag.BoolVar(&flags.inCluster, "inCluster", false, "set to true if running in the cluster") flag.StringVar(&flags.project, "project", "", "GCP project") flag.StringVar(&flags.region, "region", "", "GCP Region (e.g. us-central1)") + flag.StringVar(&flags.network, "network", "", "GCP network name (e.g. default) to use for ilb subnet") flag.Int64Var(&flags.seed, "seed", -1, "random seed") flag.BoolVar(&flags.destroySandboxes, "destroySandboxes", true, "set to false to leave sandboxed resources for debugging") flag.BoolVar(&flags.handleSIGINT, "handleSIGINT", true, "catch SIGINT to perform clean") @@ -88,6 +90,10 @@ func TestMain(m *testing.M) { os.Exit(1) } + if flags.network == "" { + klog.Info("No network provided, will not create ILB Subnet") + } + fmt.Printf("Version: %q, Commit: %q\n", version.Version, version.GitCommit) var err error @@ -113,6 +119,7 @@ func TestMain(m *testing.M) { Framework = e2e.NewFramework(kubeconfig, e2e.Options{ Project: flags.project, Region: flags.region, + Network: flags.network, Seed: flags.seed, DestroySandboxes: flags.destroySandboxes, GceEndpointOverride: flags.gceEndpointOverride, diff --git a/pkg/e2e/fixtures.go b/pkg/e2e/fixtures.go index 98c75e61df..448fd4fd65 100644 --- a/pkg/e2e/fixtures.go +++ b/pkg/e2e/fixtures.go @@ -265,6 +265,12 @@ func DeleteGCPAddress(s *Sandbox, name string) error { // CreateILBSubnet creates the ILB subnet func CreateILBSubnet(s *Sandbox) error { klog.V(3).Info("CreateILBSubnet()") + + // If no network is provided, we don't try to create the subnet + if s.f.Network == "" { + return ErrSubnetExists + } + name := "ilb-subnet-ingress-e2e" // Try up to 10 different subnets since we can't conflict with anything in the test project @@ -285,7 +291,7 @@ func CreateILBSubnet(s *Sandbox) error { // trySubnetCreate is a helper for CreateILBSubnet func trySubnetCreate(s *Sandbox, name, ipCidrRange string) error { - networkID := cloud.ResourceID{ProjectID: s.f.Project, Resource: "networks", Key: meta.GlobalKey("default")} + networkID := cloud.ResourceID{ProjectID: s.f.Project, Resource: "networks", Key: meta.GlobalKey(s.f.Network)} subnet := &computebeta.Subnetwork{ Name: name, diff --git a/pkg/e2e/framework.go b/pkg/e2e/framework.go index 16968c7c88..edcfec4eb6 100644 --- a/pkg/e2e/framework.go +++ b/pkg/e2e/framework.go @@ -43,6 +43,7 @@ import ( type Options struct { Project string Region string + Network string Seed int64 DestroySandboxes bool GceEndpointOverride string @@ -64,6 +65,7 @@ func NewFramework(config *rest.Config, options Options) *Framework { BackendConfigClient: backendConfigClient, Project: options.Project, Region: options.Region, + Network: options.Network, Cloud: theCloud, Rand: rand.New(rand.NewSource(options.Seed)), destroySandboxes: options.DestroySandboxes, @@ -79,6 +81,7 @@ type Framework struct { BackendConfigClient *backendconfigclient.Clientset Project string Region string + Network string Cloud cloud.Cloud Rand *rand.Rand statusManager *StatusManager