Skip to content

Add functionality to make architecture specific builds #963

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
Show file tree
Hide file tree
Changes from 5 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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,12 @@ gce-pd-driver: require-GCE_PD_CSI_STAGING_VERSION
go build -mod=vendor -gcflags=$(GCFLAGS) -ldflags "-X main.version=$(STAGINGVERSION)" -o bin/${DRIVERBINARY} ./cmd/gce-pd-csi-driver/

gce-pd-driver-windows: require-GCE_PD_CSI_STAGING_VERSION
ifeq (GOARCH, amd64)
Copy link
Member

Choose a reason for hiding this comment

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

I think this broke builds of the windows binary in https://prow.k8s.io/job-history/gs/kubernetes-jenkins/logs/ci-gce-pd-csi-driver-latest-k8s-master-windows-2019 (see the recent failures in about 7m), should it be $(GOARCH) instead?

W0504 14:19:19.035] #0 0.160 Makefile:48: gcp-pd-driver-windows only supports amd64.

Copy link
Member

Choose a reason for hiding this comment

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

I'm attempting to fix this in #973

mkdir -p bin
GOOS=windows go build -mod=vendor -ldflags -X=main.version=$(STAGINGVERSION) -o bin/${DRIVERWINDOWSBINARY} ./cmd/gce-pd-csi-driver/
else
$(warning gcp-pd-driver-windows only supports amd64.)
endif

build-container: require-GCE_PD_CSI_STAGING_IMAGE require-GCE_PD_CSI_STAGING_VERSION init-buildx
$(DOCKER) buildx build --platform=linux --progress=plain \
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/tests/setup_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import (
var (
project = flag.String("project", "", "Project to run tests in")
serviceAccount = flag.String("service-account", "", "Service account to bring up instance with")
architecture = flag.String("arch", "amd64", "Architecture pd csi driver build on")
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")
Expand Down Expand Up @@ -93,7 +94,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, *machineType, *serviceAccount, *imageURL, computeService)
i, err := remote.SetupInstance(*project, *architecture, curZone, nodeID, *machineType, *serviceAccount, *imageURL, computeService)
if err != nil {
klog.Fatalf("Failed to setup instance %v: %v", nodeID, err)
}
Expand Down
8 changes: 4 additions & 4 deletions test/remote/archiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"k8s.io/klog"
)

