Skip to content
Closed
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
27 changes: 26 additions & 1 deletion spread/google.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,22 @@ func (p *googleProvider) createMachine(ctx context.Context, system *System) (*go
}
debugf("System %s will use Google image %s", system, sourceImage)

owner := strings.ToLower(username())
if !p.validLabel(owner) {
// the username doesn't match Google's label constraints:
// https://docs.cloud.google.com/compute/docs/labeling-resources
// The username might be an email address (corporate setup) so do a best-effort
// check and try to preserve the personal part of the address. We could
// encode it in base64url but those wouldn't be human readable

if index, ok := isKindOfAnEmail(owner); ok {
owner = strings.ReplaceAll(owner[:index], ".", "-")
}
}

labels := googleParams{
"spread": "true",
"owner": strings.ToLower(username()),
"owner": owner,
"reuse": strconv.FormatBool(p.options.Reuse),
}
if p.validLabel(p.options.Password) {
Expand Down Expand Up @@ -548,6 +561,18 @@ func (p *googleProvider) createMachine(ctx context.Context, system *System) (*go
return s, nil
}

// isKindOfAnEmail checks if the string has a '@' character and a '.' after it,
// if it does it returns true and the index of the @.
func isKindOfAnEmail(str string) (index int, ok bool) {
if index = strings.Index(str, "@"); index != -1 {
if strings.Index(str[index:], ".") != -1 {
return index, true
}
}

return -1, false
}

func (p *googleProvider) waitServerBoot(ctx context.Context, s *googleServer) error {
printf("Waiting for %s to boot at %s...", s, s.address)

Expand Down
Loading