Skip to content

Add flags to specify zone/machine-type/OS image #962

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

Merged
merged 1 commit into from
Apr 22, 2022
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
8 changes: 6 additions & 2 deletions test/e2e/tests/setup_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"flag"
"fmt"
"math/rand"
"strings"
"testing"
"time"

Expand All @@ -35,6 +36,9 @@ import (
var (
project = flag.String("project", "", "Project to run tests in")
serviceAccount = flag.String("service-account", "", "Service account to bring up instance with")
zones = flag.String("zones", "us-central1-c,us-central1-b", "Zones to run tests in. If there are multiple zones, separate each by comma")
machineType = flag.String("machine-type", "n1-standard-1", "Type of machine to provision instance on")
imageURL = flag.String("image-url", "projects/debian-cloud/global/images/family/debian-11", "OS image url to get image from")
Copy link
Contributor

Choose a reason for hiding this comment

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

since we have moved to distroless, do we need to change to that here too? @pwschuurman

runInProw = flag.Bool("run-in-prow", false, "If true, use a Boskos loaned project and special CI service accounts and ssh keys")
deleteInstances = flag.Bool("delete-instances", false, "Delete the instances after tests run")

Expand All @@ -60,7 +64,7 @@ var _ = BeforeSuite(func() {
tcc := make(chan *remote.TestContext)
defer close(tcc)

zones := []string{"us-central1-c", "us-central1-b"}
zones := strings.Split(*zones, ",")

rand.Seed(time.Now().UnixNano())

Expand Down Expand Up @@ -89,7 +93,7 @@ var _ = BeforeSuite(func() {
nodeID := fmt.Sprintf("gce-pd-csi-e2e-%s", curZone)
klog.Infof("Setting up node %s\n", nodeID)

i, err := remote.SetupInstance(*project, curZone, nodeID, *serviceAccount, computeService)
i, err := remote.SetupInstance(*project, curZone, nodeID, *machineType, *serviceAccount, *imageURL, computeService)
if err != nil {
klog.Fatalf("Failed to setup instance %v: %v", nodeID, err)
}
Expand Down
29 changes: 11 additions & 18 deletions test/remote/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ import (
)

const (
defaultMachine = "n1-standard-1"
defaultFirewallRule = "default-allow-ssh"

// timestampFormat is the timestamp format used in the e2e directory name.
timestampFormat = "20060102T150405"
)

type InstanceInfo struct {
project string
zone string
name string
project string
zone string
name string
machineType string

// External IP is filled in after instance creation
externalIP string
Expand All @@ -68,18 +68,19 @@ func (i *InstanceInfo) GetNodeID() string {
return common.CreateNodeID(i.project, i.zone, i.name)
}

func CreateInstanceInfo(project, instanceZone, name string, cs *compute.Service) (*InstanceInfo, error) {
func CreateInstanceInfo(project, instanceZone, name, machineType string, cs *compute.Service) (*InstanceInfo, error) {
return &InstanceInfo{
project: project,
zone: instanceZone,
name: name,
project: project,
zone: instanceZone,
name: name,
machineType: machineType,

computeService: cs,
}, nil
}

// Provision a gce instance using image
func (i *InstanceInfo) CreateOrGetInstance(serviceAccount string) error {
func (i *InstanceInfo) CreateOrGetInstance(imageURL, serviceAccount string) error {
var err error
var instance *compute.Instance
klog.V(4).Infof("Creating instance: %v", i.name)
Expand All @@ -91,10 +92,9 @@ func (i *InstanceInfo) CreateOrGetInstance(serviceAccount string) error {
return fmt.Errorf("Failed to create firewall rule: %v", err)
}

imageURL := "projects/debian-cloud/global/images/family/debian-11"
inst := &compute.Instance{
Name: i.name,
MachineType: machineType(i.zone, ""),
MachineType: fmt.Sprintf("zones/%s/machineTypes/%s", i.zone, i.machineType),
NetworkInterfaces: []*compute.NetworkInterface{
{
AccessConfigs: []*compute.AccessConfig{
Expand Down Expand Up @@ -215,13 +215,6 @@ func getTimestamp() string {
return fmt.Sprintf(time.Now().Format(timestampFormat))
}

func machineType(zone, machine string) string {
if machine == "" {
machine = defaultMachine
}
return fmt.Sprintf("zones/%s/machineTypes/%s", zone, machine)
}

// Create default SSH filewall rule if it does not exist
func (i *InstanceInfo) createDefaultFirewallRule() error {
var err error
Expand Down
6 changes: 3 additions & 3 deletions test/remote/setup-teardown.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ type processes struct {
}

// SetupInstance sets up the specified GCE Instance for E2E testing and returns a handle to the instance object for future use.
func SetupInstance(instanceProject, instanceZone, instanceName, instanceServiceAccount string, cs *compute.Service) (*InstanceInfo, error) {
func SetupInstance(instanceProject, instanceZone, instanceName, instanceMachineType, instanceServiceAccount, instanceImageURL string, cs *compute.Service) (*InstanceInfo, error) {
// Create the instance in the requisite zone
instance, err := CreateInstanceInfo(instanceProject, instanceZone, instanceName, cs)
instance, err := CreateInstanceInfo(instanceProject, instanceZone, instanceName, instanceMachineType, cs)
if err != nil {
return nil, err
}

err = instance.CreateOrGetInstance(instanceServiceAccount)
err = instance.CreateOrGetInstance(instanceImageURL, instanceServiceAccount)
if err != nil {
return nil, err
}
Expand Down