{"record":{"id":"4a53b08e85eb54c2","repo":"kubernetes/kops","slug":"error-creating-kops-config-template-w","errorCode":null,"errorMessage":"error creating kops config template: %w","messagePattern":"error creating kops config template: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"clusterapi/pkg/builders/machinedeploymentbuilder.go","lineNumber":217,"sourceCode":"\t\t\t\"name\":      b.Name,\n\t\t\t\"namespace\": b.Namespace,\n\t\t},\n\t\t\"spec\": map[string]any{\n\t\t\t\"template\": map[string]any{\n\t\t\t\t\"spec\": templateSpec,\n\t\t\t},\n\t\t},\n\t}\n\n\tu := &unstructured.Unstructured{Object: obj}\n\n\tb.capiInfra = u\n\treturn nil\n}\n\nfunc (b *MachineDeploymentBuilder) BuildObjects(ctx context.Context) ([]*unstructured.Unstructured, error) {\n\tif err := b.createKopsConfigTemplate(ctx); err != nil {\n\t\treturn nil, fmt.Errorf(\"error creating kops config template: %w\", err)\n\t}\n\n\tif err := b.createGCPMachineTemplate(ctx); err != nil {\n\t\treturn nil, fmt.Errorf(\"error creating gcp machine template: %w\", err)\n\t}\n\n\tif err := b.buildMachineDeployments(); err != nil {\n\t\treturn nil, fmt.Errorf(\"error building machine deployments: %w\", err)\n\t}\n\n\tvar objects []*unstructured.Unstructured\n\tobjects = append(objects, b.capiConfigTemplate)\n\tobjects = append(objects, b.capiInfra)\n\n\tvar machineDeployments []*unstructured.Unstructured\n\tfor _, md := range b.capiMachineDeployments {\n\t\tmachineDeployments = append(machineDeployments, md)\n\t}","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/clusterapi/pkg/builders/machinedeploymentbuilder.go#L199-L235","documentation":"MachineDeploymentBuilder.BuildObjects wraps any failure from createKopsConfigTemplate with this message. createKopsConfigTemplate constructs the cluster-api KopsConfigTemplate unstructured object (bootstrap.cluster.x-k8s.io/v1beta1) from the builder's fields. In practice this means an earlier stage of generating the kops-config template failed, and the wrapper preserves the underlying cause via %w.","triggerScenarios":"Calling BuildObjects (via RunGenerateMachineDeployment) when createKopsConfigTemplate returns a non-nil error — typically when the context is cancelled/deadlined or the template construction fails.","commonSituations":"Running `kops create cluster --controller-nodes ...` style machine-deployment generation with a cancelled context; embedding the clusterapi builders in a tool whose ctx is already done; future validation added to template construction rejecting builder fields.","solutions":["Inspect the wrapped cause (%w) printed after this message — it identifies the real failure inside createKopsConfigTemplate.","Ensure the ctx passed to BuildObjects is alive (not cancelled/timed out) for the duration of object generation.","Verify Name and Namespace on MachineDeploymentBuilder are set to valid DNS-1123 values before calling BuildObjects.","Rebuild from a matching kops version; this builder code (clusterapi/pkg/builders) evolves with the cluster-api bootstrap provider."],"exampleFix":"// before\nobjs, err := builder.BuildObjects(ctx) // ctx from a short-lived request timeout\n// after\nctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)\ndefer cancel()\nobjs, err := builder.BuildObjects(ctx)","handlingStrategy":"try-catch","validationCode":"if err := ctx.Err(); err != nil {\n    return fmt.Errorf(\"context already done before BuildObjects: %w\", err)\n}\nif builder.Name == \"\" || builder.Namespace == \"\" {\n    return fmt.Errorf(\"builder Name and Namespace must be set\")\n}","typeGuard":null,"tryCatchPattern":"objs, err := builder.BuildObjects(ctx)\nif err != nil {\n    if strings.Contains(err.Error(), \"error creating kops config template\") {\n        // log wrapped cause: fmt.Sprintf(\"%+v\", errors.Unwrap(err))\n        return fmt.Errorf(\"kops config template stage failed: %w\", err)\n    }\n    return err\n}","preventionTips":["Always pass a live context with a sufficient timeout to BuildObjects.","Validate builder fields (Name, Namespace) before invoking.","Log errors with errors.Unwrap so the root cause is visible."],"tags":["kops","cluster-api","gcp","object-generation"],"backgroundTag":"kops-config-template-build-failed","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"}