Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -network flag to e2e test framework for ILB subnet creation #893

Merged
merged 1 commit into from
Oct 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make sure to cleanup the created subnet after the test (e.g. TestILB)? Or eventually we will be failing on deleting the network because this subnet is still there.

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