@hashgraph/solo
Version:
An opinionated CLI tool to deploy and manage private Hedera Networks.
43 lines • 1.49 kB
JavaScript
// SPDX-License-Identifier: Apache-2.0
import { CoreV1Api } from '@kubernetes/client-node';
import { NamespaceName } from '../../../../../types/namespace/namespace-name.js';
export class K8ClientContexts {
kubeConfig;
constructor(kubeConfig) {
this.kubeConfig = kubeConfig;
}
list() {
const contexts = [];
for (const context of this.kubeConfig.getContexts()) {
contexts.push(context.name);
}
return contexts;
}
readCurrent() {
return this.kubeConfig.getCurrentContext();
}
readCurrentNamespace() {
return NamespaceName.of(this.kubeConfig.getContextObject(this.readCurrent())?.namespace);
}
updateCurrent(context) {
this.kubeConfig.setCurrentContext(context);
}
async testContextConnection(context) {
const originalContextName = this.readCurrent();
this.kubeConfig.setCurrentContext(context);
const temporaryKubeClient = this.kubeConfig.makeApiClient(CoreV1Api);
try {
const result = await temporaryKubeClient.listNamespace();
if (result?.items) {
this.kubeConfig.setCurrentContext(originalContextName);
return true;
}
}
catch {
// Do nothing, we will return false at the end of the method
}
this.kubeConfig.setCurrentContext(originalContextName);
return false;
}
}
//# sourceMappingURL=k8-client-contexts.js.map