{"record":{"id":"2ff7932e5c453913","repo":"kubernetes/kops","slug":"error-building-context-v-2ff793","errorCode":null,"errorMessage":"error building context: %v","messagePattern":"error building context: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/apply_cluster.go","lineNumber":849,"sourceCode":"\n\t\t// Avoid making changes on a dry-run\n\t\tshouldPrecreateDNS = false\n\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unsupported target type %q\", c.TargetName)\n\t}\n\tc.Target = target\n\n\tif target.DefaultCheckExisting() {\n\t\tc.TaskMap, err = l.FindDeletions(cloud, c.LifecycleOverrides)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error finding deletions: %w\", err)\n\t\t}\n\t}\n\n\tcontext, err := fi.NewCloudupContext(ctx, deletionProcessingMode, target, cluster, cloud, keyStore, secretStore, configBase, c.TaskMap)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error building context: %v\", err)\n\t}\n\n\tvar options fi.RunTasksOptions\n\tif c.RunTasksOptions != nil {\n\t\toptions = *c.RunTasksOptions\n\t} else {\n\t\toptions.InitDefaults()\n\t}\n\n\terr = context.RunTasks(options)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error running tasks: %v\", err)\n\t}\n\n\tif !cluster.PublishesDNSRecords() {\n\t\tshouldPrecreateDNS = false\n\t}\n","sourceCodeStart":831,"sourceCodeEnd":867,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/apply_cluster.go#L831-L867","documentation":"Run constructs the fi.CloudupContext that ties together target, cluster, cloud, key/secret stores, configBase, and the task map. If fi.NewCloudupContext fails, the apply is aborted with this wrapped error — typically because one of those inputs is invalid (e.g. keystore/secretstore setup or configBase access problems).","triggerScenarios":"fi.NewCloudupContext returns an error during `kops update cluster` / apply — most often when the key store or secret store cannot be initialized or configBase (state store path) is unreachable.","commonSituations":"Broken or missing state-store (S3/GCS/Azure blob) configuration or credentials; cluster state deleted or moved so configBase paths are wrong; key store corruption (bad keys/certs); custom Go callers passing nil stores to ApplyClusterCmd.","solutions":["Inspect the wrapped message (%v) for the underlying cause and fix it","Verify the state store: --state flag / KOPS_STATE_STORE env and that the bucket/container exists and is accessible","Run `kops get cluster` to confirm kops can read cluster state from configBase","Check key store / secret store integrity (keys and certs readable)","If calling ApplyClusterCmd in Go, ensure all parameters to fi.NewCloudupContext are non-nil and correctly initialized"],"exampleFix":"// before\nexport KOPS_STATE_STORE=s3://nonexistent-bucket\nkops update cluster mycluster.example.com\n// after\nexport KOPS_STATE_STORE=s3://my-real-kops-state-bucket\nkops update cluster mycluster.example.com","handlingStrategy":"validation","validationCode":"if os.Getenv(\"KOPS_STATE_STORE\") == \"\" && stateStore == \"\" {\n\treturn fmt.Errorf(\"KOPS_STATE_STORE must be set and reachable\")\n}\n// verify readability before apply:\nif _, err := clientset.GetCluster(ctx, clusterName); err != nil {\n\treturn fmt.Errorf(\"cannot read cluster state: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := cmd.Run(ctx); err != nil && strings.Contains(err.Error(), \"error building context\") {\n\t// check state-store access, key/secret store init, configBase path\n}","preventionTips":["Verify --state / KOPS_STATE_STORE and cloud credentials before apply","Confirm `kops get cluster <name>` succeeds before updating","Don't move or delete state-store objects manually","Keep key store (kops get secrets) intact and backed up"],"tags":["state-store","context","apply"],"backgroundTag":"state-store-unreachable","analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}