kubernetes/kops · error

parsing S3 location: %w

Error message

parsing S3 location: %w

What it means

escapeS3Location parses the S3 URL with url.Parse before re-escaping the path via httpbinding.EscapePath. This error is thrown when Go's url.Parse rejects the location string, meaning it is not a syntactically valid URL at all.

Source

Thrown at pkg/model/resources/nodeup.go:286

			escape = escapeS3Location
		case strings.HasPrefix(location, "azureblob://"):
			escape = escapeBlobLocation
		default:
			continue
		}
		escaped, err := escape(location)
		if err != nil {
			return "", fmt.Errorf("escaping nodeup source %q: %w", location, err)
		}
		locations[i] = escaped
	}
	return strings.Join(locations, ","), nil
}

func escapeS3Location(location string) (string, error) {
	u, err := url.Parse(location)
	if err != nil {
		return "", fmt.Errorf("parsing S3 location: %w", err)
	}
	if u.Scheme != "s3" || u.Host == "" {
		return "", fmt.Errorf("invalid S3 location")
	}

	return "s3://" + u.Host + httpbinding.EscapePath(u.Path, false), nil
}

func escapeBlobLocation(location string) (string, error) {
	u, err := url.Parse(location)
	if err != nil {
		return "", fmt.Errorf("parsing Azure Blob location: %w", err)
	}
	container, key, _ := strings.Cut(strings.TrimPrefix(u.Path, "/"), "/")
	// Reject ports, IPv6 hosts, userinfo, queries, and fragments, which the account-based
	// blob.core.windows.net URL cannot represent, so they fail here instead of in the boot retry loop.
	if u.Scheme != "azureblob" || u.Host == "" || u.Hostname() != u.Host || u.User != nil || u.RawQuery != "" || u.Fragment != "" || container == "" || key == "" {
		return "", fmt.Errorf("invalid Azure Blob location; expected azureblob://<account>/<container>/<key>")

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Read the wrapped url.Parse error to see the offending position.
  2. Fix the S3 URL so it is a valid URL: s3://<bucket>/<key> with no spaces or control characters.
  3. If the location is assembled dynamically, percent-escape or sanitize its components first.
  4. Verify with `url.Parse` in a small Go snippet or `kops toolbox` that the URL parses.

Example fix

// before
location := fmt.Sprintf("s3://%s/nodeup", bucketNameWithSpace)
// after
location := fmt.Sprintf("s3://%s/nodeup", strings.ReplaceAll(bucketName, " ", "-"))
Defensive patterns

Strategy: validation

Validate before calling

u, err := url.Parse(location)
if err != nil {
    return fmt.Errorf("s3 location not a valid URL: %w", err)
}

Type guard

func parsesAsURL(s string) bool { _, err := url.Parse(s); return err == nil }

Try / catch

escaped, err := escapeS3Location(loc)
if err != nil {
    return fmt.Errorf("fix s3:// URL syntax (%v): %w", loc, err)
}

Prevention

When it happens

Trigger: A nodeup source location with the s3:// scheme that contains characters invalid for url.Parse, such as raw spaces, unescaped control characters, or a malformed authority (e.g. 's3://bucket:/key' variants that trip the parser).

Common situations: Hand-edited nodeup source values, templating mistakes that leave whitespace or newlines in the URL, or copy-paste artifacts like trailing spaces or embedded quotes.

Related errors


AI-assisted analysis of kubernetes/kops@4c8573c808 (2026-09-05). Data as JSON: /api/errors/07635e926c6c4c57. Report an issue: GitHub.