From ff9582d1b6ee110fc68c1cea54022eb839c4212d Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Wed, 13 Feb 2019 18:12:43 -0500 Subject: [PATCH 1/4] Allow for specifying custom VM type via compound group value --- backend/gce.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/backend/gce.go b/backend/gce.go index ccd3de5f1..3a7a6156a 100644 --- a/backend/gce.go +++ b/backend/gce.go @@ -792,7 +792,7 @@ func (p *gceProvider) Setup(ctx gocontext.Context) error { logger.Debug("building machine type self link map") for _, zoneName := range append([]string{p.ic.Zone.Name}, p.alternateZones...) { - for _, machineType := range []string{p.ic.MachineType, p.ic.PremiumMachineType} { + for _, machineType := range []string{p.ic.MachineType, p.ic.PremiumMachineType, "n1-highmem-4", "n1-standard-8"} { if zoneName == "" || machineType == "" { continue } @@ -913,6 +913,23 @@ func (p *gceProvider) SupportsProgress() bool { func (p *gceProvider) StartWithProgress(ctx gocontext.Context, startAttributes *StartAttributes, progresser Progresser) (Instance, error) { logger := context.LoggerFromContext(ctx).WithField("self", "backend/gce_provider") + // HACK: extract vm type from group { + // e.g.: + // + // group: stable,vm_type=n1-highmem-4 + // + if strings.HasPrefix(startAttributes.Group, "vm_type") { + parts := strings.Split(startAttributes.Group, ",") + if len(parts) == 2 { + vmTypeParts := strings.Split(parts[1], "=") + if len(vmTypeParts) == 2 { + startAttributes.VMType = strings.TrimSpace(vmTypeParts[1]) + startAttributes.Group = strings.TrimSpace(parts[0]) + } + } + } + // } + c := &gceStartContext{ startAttributes: startAttributes, zoneName: p.ic.Zone.Name, @@ -1458,8 +1475,15 @@ func (p *gceProvider) buildInstance(ctx gocontext.Context, c *gceStartContext) ( } machineType := p.ic.MachineType - if c.startAttributes.VMType == "premium" { + switch c.startAttributes.VMType { + case "premium": machineType = p.ic.PremiumMachineType + case "n1-standard-8": + machineType = "n1-standard-8" + case "n1-highmem-4": + machineType = "n1-highmem-4" + default: + return nil, fmt.Errorf("unknown vm type %s in start attributes", c.startAttributes.VMType) } var ok bool From 0106501da86b805c03ccfdc1c6bc72b74e4eff09 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Wed, 13 Feb 2019 18:41:18 -0500 Subject: [PATCH 2/4] Split on space instead of comma in compound group --- backend/gce.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/backend/gce.go b/backend/gce.go index 3a7a6156a..11c9a8c24 100644 --- a/backend/gce.go +++ b/backend/gce.go @@ -916,10 +916,10 @@ func (p *gceProvider) StartWithProgress(ctx gocontext.Context, startAttributes * // HACK: extract vm type from group { // e.g.: // - // group: stable,vm_type=n1-highmem-4 + // group: stable vm_type=n1-highmem-4 // - if strings.HasPrefix(startAttributes.Group, "vm_type") { - parts := strings.Split(startAttributes.Group, ",") + if strings.Contains(startAttributes.Group, "vm_type=") { + parts := strings.Split(startAttributes.Group, " ") if len(parts) == 2 { vmTypeParts := strings.Split(parts[1], "=") if len(vmTypeParts) == 2 { From 09f1c5e2da1d9df68304f1cafab4fe09340c1bca Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Wed, 13 Feb 2019 19:31:12 -0500 Subject: [PATCH 3/4] Handle the case of a literal "default" vm type --- backend/gce.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/gce.go b/backend/gce.go index 11c9a8c24..e2c84c592 100644 --- a/backend/gce.go +++ b/backend/gce.go @@ -1482,6 +1482,8 @@ func (p *gceProvider) buildInstance(ctx gocontext.Context, c *gceStartContext) ( machineType = "n1-standard-8" case "n1-highmem-4": machineType = "n1-highmem-4" + case "default": + machineType = p.ic.MachineType default: return nil, fmt.Errorf("unknown vm type %s in start attributes", c.startAttributes.VMType) } From a7e15a01cdda7b6e74cf33da33191d57e8e6ae3a Mon Sep 17 00:00:00 2001 From: Duologic Date: Mon, 15 Jul 2019 14:18:31 +0200 Subject: [PATCH 4/4] Don't unescape ACCOUNT_JSON variable The GCE provider uses an ACCOUNT_JSON variable to fetch the credentials for accessing the GCE API. This variable can either be a path to the JSON or a string of the JSON. A similar implementation is used in gcloud-cleanup. In worker, the provider config is processed and all config variables are 'unescaped' as if it was a URL. This causes the JSON to become unusable, mainly because the private key contains `+` symbols which get replaced by spaces. This solution simply checks if the key ends with ACCOUNT_JSON and skips the 'unescape' step. This ensures backwards compatibility for any other variables relying on this behavior. Ideally we should only run this step when required, as in 'variable is a URL that needs unescaping'. --- config/provider_config.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/config/provider_config.go b/config/provider_config.go index 862a1c9ad..fc884e65e 100644 --- a/config/provider_config.go +++ b/config/provider_config.go @@ -98,9 +98,11 @@ func ProviderConfigFromEnviron(providerName string) *ProviderConfig { key := strings.ToUpper(strings.TrimPrefix(pair[0], prefix)) value := pair[1] - unescapedValue, err := url.QueryUnescape(value) - if err == nil { - value = unescapedValue + if !strings.HasSuffix(key, "ACCOUNT_JSON") { + unescapedValue, err := url.QueryUnescape(value) + if err == nil { + value = unescapedValue + } } pc.Set(key, value)