{"record":{"id":"15e922cd53ba957f","repo":"kubernetes/kops","slug":"error-querying-namespace-q-v","errorCode":null,"errorMessage":"error querying namespace %q: %v","messagePattern":"error querying namespace %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"channels/pkg/channels/channel_version.go","lineNumber":148,"sourceCode":"\n\tif existing.SystemGeneration != c.SystemGeneration {\n\t\tif existing.SystemGeneration > c.SystemGeneration {\n\t\t\tklog.V(4).Infof(\"cluster has newer SystemGeneration for %q (%v vs %v), will not replace\", name, existing.SystemGeneration, c.SystemGeneration)\n\t\t\treturn false\n\t\t} else {\n\t\t\tklog.V(4).Infof(\"cluster has different SystemGeneration for %q (%v vs %v); will replace\", name, existing.SystemGeneration, c.SystemGeneration)\n\t\t\treturn true\n\t\t}\n\t}\n\n\tklog.V(4).Infof(\"manifest Match for %q: %v\", name, existing)\n\treturn false\n}\n\nfunc (c *Channel) GetInstalledVersion(ctx context.Context, k8sClient kubernetes.Interface) (*ChannelVersion, error) {\n\tns, err := k8sClient.CoreV1().Namespaces().Get(ctx, c.Namespace, metav1.GetOptions{})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error querying namespace %q: %v\", c.Namespace, err)\n\t}\n\n\tannotationValue, ok := ns.Annotations[c.AnnotationName()]\n\tif !ok {\n\t\treturn nil, nil\n\t}\n\n\treturn ParseChannelVersion(annotationValue)\n}\n\nfunc (c *Channel) IsPKIInstalled(ctx context.Context, k8sClient kubernetes.Interface, cmClient certmanager.Interface) (bool, error) {\n\t_, err := k8sClient.CoreV1().Secrets(\"kube-system\").Get(ctx, c.Name+\"-ca\", metav1.GetOptions{})\n\tif errors.IsNotFound(err) {\n\t\treturn false, nil\n\t}\n\tif err != nil {\n\t\treturn true, err\n\t}","sourceCodeStart":130,"sourceCodeEnd":166,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/channels/pkg/channels/channel_version.go#L130-L166","documentation":"GetInstalledVersion reads the installed channel version from an annotation on the channel's namespace. Before it can read the annotation, it fetches the namespace via the Kubernetes API; if that GET fails (namespace missing, RBAC denied, API server unreachable), the raw client error is wrapped with this message. It indicates the version could not be determined because the namespace itself could not be queried.","triggerScenarios":"Calling Channel.GetInstalledVersion when the namespace does not exist (NotFound), the caller lacks get permission on namespaces (Forbidden), or the API server connection fails (connection refused / timeout).","commonSituations":"Pointing the channel at a namespace in a different cluster than intended; running kops with insufficient kubeconfig credentials; typo'd namespace name; API server down or kubeconfig misconfigured.","solutions":["Verify the namespace exists: kubectl get namespace <name> in the target cluster.","Check kubeconfig context points at the correct cluster.","Grant the identity RBAC get permission on namespaces (clusterrole with 'namespaces' resource, 'get' verb).","Check API server reachability and network/VPN connectivity."],"exampleFix":"// before\nch := channels.AddonsChannel(namespace, name) // namespace not created\nv, err := ch.GetInstalledVersion(ctx, client)\n// after\nif _, err := client.CoreV1().Namespaces().Get(ctx, namespace, metav1.GetOptions{}); err != nil {\n    // create the namespace or fix the name before querying the version\n}\nv, err := ch.GetInstalledVersion(ctx, client)","handlingStrategy":"try-catch","validationCode":"nsClient := k8sClient.CoreV1().Namespaces()\nif _, err := nsClient.Get(ctx, namespace, metav1.GetOptions{}); err != nil {\n    return fmt.Errorf(\"namespace %q not queryable: %w\", namespace, err)\n}","typeGuard":"func isNamespaceMissing(err error) bool {\n    return apierrors.IsNotFound(err)\n}","tryCatchPattern":"v, err := ch.GetInstalledVersion(ctx, k8sClient)\nif err != nil {\n    if apierrors.IsNotFound(err) {\n        // namespace absent: treat as no installed version or create it\n        return nil, nil\n    }\n    return fmt.Errorf(\"GetInstalledVersion: %w\", err)\n}","preventionTips":["Ensure the namespace exists before channel operations (create it in setup).","Grant RBAC get permission on namespaces to the operating identity.","Verify kubeconfig context targets the intended cluster.","Add a preflight connectivity check against the API server."],"tags":["kubernetes","namespace","rbac","api-server"],"backgroundTag":"namespace-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"}