deno-kubernetes_apis icon indicating copy to clipboard operation
deno-kubernetes_apis copied to clipboard

getConfigMap is not a function

Open scott4dev opened this issue 1 year ago • 1 comments
trafficstars

Hi,

I'm trying to run this code

import { autoDetectClient, readAllItems, Reflector} from "https://deno.land/x/[email protected]/mod.ts";
import { CoreV1Api } from 'https://deno.land/x/kubernetes_apis/builtin/core@v1/mod.ts';

const client = await autoDetectClient();
const coreApi = new CoreV1Api(client);

await coreApi.getConfigMap("cluster-info");

but I get this error

error: Uncaught (in promise) TypeError: coreApi.getConfigMap is not a function
await coreApi.getConfigMap("cluster-info");

Could this be related to the fact that on deno.land/x the latest version is 0.5? https://deno.land/x/[email protected]/builtin/core@v1/mod.ts

scott4dev avatar Apr 03 '24 15:04 scott4dev

Hello, it looks like you are interacting with CoreV1Api when you expect to have a CoreV1NamespacedApi instead. This is important when working with any namespaced resource.

You can select either the default namespace (from kubeconfig, or based on the pod when running in-cluster):

await coreApi.myNamespace().getConfigMap("cluster-info");

Or you can name a particular namespace:

await coreApi.namespace("kube-public").getConfigMap("cluster-info");

If you're only working with one particular namespace, you may find it cleaner to change the declaration of coreApi instead:

const client = await autoDetectClient();
const coreApi = new CoreV1Api(client).namespace("kube-public");

await coreApi.getConfigMap("cluster-info");

Hope this helps

danopia avatar Apr 04 '24 08:04 danopia

Closing for inactivity. Feel free to comment still if you have further concerns with this.

danopia avatar Sep 05 '24 22:09 danopia