{"record":{"id":"ebc616c09cf64cd6","repo":"kubernetes/kops","slug":"building-instance-profile-for-q-w","errorCode":null,"errorMessage":"building instance profile for %q: %w","messagePattern":"building instance profile for %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"upup/pkg/fi/cloudup/template_functions_karpenter.go","lineNumber":222,"sourceCode":"}\n\nfunc marshalKarpenterResource(ig *kops.InstanceGroup, object interface{}) (string, error) {\n\tdata, err := yaml.Marshal(object)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"marshaling Karpenter resource for %q: %w\", ig.Name, err)\n\t}\n\treturn strings.TrimSpace(string(data)), nil\n}\n\nfunc (tf *TemplateFunctions) buildKarpenterEC2NodeClass(ig *kops.InstanceGroup) (*karpenterEC2NodeClass, error) {\n\tamiSelectorTerms, err := buildKarpenterAMITerms(ig.Spec.Image)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"building amiSelectorTerms for %q: %w\", ig.Name, err)\n\t}\n\n\tinstanceProfile, err := tf.LinkToIAMInstanceProfile(ig)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"building instance profile for %q: %w\", ig.Name, err)\n\t}\n\n\ttags, err := tf.CloudTagsForInstanceGroup(ig)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"building tags for %q: %w\", ig.Name, err)\n\t}\n\ttags = karpenterEC2NodeClassTags(tags)\n\tassociatePublicIP, err := tf.karpenterAssociatePublicIP(ig)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tuserData, err := tf.managedFileContents(\"nodeupscript-\" + ig.Name)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"reading userData for %q: %w\", ig.Name, err)\n\t}\n\trootDeviceName, err := tf.karpenterRootDeviceName(ig.Spec.Image)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"resolving root device for %q: %w\", ig.Name, err)","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/upup/pkg/fi/cloudup/template_functions_karpenter.go#L204-L240","documentation":"Returned by buildKarpenterEC2NodeClass when tf.LinkToIAMInstanceProfile(ig) fails to resolve the IAM instance profile for the instance group. The wrapped cause explains why (profile task missing or not built yet).","triggerScenarios":"Rendering a KarpenterEC2NodeClass for an instance group whose IAMInstanceProfile task cannot be linked — profile task absent from the task map or failed construction earlier in cloudup.","commonSituations":"IAMInstanceProfile not created for the instance group (profile spec removed), custom IAM configuration that skips profile creation, ordering issues where templates render before IAM tasks exist.","solutions":["Verify the instance group has an IAM instance profile configured and its task is built","Check the wrapped error from LinkToIAMInstanceProfile for the missing task name","Ensure template rendering happens after IAM task construction in the build","If using external IAM, confirm profile name is resolvable"],"exampleFix":"// before: instance group with no profile\niam:\n  allowContainerRegistry: true\n// after\niam:\n  allowContainerRegistry: true\n  instanceProfile: nodes.karpenter  # or let kops generate it","handlingStrategy":"validation","validationCode":"// ensure the instance group defines an IAM instance profile before rendering\nif ig.Spec.IAM == nil || (ig.Spec.IAM.InstanceProfile == nil && ig.Spec.IAM.Profile == nil) && !allowGenerated {\n\treturn fmt.Errorf(\"instance group %q has no IAM instance profile\", ig.Name)\n}","typeGuard":null,"tryCatchPattern":"nc, err := tf.KarpenterEC2NodeClass(ig)\nif err != nil {\n\treturn fmt.Errorf(\"instance profile resolution for %q failed: %w\", ig.Name, err)\n}","preventionTips":["Always configure iam settings for Karpenter instance groups","Ensure IAM tasks are constructed before template rendering","Test EC2NodeClass rendering end-to-end in CI","Keep instanceProfile names consistent with generated IAM tasks"],"tags":["karpenter","iam","instance-profile","kops"],"backgroundTag":"missing-iam-instance-profile","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"}