Skip to content

Commit

Permalink
Add -network flag to e2e test framework for ILB subnet creation
Browse files Browse the repository at this point in the history
We need this to create the ILB subnet in the right network
  • Loading branch information
spencerhance committed Oct 16, 2019
1 parent 0d42a4c commit cb40644
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions cmd/e2e-test/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var (
kubeconfig string
project string
region string
network string
seed int64
destroySandboxes bool
handleSIGINT bool
Expand All @@ -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")
Expand All @@ -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
Expand All @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion pkg/e2e/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions pkg/e2e/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
type Options struct {
Project string
Region string
Network string
Seed int64
DestroySandboxes bool
GceEndpointOverride string
Expand All @@ -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,
Expand All @@ -79,6 +81,7 @@ type Framework struct {
BackendConfigClient *backendconfigclient.Clientset
Project string
Region string
Network string
Cloud cloud.Cloud
Rand *rand.Rand
statusManager *StatusManager
Expand Down

0 comments on commit cb40644

Please sign in to comment.