Skip to content
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

Allow for specifying custom VM type via compound group value #582

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
30 changes: 28 additions & 2 deletions backend/gce.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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.Contains(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,
Expand Down Expand Up @@ -1458,8 +1475,17 @@ 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"
case "default":
machineType = p.ic.MachineType
default:
return nil, fmt.Errorf("unknown vm type %s in start attributes", c.startAttributes.VMType)
}

var ok bool
Expand Down
8 changes: 5 additions & 3 deletions config/provider_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down