{"record":{"id":"6b412110ddea5077","repo":"kubernetes/kops","slug":"error-rendering-userdata-s","errorCode":null,"errorMessage":"error rendering UserData: %s","messagePattern":"error rendering UserData: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/azuretasks/vmscaleset.go","lineNumber":281,"sourceCode":"\t}\n\treturn nil\n}\n\n// RenderAzure creates or updates a VM Scale Set.\nfunc (s *VMScaleSet) RenderAzure(t *azure.AzureAPITarget, a, e, changes *VMScaleSet) error {\n\tif a == nil {\n\t\tklog.Infof(\"Creating a new VM Scale Set with name: %s\", fi.ValueOf(e.Name))\n\t} else {\n\t\tklog.Infof(\"Updating a VM Scale Set with name: %s\", fi.ValueOf(e.Name))\n\t}\n\n\tname := *e.Name\n\n\tvar customData *string\n\tif e.UserData != nil {\n\t\td, err := fi.ResourceAsBytes(e.UserData)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"error rendering UserData: %s\", err)\n\t\t}\n\t\tcustomData = to.Ptr(base64.StdEncoding.EncodeToString(d))\n\t}\n\n\tosProfile := &compute.VirtualMachineScaleSetOSProfile{\n\t\tComputerNamePrefix: e.ComputerNamePrefix,\n\t\tAdminUsername:      e.AdminUser,\n\t\tLinuxConfiguration: &compute.LinuxConfiguration{\n\t\t\tSSH: &compute.SSHConfiguration{\n\t\t\t\tPublicKeys: []*compute.SSHPublicKey{\n\t\t\t\t\t{\n\t\t\t\t\t\tPath:    to.Ptr(fmt.Sprintf(\"/home/%s/.ssh/authorized_keys\", *e.AdminUser)),\n\t\t\t\t\t\tKeyData: to.Ptr(*e.SSHPublicKey),\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\tDisablePasswordAuthentication: to.Ptr(true),\n\t\t},","sourceCodeStart":263,"sourceCodeEnd":299,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/azuretasks/vmscaleset.go#L263-L299","documentation":"In RenderAzure, before creating/updating a VMSS, kOps converts the task's UserData fi.Resource (e.g. nodeup bootstrap script) into bytes with fi.ResourceAsBytes so it can base64-encode it into osProfile.customData. If reading the resource bytes fails, RenderAzure returns this error and the whole apply for the VMSS task fails.","triggerScenarios":"RenderAzure (via kops update cluster apply) when e.UserData is non-nil but fi.ResourceAsBytes cannot read it — e.g. a resource backed by an unreadable file path, a failed/closed reader, or a nil/invalid resource implementation.","commonSituations":"Assets/vfs file unreadable at apply time (permissions, missing file); custom fi.Resource implementations whose Read errors; transient storage issues when reading from a remote VFS.","solutions":["Re-run the apply; if the source was a remote VFS, check connectivity/credentials to the state store.","If UserData points at a local file, verify the path exists and is readable by the kops process.","Check custom fi.Resource implementations for Read errors; fix or replace with fi.NewBytesResource.","Regenerate the target with `kops update cluster` to rebuild the resource from the cluster spec."],"exampleFix":"// before (unreliable reader)\nr := myLazyFileReader(path)\ne.UserData = r\n// after (read once, surface errors early)\nb, err := os.ReadFile(path)\nif err != nil { return err }\ne.UserData = fi.NewBytesResource(b)","handlingStrategy":"try-catch","validationCode":"if e.UserData != nil {\n  if _, err := fi.ResourceAsBytes(e.UserData); err != nil {\n    return fmt.Errorf(\"userdata unreadable before apply: %w\", err)\n  }\n}","typeGuard":null,"tryCatchPattern":"d, err := fi.ResourceAsBytes(e.UserData)\nif err != nil {\n  return fmt.Errorf(\"error rendering UserData: %s\", err)\n}","preventionTips":["Verify state store connectivity/credentials before applying","Prefer fi.NewBytesResource for custom resources","Ensure referenced local files exist and are readable","Test custom fi.Resource implementations for read errors"],"tags":["azure","vmss","userdata","render"],"backgroundTag":"userdata-render-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"}