kubernetes/kops · error

CacheDir is required

Error message

CacheDir is required

What it means

NodeUpCommand requires CacheDir, the local directory where nodeup caches downloaded binaries and assets. Run returns this error immediately when the field is empty. It is a required-flag/usage error; nodeup does not infer a default cache directory.

Source

Thrown at upup/pkg/fi/nodeup/command.go:104

	ctx := context.Background()

	var bootConfig nodeup.BootConfig
	if c.ConfigLocation != "" {
		b, err := vfs.Context.ReadFile(c.ConfigLocation)
		if err != nil {
			return fmt.Errorf("error loading configuration %q: %v", c.ConfigLocation, err)
		}

		err = utils.YamlUnmarshal(b, &bootConfig)
		if err != nil {
			return fmt.Errorf("error parsing configuration %q: %v", c.ConfigLocation, err)
		}
	} else {
		return fmt.Errorf("ConfigLocation is required")
	}

	if c.CacheDir == "" {
		return fmt.Errorf("CacheDir is required")
	}

	region, err := getRegion(ctx, &bootConfig)
	if err != nil {
		return err
	}

	var configBase vfs.Path

	// If we're using a config server instead of vfs, nodeConfig will hold our configuration
	var nodeConfig *nodeup.NodeConfig

	if bootConfig.ConfigServer != nil && len(bootConfig.ConfigServer.Servers) > 0 {
		response, err := getNodeConfigFromServers(ctx, &bootConfig, region)
		if err != nil {
			return fmt.Errorf("failed to get node config from server: %w", err)
		}
		nodeConfig = response.NodeConfig

View on GitHub (pinned to 4c8573c808)

Solutions

  1. Pass --cachedir /var/cache/nodeup (or equivalent writable path) when invoking nodeup
  2. Set NodeUpCommand.CacheDir in code before calling Run
  3. Ensure the generated user-data/unit file includes the cachedir argument and the path exists and is writable by root

Example fix

// before
nodeup --config s3://bucket/... (no --cachedir)
// after
nodeup --config s3://bucket/... --cachedir /var/cache/nodeup
Defensive patterns

Strategy: validation

Validate before calling

if cfg.CacheDir == "" {
  return errors.New("nodeup requires --cachedir (e.g. /var/cache/nodeup)")
}

Type guard

func cacheReady(cmd *NodeUpCommand) bool { return cmd.CacheDir != "" }

Try / catch

if err := cmd.Run(os.Stdout); err != nil {
  if err.Error() == "CacheDir is required" {
    klog.Error("nodeup invoked without --cachedir; fix the user-data/systemd unit")
    os.Exit(2)
  }
  return err
}

Prevention

When it happens

Trigger: Invoking nodeup without --cachedir, or constructing NodeUpCommand in code without setting CacheDir.

Common situations: Systemd unit or user-data template missing the --cachedir argument; custom code building NodeUpCommand but leaving CacheDir empty; regression in generated nodeup invocation.

Understand the failure class

Background: "--flag is required" and "must specify" CLI errors: how missing-required-flag validation works and how to fix it — this error's family across 20 libraries.

Related errors


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