-
Notifications
You must be signed in to change notification settings - Fork 160
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
Changes from 5 commits
83b5c98
81b9946
59275d3
acaa887
160f4b6
3744d78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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 | ||
|
@@ -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{ | ||
|
@@ -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) { | ||
dannawang0221 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 { | ||
|
@@ -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() | ||
|
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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