kubernetes/kops · error

unable to parse assetsLocation.fileRepository %q: %v

Error message

unable to parse assetsLocation.fileRepository %q: %v

What it means

After confirming assetsLocation.fileRepository is non-empty, remapURL parses it with url.Parse to build the mirror base URL. If the configured string is not a valid URL, parsing fails and the builder wraps the url.Parse error with this message. It prevents malformed repository URLs from producing corrupt asset paths.

Source

Thrown at pkg/assets/builder.go:458

	if a.assetsLocation != nil && a.assetsLocation.FileRepository != nil {
		return nil, fmt.Errorf("you might have not staged your files correctly, please execute 'kops get assets --copy'")
	}
	return nil, fmt.Errorf("cannot determine hash for %q (have you specified a valid file location?)", u)
}

func (a *AssetBuilder) remapURL(canonicalURL *url.URL) (*url.URL, error) {
	f := ""
	if a.assetsLocation != nil {
		f = values.StringValue(a.assetsLocation.FileRepository)
	}
	if f == "" {
		return nil, fmt.Errorf("assetsLocation.fileRepository must be set to remap asset %v", canonicalURL)
	}

	fileRepo, err := url.Parse(f)
	if err != nil {
		return nil, fmt.Errorf("unable to parse assetsLocation.fileRepository %q: %v", f, err)
	}

	fileRepo.Path = path.Join(fileRepo.Path, canonicalURL.Path)
	// Escape commas, which are legal in a path but separate locations in CompactString.
	fileRepo.RawPath = strings.ReplaceAll(fileRepo.EscapedPath(), ",", "%2C")

	return fileRepo, nil
}

func NormalizeImage(a *AssetBuilder, image string) string {
	if a.assetsLocation != nil && a.assetsLocation.ContainerProxy != nil {
		containerProxy := strings.TrimSuffix(*a.assetsLocation.ContainerProxy, "/")
		normalized := image

		// If the image name contains only a single / we need to determine if the image is located on docker-hub or if it's using a convenient URL,
		// like registry.k8s.io/<image-name> or registry.k8s.io/<image-name>
		// In case of a hub image it should be sufficient to just prepend the proxy url, producing eg docker-proxy.example.com/weaveworks/weave-kube
		if strings.Count(normalized, "/") <= 1 && !strings.ContainsAny(strings.Split(normalized, "/")[0], ".:") {

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Fix cluster.spec.assetsLocation.fileRepository to a well-formed absolute URL (scheme + host), e.g. https://artifacts.example.com/kops, then kops update cluster.
  2. Validate the URL locally before applying: `go run` or `python3 -c "import urllib.parse;urllib.parse.urlparse('YOUR_VALUE')"`.
  3. Quote the YAML value and check for hidden whitespace/control characters: kops get cluster -o yaml | grep fileRepository.

Example fix

// before
fileRepository: "ht tp://artifacts example.com/kops"
// after
fileRepository: "https://artifacts.example.com/kops"
Defensive patterns

Strategy: validation

Validate before calling

repo := cluster.Spec.AssetsLocation.FileRepository
if _, err := url.Parse(repo); err != nil {
    return fmt.Errorf("fileRepository %q is not a valid URL: %w", repo, err)
}

Type guard

func validURL(s string) bool {
    u, err := url.Parse(s)
    return err == nil && u.Scheme != "" && u.Host != ""
}

Try / catch

u, err := builder.RemapFile(canonicalURL)
if err != nil {
    if strings.HasPrefix(err.Error(), "unable to parse assetsLocation.fileRepository") {
        return fmt.Errorf("check spec.assetsLocation.fileRepository in the cluster spec: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Setting cluster.spec.assetsLocation.fileRepository to a string that url.Parse rejects, e.g. one containing invalid characters, control characters, or a bad scheme like "ht tp://repo" or "::not a url::".

Common situations: Typo or stray whitespace/quotes when copying the repository URL into the cluster spec; unescaped special characters (spaces, braces) in a YAML value; generating the spec programmatically with an unvalidated string.

Understand the failure class

Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.

Related errors


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