func CreateDriverArchive(archiveName, pkgPath, binPath string) (string, error) {
func CreateDriverArchive(archiveName, architecture, pkgPath, binPath string) (string, error) {
klog.V(2).Infof("Building archive...")
tarDir, err := ioutil.TempDir("", "driver-temp-archive")
if err != nil {
Expand All @@ -35,7 +35,7 @@ func CreateDriverArchive(archiveName, pkgPath, binPath string) (string, error) {
defer os.RemoveAll(tarDir)

// Call the suite function to setup the test package.
err = setupBinaries(tarDir, pkgPath, binPath)
err = setupBinaries(architecture, tarDir, pkgPath, binPath)
if err != nil {
return "", fmt.Errorf("failed to setup test package %q: %v", tarDir, err)
}
Expand All @@ -53,9 +53,9 @@ func CreateDriverArchive(archiveName, pkgPath, binPath string) (string, error) {
return filepath.Join(dir, archiveName), nil
}

func setupBinaries(tarDir, pkgPath, binPath string) error {
func setupBinaries(architecture, tarDir, pkgPath, binPath string) error {
klog.V(4).Infof("Making binaries and copying to temp dir...")
out, err := exec.Command("make", "-C", pkgPath).CombinedOutput()
out, err := exec.Command("make", "-C", pkgPath, "GOARCH="+architecture).CombinedOutput()
if err != nil {
return fmt.Errorf("Failed to make at %s: %v: %v", pkgPath, string(out), err)
}
Expand Down
57 changes: 41 additions & 16 deletions test/remote/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,11 @@ const (
)

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

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

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

computeService: cs,
}, nil
Expand All @@ -92,7 +94,7 @@ func (i *InstanceInfo) CreateOrGetInstance(imageURL, serviceAccount string) erro
return fmt.Errorf("Failed to create firewall rule: %v", err)
}

inst := &compute.Instance{
newInst := &compute.Instance{
Name: i.name,
MachineType: fmt.Sprintf("zones/%s/machineTypes/%s", i.zone, i.machineType),
NetworkInterfaces: []*compute.NetworkInterface{
Expand Down Expand Up @@ -121,20 +123,43 @@ func (i *InstanceInfo) CreateOrGetInstance(imageURL, serviceAccount string) erro
Email: serviceAccount,
Scopes: []string{"https://www.googleapis.com/auth/cloud-platform"},
}
inst.ServiceAccounts = []*compute.ServiceAccount{saObj}
newInst.ServiceAccounts = []*compute.ServiceAccount{saObj}

if pubkey, ok := os.LookupEnv("JENKINS_GCE_SSH_PUBLIC_KEY_FILE"); ok {
klog.V(4).Infof("JENKINS_GCE_SSH_PUBLIC_KEY_FILE set to %v, adding public key to Instance", pubkey)
meta, err := generateMetadataWithPublicKey(pubkey)
if err != nil {
return err
}
inst.Metadata = meta
newInst.Metadata = meta
}

if _, err := i.computeService.Instances.Get(i.project, i.zone, inst.Name).Do(); err != nil {
op, err := i.computeService.Instances.Insert(i.project, i.zone, inst).Do()
klog.V(4).Infof("Inserted instance %v in project: %v, zone: %v", inst.Name, i.project, i.zone)
// If instance exists but machine-type doesn't match, delete instance
curInst, _ := i.computeService.Instances.Get(i.project, i.zone, newInst.Name).Do()
if curInst != nil {
if !strings.Contains(curInst.MachineType, newInst.MachineType) {
klog.V(4).Infof("Instance machine type doesn't match the required one. Delete instance.")
if _, err := i.computeService.Instances.Delete(i.project, i.zone, i.name).Do(); err != nil {
return err
}

then := time.Now()
err := wait.Poll(15*time.Second, 5*time.Minute, func() (bool, error) {
klog.V(2).Infof("Waiting for instance to be deleted. %v elapsed", time.Since(then))
if instance, _ = i.computeService.Instances.Get(i.project, i.zone, i.name).Do(); instance != nil {
return false, nil
}
return true, nil
})
if err != nil {
return err
}
}
}

if _, err := i.computeService.Instances.Get(i.project, i.zone, newInst.Name).Do(); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you just check of curInst (or instance) is nil here? I don't think you need an extra Get call. This will also make your API response handling more consistent (right now you're using the first and second parameter in the return call to indicate the same semantics)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

op, err := i.computeService.Instances.Insert(i.project, i.zone, newInst).Do()
klog.V(4).Infof("Inserted instance %v in project: %v, zone: %v", newInst.Name, i.project, i.zone)
if err != nil {
ret := fmt.Sprintf("could not create instance %s: API error: %v", i.name, err)
if op != nil {
Expand All @@ -145,7 +170,7 @@ func (i *InstanceInfo) CreateOrGetInstance(imageURL, serviceAccount string) erro
return fmt.Errorf("could not create instance %s: %+v", i.name, op.Error)
}
} else {
klog.V(4).Infof("Compute service GOT instance %v, skipping instance creation", inst.Name)
klog.V(4).Infof("Compute service GOT instance %v, skipping instance creation", newInst.Name)
}

then := time.Now()
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,9 +54,9 @@ 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, instanceMachineType, instanceServiceAccount, instanceImageURL string, cs *compute.Service) (*InstanceInfo, error) {
func SetupInstance(instanceProject, instanceArchitecture, instanceZone, instanceName, instanceMachineType, instanceServiceAccount, instanceImageURL string, cs *compute.Service) (*InstanceInfo, error) {
// Create the instance in the requisite zone
instance, err := CreateInstanceInfo(instanceProject, instanceZone, instanceName, instanceMachineType, cs)
instance, err := CreateInstanceInfo(instanceProject, instanceArchitecture, instanceZone, instanceName, instanceMachineType, cs)
if err != nil {
return nil, err
}
Expand All @@ -73,7 +73,7 @@ func SetupInstance(instanceProject, instanceZone, instanceName, instanceMachineT
// that the driver is on and the CSI Client object to make CSI calls to the remote driver.
func SetupNewDriverAndClient(instance *InstanceInfo, config *ClientConfig) (*TestContext, error) {
archiveName := fmt.Sprintf("e2e_driver_binaries_%s.tar.gz", uuid.NewUUID())
archivePath, err := CreateDriverArchive(archiveName, config.PkgPath, config.BinPath)
archivePath, err := CreateDriverArchive(archiveName, instance.architecture, config.PkgPath, config.BinPath)
if err != nil {
return nil, err
}
Expand Down
1 change: 0 additions & 1 deletion test/run-e2e-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ set -o errexit
readonly PKGDIR=sigs.k8s.io/gcp-compute-persistent-disk-csi-driver

ginkgo --v "test/e2e/tests" -- --project "${PROJECT}" --service-account "${IAM_NAME}" --v=4 --logtostderr