mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-21 10:09:07 +00:00
moby: Add system disk and disk size parameter to GCP
This makes gcp behave in a similar way to the qemu backend. The minimum size on GCP 1GB, whereas qemu uses 256MB. Without this, the LTP tests fail on GCP. Signed-off-by: Dave Tucker <dt@docker.com>
This commit is contained in:
parent
52f62bb30c
commit
d5264ac9e7
@ -178,7 +178,7 @@ func (g GCPClient) DeleteImage(name string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateInstance creates and starts an instance on GCP
|
// CreateInstance creates and starts an instance on GCP
|
||||||
func (g GCPClient) CreateInstance(name, image, zone, machineType string, replace bool) error {
|
func (g GCPClient) CreateInstance(name, image, zone, machineType string, diskSize int, replace bool) error {
|
||||||
if replace {
|
if replace {
|
||||||
if err := g.DeleteInstance(name, zone, true); err != nil {
|
if err := g.DeleteInstance(name, zone, true); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -196,6 +196,15 @@ func (g GCPClient) CreateInstance(name, image, zone, machineType string, replace
|
|||||||
sshKey := new(string)
|
sshKey := new(string)
|
||||||
*sshKey = fmt.Sprintf("moby:%s moby", string(ssh.MarshalAuthorizedKey(k)))
|
*sshKey = fmt.Sprintf("moby:%s moby", string(ssh.MarshalAuthorizedKey(k)))
|
||||||
|
|
||||||
|
diskName := name + "-systemdisk"
|
||||||
|
diskOp, err := g.compute.Disks.Insert(g.projectName, zone, &compute.Disk{Name: diskName, SizeGb: int64(diskSize)}).Do()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := g.pollZoneOperationStatus(diskOp.Name, zone); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
instanceObj := &compute.Instance{
|
instanceObj := &compute.Instance{
|
||||||
MachineType: fmt.Sprintf("zones/%s/machineTypes/%s", zone, machineType),
|
MachineType: fmt.Sprintf("zones/%s/machineTypes/%s", zone, machineType),
|
||||||
Name: name,
|
Name: name,
|
||||||
@ -207,6 +216,11 @@ func (g GCPClient) CreateInstance(name, image, zone, machineType string, replace
|
|||||||
SourceImage: fmt.Sprintf("global/images/%s", image),
|
SourceImage: fmt.Sprintf("global/images/%s", image),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
AutoDelete: true,
|
||||||
|
Boot: false,
|
||||||
|
Source: fmt.Sprintf("zones/%s/disks/%s", zone, diskName),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
NetworkInterfaces: []*compute.NetworkInterface{
|
NetworkInterfaces: []*compute.NetworkInterface{
|
||||||
{
|
{
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
defaultZone = "europe-west1-d"
|
defaultZone = "europe-west1-d"
|
||||||
defaultMachine = "g1-small"
|
defaultMachine = "g1-small"
|
||||||
|
defaultDiskSize = 1
|
||||||
zoneVar = "MOBY_GCP_ZONE"
|
zoneVar = "MOBY_GCP_ZONE"
|
||||||
machineVar = "MOBY_GCP_MACHINE"
|
machineVar = "MOBY_GCP_MACHINE"
|
||||||
keysVar = "MOBY_GCP_KEYS"
|
keysVar = "MOBY_GCP_KEYS"
|
||||||
@ -20,6 +21,7 @@ const (
|
|||||||
familyVar = "MOBY_GCP_FAMILY"
|
familyVar = "MOBY_GCP_FAMILY"
|
||||||
publicVar = "MOBY_GCP_PUBLIC"
|
publicVar = "MOBY_GCP_PUBLIC"
|
||||||
nameVar = "MOBY_GCP_IMAGE_NAME"
|
nameVar = "MOBY_GCP_IMAGE_NAME"
|
||||||
|
diskSizeVar = "MOBY_GCP_DISK_SIZE"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Process the run arguments and execute run
|
// Process the run arguments and execute run
|
||||||
@ -41,6 +43,8 @@ func runGcp(args []string) {
|
|||||||
publicFlag := gcpCmd.Bool("public", false, "Select if file on GS should be public. *Optional* when 'prefix' is a filename")
|
publicFlag := gcpCmd.Bool("public", false, "Select if file on GS should be public. *Optional* when 'prefix' is a filename")
|
||||||
familyFlag := gcpCmd.String("family", "", "GCP Image Family. A group of images where the family name points to the most recent image. *Optional* when 'prefix' is a filename")
|
familyFlag := gcpCmd.String("family", "", "GCP Image Family. A group of images where the family name points to the most recent image. *Optional* when 'prefix' is a filename")
|
||||||
nameFlag := gcpCmd.String("img-name", "", "Overrides the Name used to identify the file in Google Storage, Image and Instance. Defaults to [name]")
|
nameFlag := gcpCmd.String("img-name", "", "Overrides the Name used to identify the file in Google Storage, Image and Instance. Defaults to [name]")
|
||||||
|
diskSizeFlag := gcpCmd.Int("disk-size", 0, "Size of system disk in GB")
|
||||||
|
|
||||||
if err := gcpCmd.Parse(args); err != nil {
|
if err := gcpCmd.Parse(args); err != nil {
|
||||||
log.Fatal("Unable to parse args")
|
log.Fatal("Unable to parse args")
|
||||||
}
|
}
|
||||||
@ -61,6 +65,7 @@ func runGcp(args []string) {
|
|||||||
public := getBoolValue(publicVar, *publicFlag)
|
public := getBoolValue(publicVar, *publicFlag)
|
||||||
family := getStringValue(familyVar, *familyFlag, "")
|
family := getStringValue(familyVar, *familyFlag, "")
|
||||||
name := getStringValue(nameVar, *nameFlag, "")
|
name := getStringValue(nameVar, *nameFlag, "")
|
||||||
|
diskSize := getIntValue(diskSizeVar, *diskSizeFlag, defaultDiskSize)
|
||||||
|
|
||||||
client, err := NewGCPClient(keys, project)
|
client, err := NewGCPClient(keys, project)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -93,7 +98,7 @@ func runGcp(args []string) {
|
|||||||
name = prefix
|
name = prefix
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = client.CreateInstance(name, prefix, zone, machine, true); err != nil {
|
if err = client.CreateInstance(name, prefix, zone, machine, diskSize, true); err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "os"
|
import (
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
func getStringValue(envKey string, flagVal string, defaultVal string) string {
|
func getStringValue(envKey string, flagVal string, defaultVal string) string {
|
||||||
var res string
|
var res string
|
||||||
@ -23,6 +26,31 @@ func getStringValue(envKey string, flagVal string, defaultVal string) string {
|
|||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getIntValue(envKey string, flagVal int, defaultVal int) int {
|
||||||
|
var res int
|
||||||
|
|
||||||
|
// If defined, take the env variable
|
||||||
|
if _, ok := os.LookupEnv(envKey); ok {
|
||||||
|
var err error
|
||||||
|
res, err = strconv.Atoi(os.Getenv(envKey))
|
||||||
|
if err != nil {
|
||||||
|
res = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If a flag is specified, this value takes precedence
|
||||||
|
// Ignore cases where the flag carries the default value
|
||||||
|
if flagVal > 0 {
|
||||||
|
res = flagVal
|
||||||
|
}
|
||||||
|
|
||||||
|
// if we still don't have a value, use the default
|
||||||
|
if res == 0 {
|
||||||
|
res = defaultVal
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
func getBoolValue(envKey string, flagVal bool) bool {
|
func getBoolValue(envKey string, flagVal bool) bool {
|
||||||
var res bool
|
var res bool
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user