import fs from 'fs'; import { isInCluster } from './_k8s'; const LOCAL_NAMESPACE = 'local'; class NamespaceCache { cache?: string; get() { if (!isInCluster()) { return LOCAL_NAMESPACE; } if (!this.cache) { try { const data = fs.readFileSync( '/var/run/secrets/kubernetes.io/serviceaccount/namespace', 'utf8', ); this.cache = data; } catch (err) { console.error(err); } } return this.cache; } } const namespace = new NamespaceCache(); export default namespace;