{"record":{"id":"938d4919d56d7e5d","repo":"kubernetes/kops","slug":"failed-to-create-host-s-s-w","errorCode":null,"errorMessage":"failed to create host %s/%s: %w","messagePattern":"failed to create host (.+?)/(.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/toolbox_enroll.go","lineNumber":235,"sourceCode":"\t\treturn fmt.Errorf(\"building kubernetes scheme: %w\", err)\n\t}\n\t// Ensure that we don't try to use proto with our CRD\n\trestConfigNoProto := rest.CopyConfig(restConfig)\n\trestConfigNoProto.ContentType = runtime.ContentTypeJSON\n\trestConfigNoProto.AcceptContentTypes = runtime.ContentTypeJSON\n\n\tkubeClient, err := client.New(restConfigNoProto, client.Options{\n\t\tScheme: scheme,\n\t})\n\tif err != nil {\n\t\treturn fmt.Errorf(\"building kubernetes client: %w\", err)\n\t}\n\n\t// We can't create the host resource in the API server for control-plane nodes,\n\t// because the API server (likely) isn't running yet.\n\tif !ig.IsControlPlane() {\n\t\tif err := kubeClient.Create(ctx, hostData); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to create host %s/%s: %w\", hostData.Namespace, hostData.Name, err)\n\t\t}\n\t}\n\n\tfor k, v := range bootstrapData.NodeupScriptAdditionalFiles {\n\t\tif err := sshTarget.writeFile(ctx, k, bytes.NewReader(v)); err != nil {\n\t\t\treturn fmt.Errorf(\"writing file %q over SSH: %w\", k, err)\n\t\t}\n\t}\n\n\tif len(bootstrapData.NodeupScript) != 0 {\n\t\tif _, err := sshTarget.runScript(ctx, string(bootstrapData.NodeupScript), ExecOptions{Echo: true}); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\treturn nil\n}\n\nconst scriptCreateKey = `","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/commands/toolbox_enroll.go#L217-L253","documentation":"After building the controller-runtime client, enrollHost creates the kops Host custom resource in the kops-system namespace on the target cluster. The error wraps the API server's rejection of that Create call, including its reason.","triggerScenarios":"kubeClient.Create(ctx, hostData) returns an error: Host CRD not installed on the cluster, the Host with that namespace/name already exists (AlreadyExists), RBAC denies creating hosts, or the API server is unreachable.","commonSituations":"Enrolling a worker against a cluster where kops-controller CRDs are missing or an older kOps version, re-running enroll for a host that already registered, or insufficient user credentials against the admin API server.","solutions":["Check the wrapped error: if AlreadyExists, the host is registered — delete it first (kubectl -n kops-system delete host <name>) or proceed","Confirm the Host CRD exists: kubectl get crd hosts.kops.k8s.io; if missing, upgrade/apply kops CRDs","Verify RBAC: kubectl auth can-i create hosts.kops.k8s.io -n kops-system","Confirm API server connectivity: kubectl get --raw /healthz"],"exampleFix":"// before\nif err := kubeClient.Create(ctx, hostData); err != nil {\n    return fmt.Errorf(\"failed to create host %s/%s: %w\", hostData.Namespace, hostData.Name, err)\n}\n// after\nerr = kubeClient.Create(ctx, hostData)\nif err != nil {\n    if apierrors.IsAlreadyExists(err) {\n        klog.Infof(\"host %s/%s already registered\", hostData.Namespace, hostData.Name)\n    } else {\n        return fmt.Errorf(\"failed to create host %s/%s: %w\", hostData.Namespace, hostData.Name, err)\n    }\n}","handlingStrategy":"validation","validationCode":"kubectl get crd hosts.kops.k8s.io && \\\n  kubectl auth can-i create hosts.kops.k8s.io -n kops-system && \\\n  kubectl get --raw /healthz","typeGuard":"func canCreateHosts(cfg *rest.Config) bool {\n    cl, err := discovery.NewForConfig(cfg)\n    if err != nil { return false }\n    res, err := cl.ServerResourcesForGroupVersion(\"kops.k8s.io/v1alpha2\")\n    if err != nil { return false }\n    for _, r := range res.APIResources { return strings.Contains(r.Name, \"hosts\") }\n    return false\n}","tryCatchPattern":"err = kubeClient.Create(ctx, hostData)\nif err != nil {\n    if apierrors.IsAlreadyExists(err) { klog.Info(\"host already registered\") } else { return err }\n}","preventionTips":["Pre-check the Host CRD exists before enrolling workers","Handle AlreadyExists as idempotent rather than fatal","Confirm RBAC with kubectl auth can-i before automating enroll"],"tags":["kubernetes","crd","api-server"],"backgroundTag":"crd-create-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"}