{"record":{"id":"26b0953d8a55ac7a","repo":"kubernetes/kops","slug":"could-not-get-existing-object-w","errorCode":null,"errorMessage":"could not get existing object: %w","messagePattern":"could not get existing object: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/applylib/applyset/unstructuredclient.go","lineNumber":118,"sourceCode":"\t}\n\n\tupdated, err := dynamicResource.Update(ctx, obj, opt)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error updating object: %w\", err)\n\t}\n\treturn updated, nil\n}\n\n// Get reads the specified object.\nfunc (c *UnstructuredClient) Get(ctx context.Context, gvk schema.GroupVersionKind, nn types.NamespacedName) (*unstructured.Unstructured, error) {\n\tdynamicResource, err := c.dynamicResource(ctx, gvk, nn.Namespace)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tobj, err := dynamicResource.Get(ctx, nn.Name, metav1.GetOptions{})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"could not get existing object: %w\", err)\n\t}\n\n\treturn obj, nil\n}\n","sourceCodeStart":100,"sourceCodeEnd":123,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/applylib/applyset/unstructuredclient.go#L100-L123","documentation":"Get wraps errors from reading an existing object via the dynamic client. The wrapped error distinguishes the cases: NotFound means the object does not exist yet; anything else (RBAC, network, bad namespace) means the read itself failed.","triggerScenarios":"Calling UnstructuredClient.Get (used by ApplyOnce to fetch current state before applying) when the object is absent, RBAC blocks read, the namespace/scope is wrong, or the API server is unreachable.","commonSituations":"First apply of a brand-new object where it legitimately does not exist yet (treat NotFound as create, not failure); wrong namespace configured; missing get RBAC for the service account; typo in GVK leading to a nonexistent resource type.","solutions":["Check apierrors.IsNotFound(err) and treat it as the create path instead of a hard failure","Verify the namespace and GVK are correct (a wrong namespace or kind yields NotFound)","Check RBAC get permission for the resource in the target namespace","If non-NotFound, inspect the wrapped API error (Forbidden, Timeout) and fix connectivity/permissions"],"exampleFix":"// before\nobj, err := client.Get(ctx, gvk, nn)\nif err != nil {\n\treturn err\n}\n// after\nobj, err := client.Get(ctx, gvk, nn)\nif err != nil {\n\tif apierrors.IsNotFound(err) {\n\t\t// object does not exist yet: proceed with create/apply\n\t\treturn nil\n\t}\n\treturn err\n}","handlingStrategy":"type-guard","validationCode":"if nn.Namespace == \"\" && requiresNamespace(gvk) {\n\treturn fmt.Errorf(\"pre-check: cannot get %s without namespace\", gvk.Kind)\n}","typeGuard":"func isNotExist(err error) bool {\n\treturn err != nil && apierrors.IsNotFound(errors.Unwrap(err))\n}","tryCatchPattern":"obj, err := client.Get(ctx, gvk, nn)\nswitch {\ncase err == nil:\n\t// object exists\n\tcase isNotExist(err):\n\t// treat as create path\n\tcase apierrors.IsForbidden(errors.Unwrap(err)):\n\t// check RBAC get permissions\n\tdefault:\n\treturn err\n}","preventionTips":["Expect NotFound on first apply and branch to create instead of failing","Verify namespace and GVK spelling when reads unexpectedly 404","Audit RBAC get permissions for the operator's ServiceAccount","Check API server connectivity for non-NotFound wrapped errors"],"tags":["kubernetes","get","not-found"],"backgroundTag":"kubernetes-object-not-found","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"}