kubernetes/kops · warning

error parsing: %v

Error message

error parsing: %v

What it means

loadCachedExecCredential reads the on-disk credential cache and unmarshals it into ExecCredential. If the file exists but is not valid JSON matching the struct, it returns this 'error parsing' wrapper. The caller (RunKubectlAuthHelper) treats any load error as a cache miss and re-issues credentials, so this is usually benign — it just forces a new certificate issue.

Source

Thrown at pkg/commands/helpers/kubectl_auth.go:214

		sanitizedName = sanitizedName[:32]
	}
	return filepath.Join(homedir.HomeDir(), ".kube", "cache", "kops-authentication", sanitizedName+"_"+hash)
}

func loadCachedExecCredential(cacheFilePath string) (*ExecCredential, error) {
	b, err := os.ReadFile(cacheFilePath)
	if err != nil {
		if os.IsNotExist(err) {
			// expected - a cache miss
			return nil, nil
		} else {
			return nil, err
		}
	}

	execCredential := &ExecCredential{}
	if err := json.Unmarshal(b, execCredential); err != nil {
		return nil, fmt.Errorf("error parsing: %v", err)
	}

	if execCredential.Status.ExpirationTimestamp.Before(time.Now()) {
		return nil, nil
	}

	if execCredential.Status.ClientCertificateData == "" || execCredential.Status.ClientKeyData == "" {
		return nil, fmt.Errorf("no credentials in cached file")
	}

	return execCredential, nil
}

func buildCredentials(ctx context.Context, f *util.Factory, options *HelperKubectlAuthOptions) (*ExecCredentialStatus, error) {
	clientset, err := f.KopsClient()
	if err != nil {
		return nil, err
	}

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Delete the corrupt cache file under ~/.kube/cache/kops-authentication/ and re-run; a fresh credential will be issued.
  2. No action strictly needed — the helper logs via klog.Infof and falls back to issuing new credentials.
  3. Avoid hand-editing cache files; the cache is derived from the kOps state store.

Example fix

// before
cat ~/.kube/cache/kops-authentication/mycluster_ab12cd  # corrupt
// after
rm ~/.kube/cache/kops-authentication/mycluster_ab12cd
Defensive patterns

Strategy: fallback

Validate before calling

b, err := os.ReadFile(path)
if err == nil && !json.Valid(b) {
    os.Remove(path) // drop corrupt cache before invoking the helper
}

Prevention

When it happens

Trigger: The file at ~/.kube/cache/kops-authentication/<name>_<hash> exists but contains garbage: truncated writes, hand-edited content, another tool overwriting it, or filesystem corruption.

Common situations: Manual inspection/editing of the cache file; disk-full during a previous write leaving a partial file; copying cache files between machines or state stores.

Related errors


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