{"record":{"id":"6c20130a75aa7f79","repo":"kubernetes/kops","slug":"error-closing-target-w","errorCode":null,"errorMessage":"error closing target: %w","messagePattern":"error closing target: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/nodeup/command.go","lineNumber":395,"sourceCode":"\tcontext, err := fi.NewNodeupContext(ctx, target, keyStore, &bootConfig, &nodeupConfig, taskMap)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error building context: %w\", err)\n\t}\n\n\tvar options fi.RunTasksOptions\n\toptions.InitDefaults()\n\n\t// Return rather than exit, so that the retry loop in cmd/nodeup gets to run:\n\t// kops-configuration.service is Type=oneshot, so a bootstrap that exits here is never\n\t// retried and the node never joins the cluster.\n\terr = context.RunTasks(options)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error running tasks: %w\", err)\n\t}\n\n\terr = target.Finish(taskMap)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error closing target: %w\", err)\n\t}\n\n\tif nodeupConfig.EnableLifecycleHook {\n\t\tif bootConfig.CloudProvider == api.CloudProviderAWS {\n\t\t\terr := completeWarmingLifecycleAction(ctx, cloud, modelContext)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to complete lifecylce action: %w\", err)\n\t\t\t}\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc getMachineType(ctx context.Context) (string, error) {\n\tconfig, err := awsconfig.LoadDefaultConfig(ctx)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to load AWS config: %w\", err)\n\t}","sourceCodeStart":377,"sourceCodeEnd":413,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/nodeup/command.go#L377-L413","documentation":"After tasks succeed, Run() calls target.Finish(taskMap) to finalize. For LocalTarget this flushes any pending operations/assets to the cache; for the dry-run target it writes the manifest to the output writer. A failure here is wrapped as \"error closing target\" — the work may have been applied but results could not be persisted/reported.","triggerScenarios":"target.Finish(taskMap) returns an error: for LocalTarget, failures writing to CacheDir; for NodeupDryRunTarget, failures writing to the output stream (closed/broken pipe, unwritable file).","commonSituations":"--cache-dir points to a read-only or full filesystem; disk full on the node; dry-run output file path unwritable or the pipe consumer exited early (e.g. `nodeup --target dryrun | head` closing stdout).","solutions":["Check the wrapped error and confirm the cache dir (--cache-dir, default /var/cache/nodeup) is writable and has free space","For dryrun, ensure the output file/pipe is valid and the consumer is still reading","Free disk space or fix permissions on the cache/output paths, then re-run nodeup","Since tasks already ran, verify node state with systemctl/containerd before blindly re-running"],"exampleFix":"// before\nnodeup --target=dryrun --config=... > /mnt/ro/out.yaml   # /mnt/ro read-only\n// after\nnodeup --target=dryrun --config=... > /tmp/out.yaml","handlingStrategy":"validation","validationCode":"cacheDir := \"/var/cache/nodeup\"\nif info, err := os.Stat(cacheDir); err != nil || !info.IsDir() {\n    os.MkdirAll(cacheDir, 0o755)\n}\nif unix.Access(cacheDir, unix.W_OK) != nil {\n    return fmt.Errorf(\"cache dir %s not writable\", cacheDir)\n}","typeGuard":null,"tryCatchPattern":"if err := nodeupCmd.Run(ctx); err != nil {\n    if strings.Contains(err.Error(), \"error closing target\") {\n        log.Fatalf(\"target finish failed (check cache dir / output file): %v\", err)\n    }\n    return err\n}","preventionTips":["Ensure --cache-dir exists, is writable, and has free space","For dryrun, write output to a real file rather than a short-lived pipe","Monitor disk usage on nodes before bootstrap","Remember tasks may have applied — verify node state before re-running"],"tags":["nodeup","target","filesystem","dryrun"],"backgroundTag":"target-finish-write-failed","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}