{"record":{"id":"fdcea06d662d31c5","repo":"kubernetes/kops","slug":"error-creating-gcp-machine-template-w","errorCode":null,"errorMessage":"error creating gcp machine template: %w","messagePattern":"error creating gcp machine template: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"clusterapi/pkg/builders/machinedeploymentbuilder.go","lineNumber":221,"sourceCode":"\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}\n\tsort.Slice(machineDeployments, func(i, j int) bool {\n\t\treturn machineDeployments[i].GetName() < machineDeployments[j].GetName()\n\t})\n","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/clusterapi/pkg/builders/machinedeploymentbuilder.go#L203-L239","documentation":"MachineDeploymentBuilder.BuildObjects wraps any failure from createGCPMachineTemplate with this message. That function builds a GCPMachineTemplate unstructured object (infrastructure.cluster.x-k8s.io/v1beta1) including instance type, image, subnet (cluster-suffixed), and network tags. The failure cause is preserved via %w.","triggerScenarios":"Calling BuildObjects when createGCPMachineTemplate errors — e.g. gce.TagForRole or gce.ClusterSuffixedName helpers failing on malformed ClusterName/Subnet/Role inputs, or a dead context.","commonSituations":"Cluster names exceeding GCP's 63-char safe-name limit, an empty or unrecognized InstanceGroupRole, an empty Subnet producing an invalid suffixed name, or a malformed image spec.","solutions":["Read the wrapped underlying error after this message for the actual cause.","Validate ClusterName (must survive gce.SafeClusterName / 63-char suffixing) and Subnet before building.","Ensure Role is a valid kops.InstanceGroupRole (e.g. Node, ControlPlane) so TagForRole can compute the network tag.","Check the Image field format; values with one '/' are rewritten to projects/<proj>/global/images/<name>, invalid forms pass through and may fail downstream."],"exampleFix":"// before\nb := &builders.MachineDeploymentBuilder{ClusterName: \"\", Subnet: \"\"}\n// after\nif b.ClusterName == \"\" || b.Subnet == \"\" {\n    return fmt.Errorf(\"ClusterName and Subnet are required\")\n}","handlingStrategy":"validation","validationCode":"if b.ClusterName == \"\" || len(b.ClusterName) > 63 {\n    return fmt.Errorf(\"ClusterName must be non-empty and <= 63 chars\")\n}\nif b.Subnet == \"\" {\n    return fmt.Errorf(\"Subnet must be set\")\n}\nif b.Role == \"\" {\n    return fmt.Errorf(\"Role must be a valid kops.InstanceGroupRole\")\n}","typeGuard":null,"tryCatchPattern":"objs, err := builder.BuildObjects(ctx)\nif err != nil {\n    var wrapped error\n    if errors.As(err, &wrapped) && strings.Contains(err.Error(), \"gcp machine template\") {\n        return fmt.Errorf(\"GCPMachineTemplate generation failed (check cluster name/subnet/role): %w\", err)\n    }\n    return err\n}","preventionTips":["Keep cluster names short enough to survive 63-char suffixing (gce.ClusterSuffixedName).","Use only valid kops.InstanceGroupRole values so TagForRole works.","Provide the image in project/name form or a full image URL."],"tags":["kops","cluster-api","gcp","gce-machine-template"],"backgroundTag":"gcp-machine-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"}