GoogleContainerTools/skaffold · error

initializing cache: %w

Error message

initializing cache: %w

What it means

`cache.NewCache` initializes the build cache (local or GCS-backed) that stores image build results keyed by artifact dependencies. This wraps its initialization failure in `NewForConfig`, stopping runner construction before any build.

Source

Thrown at pkg/skaffold/runner/new.go:141

		buildDependencies, err := sourceDependencies.SingleArtifactDependencies(ctx, artifact, tag)
		if err != nil {
			endTrace(instrumentation.TraceEndError(err))
			return nil, err
		}

		testDependencies, err := tester.TestDependencies(ctx, artifact)
		if err != nil {
			endTrace(instrumentation.TraceEndError(err))
			return nil, err
		}
		return append(buildDependencies, testDependencies...), nil
	}

	artifactCache, err := cache.NewCache(ctx, runCtx, isLocalImage, depLister, g, store)
	if err != nil {
		endTrace(instrumentation.TraceEndError(err))
		return nil, fmt.Errorf("initializing cache: %w", err)
	}
	// The Builder must be instantiated AFTER the Deployer, because the Deploy target influences
	// the Cluster object on the RunContext, which in turn influences whether or not we will push images.
	var builder build.Builder
	builder, err = build.NewBuilderMux(runCtx, store, artifactCache, func(p latest.Pipeline) (build.PipelineBuilder, error) {
		pb, err := GetBuilder(ctx, runCtx, store, sourceDependencies, p)
		if err != nil {
			return nil, err
		}
		return withPipelineBuildHooks(pb, p.Build.Hooks), nil
	})
	if err != nil {
		endTrace(instrumentation.TraceEndError(err))
		return nil, fmt.Errorf("creating builder: %w", err)
	}

	builder, tester, renderer, deployer = WithTimings(builder, tester, renderer, deployer, runCtx.CacheArtifacts())
	if runCtx.Notification() {

View on GitHub (pinned to a1189de023)

Solutions

  1. Read the wrapped error; fix cache backend access (credentials for GCS, or bucket existence/permissions).
  2. Ensure the local cache directory location is writable (check $HOME/XDG paths, disk space).
  3. Clear a potentially corrupt cache directory and retry.
  4. Disable the cache temporarily (`--cache-artifacts=false` / remove cloud cache options) to unblock, then fix the backend.

Example fix

// CI before (read-only HOME)
$ skaffold build
// initializing cache: creating cache dir: mkdir /home/ro: read-only file system
// after (Dockerfile/CI)
export XDG_CACHE_HOME=/tmp/cache
skaffold build
Defensive patterns

Strategy: validation

Validate before calling

func cacheDirWritable() error {
  dir := os.Getenv("XDG_CACHE_HOME")
  if dir == "" {
    h, _ := os.UserHomeDir()
    dir = filepath.Join(h, ".cache")
  }
  probe := filepath.Join(dir, ".skaffold-cache-probe")
  if err := os.WriteFile(probe, nil, 0o644); err != nil {
    return fmt.Errorf("cache dir %s not writable: %w", dir, err)
  }
  os.Remove(probe)
  return nil
}

Try / catch

runner, err := runner.NewForConfig(runCtx)
if err != nil {
  if strings.Contains(err.Error(), "initializing cache") {
    log.Warn("cache unavailable; retrying with cache disabled")
    return runWithoutCache()
  }
  return err
}

Prevention

When it happens

Trigger: Local cache directory cannot be created/opened (permissions, read-only FS), or a remote cache backend (GCS bucket via `--cache-artifacts`/run context) cannot be reached or authenticated.

Common situations: CI containers with read-only $HOME so the local cache dir can't be created; cloud cache with missing GCS credentials/permissions; disk full on the machine hosting the cache.

Related errors


AI-assisted analysis of GoogleContainerTools/skaffold@a1189de023 (2026-09-05). Data as JSON: /api/errors/e511fbaab6ef02e5. Report an issue: GitHub.