From 119402504c53a26aa56527be58bd2682df1dd67f Mon Sep 17 00:00:00 2001 From: Lenin Mehedy Date: Wed, 24 Jan 2024 17:54:46 +1100 Subject: [PATCH] fix: remove kubectl usage Signed-off-by: Lenin Mehedy --- .../src/commands/base.mjs | 2 - .../src/commands/cluster.mjs | 2 +- .../src/commands/init.mjs | 5 +- .../src/commands/relay.mjs | 14 +- .../src/core/constants.mjs | 2 +- .../src/core/dependency_manager.mjs | 9 - fullstack-network-manager/src/core/index.mjs | 2 - .../src/core/kubectl.mjs | 182 ------------------ fullstack-network-manager/src/index.mjs | 3 - .../test/e2e/commands/node.test.mjs | 3 - .../test/e2e/core/kubectl_e2e.test.mjs | 42 ++-- .../test/unit/commands/base.test.mjs | 3 - .../test/unit/commands/init.test.mjs | 5 +- .../test/unit/core/kubectl.test.mjs | 77 -------- .../unit/core/platform_installer.test.mjs | 7 +- 15 files changed, 36 insertions(+), 322 deletions(-) delete mode 100644 fullstack-network-manager/src/core/kubectl.mjs delete mode 100644 fullstack-network-manager/test/unit/core/kubectl.test.mjs diff --git a/fullstack-network-manager/src/commands/base.mjs b/fullstack-network-manager/src/commands/base.mjs index c6f24aeed..53c4c3ae9 100644 --- a/fullstack-network-manager/src/commands/base.mjs +++ b/fullstack-network-manager/src/commands/base.mjs @@ -19,7 +19,6 @@ export class BaseCommand extends ShellRunner { constructor (opts) { if (!opts || !opts.logger) throw new Error('An instance of core/Logger is required') if (!opts || !opts.helm) throw new Error('An instance of core/Helm is required') - if (!opts || !opts.kubectl) throw new Error('An instance of core/Kubectl is required') if (!opts || !opts.kubectl2) throw new Error('An instance of core/Kubectl2 is required') if (!opts || !opts.chartManager) throw new Error('An instance of core/ChartManager is required') if (!opts || !opts.configManager) throw new Error('An instance of core/ConfigManager is required') @@ -28,7 +27,6 @@ export class BaseCommand extends ShellRunner { super(opts.logger) this.helm = opts.helm - this.kubectl = opts.kubectl this.kubectl2 = opts.kubectl2 this.chartManager = opts.chartManager this.configManager = opts.configManager diff --git a/fullstack-network-manager/src/commands/cluster.mjs b/fullstack-network-manager/src/commands/cluster.mjs index b9a59b6ac..030c60f9a 100644 --- a/fullstack-network-manager/src/commands/cluster.mjs +++ b/fullstack-network-manager/src/commands/cluster.mjs @@ -230,7 +230,7 @@ export class ClusterCommand extends BaseCommand { desc: 'Setup cluster with shared components', builder: y => flags.setCommandFlags(y, flags.clusterName, - flags.withDefaultValue(flags.namespace, constants.DEFAULT_NAMESPACE), + flags.namespace, flags.chartDirectory, flags.deployPrometheusStack, flags.deployMinio, diff --git a/fullstack-network-manager/src/commands/init.mjs b/fullstack-network-manager/src/commands/init.mjs index 1c8da68df..1f61e4fd4 100644 --- a/fullstack-network-manager/src/commands/init.mjs +++ b/fullstack-network-manager/src/commands/init.mjs @@ -60,13 +60,12 @@ export class InitCommand extends BaseCommand { title: 'Check dependencies', task: async (_, task) => { const deps = [ - core.constants.HELM, - core.constants.KUBECTL + core.constants.HELM ] const subTasks = self.depManager.taskCheckDependencies(deps) - // setup the sub-tasks + // set up the sub-tasks return task.newListr(subTasks, { concurrent: true, rendererOptions: { diff --git a/fullstack-network-manager/src/commands/relay.mjs b/fullstack-network-manager/src/commands/relay.mjs index 108c4f846..872dfffdc 100644 --- a/fullstack-network-manager/src/commands/relay.mjs +++ b/fullstack-network-manager/src/commands/relay.mjs @@ -85,7 +85,7 @@ export class RelayCommand extends BaseCommand { const chartDir = self.configManager.getFlag(flags.chartDirectory) // prompt if inputs are empty and set it in the context - const namespaces = await self.kubectl.getNamespace('--no-headers', '-o name') + const namespaces = await self.kubectl2.getNamespaces() ctx.config = { chartDir: await prompts.promptChartDir(task, chartDir), namespace: await prompts.promptSelectNamespaceArg(task, namespace, namespaces), @@ -132,12 +132,10 @@ export class RelayCommand extends BaseCommand { await this.chartManager.install(namespace, releaseName, chartPath, '', valuesArg) - await this.kubectl.wait('pod', - '--for=condition=ready', - '-l app=hedera-json-rpc-relay', - `-l app.kubernetes.io/instance=${releaseName}`, - '--timeout=900s' - ) + await this.kubectl2.waitForPod(constants.POD_STATUS_READY, [ + 'app=hedera-json-rpc-relay', + `app.kubernetes.io/instance=${releaseName}` + ], 1) this.logger.showList('Deployed Relays', await self.chartManager.getInstalledCharts(namespace)) } @@ -170,7 +168,7 @@ export class RelayCommand extends BaseCommand { const namespace = self.configManager.getFlag(flags.namespace) // prompt if inputs are empty and set it in the context - const namespaces = await self.kubectl.getNamespace('--no-headers', '-o name') + const namespaces = await self.kubectl2.getNamespaces() ctx.config = { namespace: await prompts.promptSelectNamespaceArg(task, namespace, namespaces), nodeIds: await prompts.promptNodeIdsArg(task, nodeIds) diff --git a/fullstack-network-manager/src/core/constants.mjs b/fullstack-network-manager/src/core/constants.mjs index b884b7f19..a55ca9dc5 100644 --- a/fullstack-network-manager/src/core/constants.mjs +++ b/fullstack-network-manager/src/core/constants.mjs @@ -18,7 +18,6 @@ export const RELEASE_NAME = 'fst' export const NAMESPACE_NAME = `fst-${USER_SANITIZED}` export const HELM = 'helm' -export const KUBECTL = 'kubectl' export const CWD = process.cwd() export const FST_CONFIG_FILE = `${FST_HOME_DIR}/fsnetman.config` export const RESOURCES_DIR = normalize(CUR_FILE_DIR + '/../../resources') @@ -69,6 +68,7 @@ export const OPERATOR_ID = process.env.FST_OPERATOR_ID || '0.0.2' export const OPERATOR_KEY = process.env.FST_OPERATOR_KEY || '302e020100300506032b65700422042091132178e72057a1d7528025956fe39b0b847f200ab59b2fdd367017f3087137' export const POD_STATUS_RUNNING = 'Running' +export const POD_STATUS_READY = 'Ready' // Listr related export const LISTR_DEFAULT_RENDERER_TIMER_OPTION = { diff --git a/fullstack-network-manager/src/core/dependency_manager.mjs b/fullstack-network-manager/src/core/dependency_manager.mjs index 9ecc8b56a..ef90888f9 100644 --- a/fullstack-network-manager/src/core/dependency_manager.mjs +++ b/fullstack-network-manager/src/core/dependency_manager.mjs @@ -9,7 +9,6 @@ export class DependencyManager extends ShellRunner { // map of dependency checks this.checks = new Map() .set(core.constants.HELM, () => this.checkHelm()) - .set(core.constants.KUBECTL, () => this.checkKubectl()) } async runCheck (cmdString) { @@ -31,14 +30,6 @@ export class DependencyManager extends ShellRunner { return this.runCheck(`${core.constants.HELM} version`) } - /** - * Check if 'kubectl' CLI program is installed or not - * @returns {Promise} - */ - async checkKubectl () { - return this.runCheck(`${core.constants.KUBECTL} version --client`) - } - /** * Check if the required dependency is installed or not * @param dep is the name of the program diff --git a/fullstack-network-manager/src/core/index.mjs b/fullstack-network-manager/src/core/index.mjs index 57491600b..6cc6068e2 100644 --- a/fullstack-network-manager/src/core/index.mjs +++ b/fullstack-network-manager/src/core/index.mjs @@ -1,7 +1,6 @@ import * as logging from './logging.mjs' import * as constants from './constants.mjs' import { Helm } from './helm.mjs' -import { Kubectl } from './kubectl.mjs' import { Kubectl2 } from './kubectl2.mjs' import { PackageDownloader } from './package_downloader.mjs' import { PlatformInstaller } from './platform_installer.mjs' @@ -16,7 +15,6 @@ export { logging, constants, Helm, - Kubectl, Kubectl2, PackageDownloader, PlatformInstaller, diff --git a/fullstack-network-manager/src/core/kubectl.mjs b/fullstack-network-manager/src/core/kubectl.mjs deleted file mode 100644 index 479b03bca..000000000 --- a/fullstack-network-manager/src/core/kubectl.mjs +++ /dev/null @@ -1,182 +0,0 @@ -import { ShellRunner } from './shell_runner.mjs' -import { FullstackTestingError } from './errors.mjs' - -export class Kubectl extends ShellRunner { - /** - * Prepare a `kubectl` shell command string - * @param action represents a helm command (e.g. create | install | get ) - * @param args args of the command - * @returns {string} - */ - prepareCommand (action, ...args) { - let cmd = `kubectl ${action}` - args.forEach(arg => { - cmd += ` ${arg}` - }) - return cmd - } - - /** - * Invoke `kubectl create` command - * @param resource a kubernetes resource type (e.g. pod | svc etc.) - * @param args args of the command - * @returns {Promise} console output as an array of strings - */ - async create (resource, ...args) { - return this.run(this.prepareCommand('create', resource, ...args)) - } - - /** - * Invoke `kubectl create ns` command - * @param args args of the command - * @returns {Promise} console output as an array of strings - */ - async createNamespace (...args) { - return this.create('ns', ...args) - } - - /** - * Invoke `kubectl delete` command - * @param resource a kubernetes resource type (e.g. pod | svc etc.) - * @param args args of the command - * @returns {Promise} console output as an array of strings - */ - async delete (resource, ...args) { - return this.run(this.prepareCommand('delete', resource, ...args)) - } - - /** - * Invoke `kubectl delete ns` command - * @param args args of the command - * @returns {Promise} console output as an array of strings - */ - async deleteNamespace (...args) { - return this.delete('ns', ...args) - } - - /** - * Invoke `kubectl get` command - * @param resource a kubernetes resource type (e.g. pod | svc etc.) - * @param args args of the command - * @returns {Promise} console output as an array of strings - */ - async get (resource, ...args) { - return this.run(this.prepareCommand('get', resource, ...args)) - } - - /** - * Invoke `kubectl get ns` command - * @param args args of the command - * @returns {Promise} console output as an array of strings - */ - async getNamespace (...args) { - return this.get('ns', ...args) - } - - /** - * Get pod IP of a pod - * @param podName name of the pod - * @returns {Promise} console output as an array of strings - */ - async getPodIP (podName) { - try { - const output = await this.run(this.prepareCommand('get', 'pod', podName, '-o jsonpath=\'{.status.podIP}\'')) - - if (output) { - return output[0].trim() - } - } catch (e) { - throw new FullstackTestingError(`error on detecting IP for pod ${podName}`, e) - } - - throw new FullstackTestingError(`No resource found for ${podName}`) - } - - /** - * Get cluster IP of a service - * @param svcName name of the service - * @returns {Promise} console output as an array of strings - */ - async getClusterIP (svcName) { - try { - const output = await this.run(this.prepareCommand('get', 'svc', svcName, '-o jsonpath=\'{.spec.clusterIP}\'')) - if (output) { - return output[0].trim() - } - } catch (e) { - throw new FullstackTestingError(`error on detecting cluster IP for svc ${svcName}`, e) - } - - throw new FullstackTestingError(`No resource found for ${svcName}`) - } - - /** - * Invoke `kubectl wait` command - * @param resource a kubernetes resource type (e.g. pod | svc etc.) - * @param args args of the command - * @returns {Promise} console output as an array of strings - */ - async wait (resource, ...args) { - return this.run(this.prepareCommand('wait', resource, ...args)) - } - - /** - * Invoke `kubectl exec` command - * @param pod a kubernetes pod name - * @param args args of the command - * @returns {Promise} console output as an array of strings - */ - async exec (pod, ...args) { - return this.run(this.prepareCommand('exec', pod, ...args)) - } - - /** - * Invoke bash command within a container - * @param pod a kubernetes pod name - * @param container name of the container within the pod - * @param bashScript bash script to be run within the container (e.g 'ls -la /opt/hgcapp') - * @returns {Promise} console output as an array of strings - */ - async execContainer (pod, container, bashScript) { - return this.exec(pod, `-c ${container}`, `-- bash -c "${bashScript}"`) - } - - /** - * Invoke `kubectl cp` command - * @param pod a kubernetes pod name - * @param args args of the command - * @returns {Promise} console output as an array of strings - */ - async copy (...args) { - return this.run(this.prepareCommand('cp', ...args)) - } - - /** - * Invoke `kubectl config` command - * @param args args of the command - * @returns {Promise} console output as an array of strings - */ - async config (...args) { - return this.run(this.prepareCommand('config', ...args)) - } - - /** - * Invoke `kubectl port-forward svc/` command - * @param resource name of the service or pod. Must be of the format pod/ or svc/ - * @param localPort port of the host machine - * @param remotePort port to be forwarded from the service or pod - * @returns {Promise} console output as an array of strings - */ - async portForward (resource, localPort, remotePort) { - return this.run(this.prepareCommand(`port-forward ${resource} ${localPort}:${remotePort} &`)) - } - - /** - * Invoke `kubectl cluster-info` command - * @param args list of args for cluster-info command - * @returns {Promise} - */ - async clusterInfo (...args) { - return this.run(this.prepareCommand('cluster-info', ...args)) - } -} diff --git a/fullstack-network-manager/src/index.mjs b/fullstack-network-manager/src/index.mjs index c39c09325..a5e2ec799 100644 --- a/fullstack-network-manager/src/index.mjs +++ b/fullstack-network-manager/src/index.mjs @@ -10,7 +10,6 @@ import { PackageDownloader, PlatformInstaller, Helm, - Kubectl, logging } from './core/index.mjs' import 'dotenv/config' @@ -21,7 +20,6 @@ export function main (argv) { try { const helm = new Helm(logger) - const kubectl = new Kubectl(logger) const downloader = new PackageDownloader(logger) const chartManager = new ChartManager(helm, logger) const configManager = new ConfigManager(logger) @@ -50,7 +48,6 @@ export function main (argv) { const opts = { logger, helm, - kubectl, kubectl2, downloader, platformInstaller, diff --git a/fullstack-network-manager/test/e2e/commands/node.test.mjs b/fullstack-network-manager/test/e2e/commands/node.test.mjs index 6d67f1205..efc8f5201 100644 --- a/fullstack-network-manager/test/e2e/commands/node.test.mjs +++ b/fullstack-network-manager/test/e2e/commands/node.test.mjs @@ -17,7 +17,6 @@ import { ChartManager, ConfigManager, Helm, - Kubectl, Kubectl2, PackageDownloader, PlatformInstaller, @@ -92,7 +91,6 @@ class TestHelper { describe('NodeCommand', () => { const helm = new Helm(testLogger) - const kubectl = new Kubectl(testLogger) const chartManager = new ChartManager(helm, testLogger) const configManager = new ConfigManager(testLogger) const packageDownloader = new PackageDownloader(testLogger) @@ -103,7 +101,6 @@ describe('NodeCommand', () => { const nodeCmd = new NodeCommand({ logger: testLogger, helm, - kubectl, kubectl2, chartManager, configManager, diff --git a/fullstack-network-manager/test/e2e/core/kubectl_e2e.test.mjs b/fullstack-network-manager/test/e2e/core/kubectl_e2e.test.mjs index a2037d3ef..cc9314070 100644 --- a/fullstack-network-manager/test/e2e/core/kubectl_e2e.test.mjs +++ b/fullstack-network-manager/test/e2e/core/kubectl_e2e.test.mjs @@ -6,53 +6,53 @@ import path from 'path' import { v4 as uuid4 } from 'uuid' import { FullstackTestingError } from '../../../src/core/errors.mjs' import { ConfigManager, constants, logging, PackageDownloader, Templates } from '../../../src/core/index.mjs' -import { Kubectl2 } from '../../../src/core/kubectl2.mjs' +import { Kubectl2 } from '../../../src/core/kubectl22.mjs' describe('Kubectl', () => { const testLogger = logging.NewLogger('debug') const configManager = new ConfigManager(testLogger) - const kubectl = new Kubectl2(configManager, testLogger) + const kubectl2 = new Kubectl2(configManager, testLogger) const downloader = new PackageDownloader(testLogger) it('should be able to list clusters', async () => { - const clusters = await kubectl.getClusters() + const clusters = await kubectl2.getClusters() expect(clusters).not.toHaveLength(0) expect(clusters).toContain(constants.CLUSTER_NAME) }) it('should be able to list namespaces', async () => { - const namespaces = await kubectl.getNamespaces() + const namespaces = await kubectl2.getNamespaces() expect(namespaces).not.toHaveLength(0) expect(namespaces).toContain(constants.DEFAULT_NAMESPACE) }) it('should be able to list contexts', async () => { - const contexts = await kubectl.getContexts() + const contexts = await kubectl2.getContexts() expect(contexts).not.toHaveLength(0) expect(contexts).toContain(constants.CONTEXT_NAME) }) it('should be able to create and delete a namespaces', async () => { const name = uuid4() - await expect(kubectl.createNamespace(name)).resolves.toBeTruthy() - await expect(kubectl.deleteNamespace(name)).resolves.toBeTruthy() + await expect(kubectl2.createNamespace(name)).resolves.toBeTruthy() + await expect(kubectl2.deleteNamespace(name)).resolves.toBeTruthy() }) it('should be able to detect pod IP of a pod', async () => { const podName = Templates.renderNetworkPodName('node0') - await expect(kubectl.getPodIP(podName)).resolves.not.toBeNull() - await expect(kubectl.getPodIP('INVALID')).rejects.toThrow(FullstackTestingError) + await expect(kubectl2.getPodIP(podName)).resolves.not.toBeNull() + await expect(kubectl2.getPodIP('INVALID')).rejects.toThrow(FullstackTestingError) }) it('should be able to detect cluster IP', async () => { const svcName = Templates.renderNetworkSvcName('node0') - await expect(kubectl.getClusterIP(svcName)).resolves.not.toBeNull() - await expect(kubectl.getClusterIP('INVALID')).rejects.toThrow(FullstackTestingError) + await expect(kubectl2.getClusterIP(svcName)).resolves.not.toBeNull() + await expect(kubectl2.getClusterIP('INVALID')).rejects.toThrow(FullstackTestingError) }) it('should be able to check if a path is directory inside a container', async () => { const podName = Templates.renderNetworkPodName('node0') - await expect(kubectl.hasDir(podName, constants.ROOT_CONTAINER, constants.HEDERA_USER_HOME_DIR)).resolves.toBeTruthy() + await expect(kubectl2.hasDir(podName, constants.ROOT_CONTAINER, constants.HEDERA_USER_HOME_DIR)).resolves.toBeTruthy() }) it('should be able to copy a file to and from a container', async () => { @@ -67,18 +67,18 @@ describe('Kubectl', () => { await expect(downloader.fetchPlatform(tag, testCacheDir)).resolves.toBe(pkgPath) expect(fs.existsSync(pkgPath)).toBeTruthy() - const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'kubectl-')) + const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'kubectl2-')) const destDir = constants.HEDERA_USER_HOME_DIR const destPath = `${destDir}/build-${tag}.zip` // upload the file - await expect(kubectl.copyTo(podName, containerName, pkgPath, destDir)).resolves.toBeTruthy() + await expect(kubectl2.copyTo(podName, containerName, pkgPath, destDir)).resolves.toBeTruthy() // download the same file - await expect(kubectl.copyFrom(podName, containerName, destPath, tmpDir)).resolves.toBeTruthy() + await expect(kubectl2.copyFrom(podName, containerName, destPath, tmpDir)).resolves.toBeTruthy() // rm file inside the container - await expect(kubectl.execContainer(podName, containerName, ['rm', '-f', destPath])).resolves + await expect(kubectl2.execContainer(podName, containerName, ['rm', '-f', destPath])).resolves fs.rmdirSync(tmpDir, { recursive: true }) }, 50000) @@ -86,7 +86,7 @@ describe('Kubectl', () => { it('should be able to port forward gossip port', (done) => { const podName = Templates.renderNetworkPodName('node0') const localPort = constants.HEDERA_NODE_INTERNAL_GOSSIP_PORT - kubectl.portForward(podName, localPort, constants.HEDERA_NODE_INTERNAL_GOSSIP_PORT).then((server) => { + kubectl2.portForward(podName, localPort, constants.HEDERA_NODE_INTERNAL_GOSSIP_PORT).then((server) => { expect(server).not.toBeNull() // client @@ -114,21 +114,21 @@ describe('Kubectl', () => { `fullstack.hedera.com/node-name=${nodeId}` ] - await expect(kubectl.waitForPod(constants.POD_STATUS_RUNNING, labels)).resolves.toBeTruthy() + await expect(kubectl2.waitForPod(constants.POD_STATUS_RUNNING, labels)).resolves.toBeTruthy() }) it('should be able to cat a log file inside the container', async () => { const podName = Templates.renderNetworkPodName('node0') const containerName = constants.ROOT_CONTAINER const testFileName = 'test.txt' - const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'kubectl-')) + const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'kubectl2-')) const tmpFile = path.join(tmpDir, testFileName) const destDir = constants.HEDERA_USER_HOME_DIR const destPath = `${destDir}/${testFileName}` fs.writeFileSync(tmpFile, 'TEST\nNow current platform status = ACTIVE') - await expect(kubectl.copyTo(podName, containerName, tmpFile, destDir)).resolves.toBeTruthy() - const output = await kubectl.execContainer(podName, containerName, ['tail', '-10', destPath]) + await expect(kubectl2.copyTo(podName, containerName, tmpFile, destDir)).resolves.toBeTruthy() + const output = await kubectl2.execContainer(podName, containerName, ['tail', '-10', destPath]) expect(output.indexOf('Now current platform status = ACTIVE')).toBeGreaterThan(0) fs.rmdirSync(tmpDir, { recursive: true }) diff --git a/fullstack-network-manager/test/unit/commands/base.test.mjs b/fullstack-network-manager/test/unit/commands/base.test.mjs index d9c106a0f..56599f8fa 100644 --- a/fullstack-network-manager/test/unit/commands/base.test.mjs +++ b/fullstack-network-manager/test/unit/commands/base.test.mjs @@ -4,7 +4,6 @@ import { ChartManager, ConfigManager, Helm, - Kubectl, logging } from '../../../src/core/index.mjs' import { BaseCommand } from '../../../src/commands/base.mjs' @@ -14,7 +13,6 @@ const testLogger = logging.NewLogger('debug') describe('BaseCommand', () => { const helm = new Helm(testLogger) - const kubectl = new Kubectl(testLogger) const chartManager = new ChartManager(helm, testLogger) const configManager = new ConfigManager(testLogger) const depManager = new DependencyManager(testLogger) @@ -23,7 +21,6 @@ describe('BaseCommand', () => { const baseCmd = new BaseCommand({ logger: testLogger, helm, - kubectl, kubectl2, chartManager, configManager, diff --git a/fullstack-network-manager/test/unit/commands/init.test.mjs b/fullstack-network-manager/test/unit/commands/init.test.mjs index fcbe8749c..43ac9724d 100644 --- a/fullstack-network-manager/test/unit/commands/init.test.mjs +++ b/fullstack-network-manager/test/unit/commands/init.test.mjs @@ -5,15 +5,13 @@ import { ChartManager, ConfigManager, DependencyManager, - Helm, - Kubectl + Helm } from '../../../src/core/index.mjs' import { Kubectl2 } from '../../../src/core/kubectl2.mjs' const testLogger = core.logging.NewLogger('debug') describe('InitCommand', () => { const helm = new Helm(testLogger) - const kubectl = new Kubectl(testLogger) const chartManager = new ChartManager(helm, testLogger) const configManager = new ConfigManager(testLogger) const depManager = new DependencyManager(testLogger) @@ -22,7 +20,6 @@ describe('InitCommand', () => { const initCmd = new InitCommand({ logger: testLogger, helm, - kubectl, kubectl2, chartManager, configManager, diff --git a/fullstack-network-manager/test/unit/core/kubectl.test.mjs b/fullstack-network-manager/test/unit/core/kubectl.test.mjs deleted file mode 100644 index f42b34e75..000000000 --- a/fullstack-network-manager/test/unit/core/kubectl.test.mjs +++ /dev/null @@ -1,77 +0,0 @@ -import { describe, expect, it, jest } from '@jest/globals' -import { Kubectl, logging } from '../../../src/core/index.mjs' -import { ShellRunner } from '../../../src/core/shell_runner.mjs' -import { FullstackTestingError } from '../../../src/core/errors.mjs' - -describe('Kubectl', () => { - const logger = logging.NewLogger('debug') - const kubectl = new Kubectl(logger) - const shellSpy = jest.spyOn(ShellRunner.prototype, 'run').mockImplementation() - - it('should run kubectl create', async () => { - await kubectl.create('resource', 'arg') - expect(shellSpy).toHaveBeenCalledWith('kubectl create resource arg') - }) - - it('should run kubectl create ns', async () => { - await kubectl.createNamespace('namespace') - expect(shellSpy).toHaveBeenCalledWith('kubectl create ns namespace') - }) - - it('should run kubectl delete', async () => { - await kubectl.delete('resource', 'arg') - expect(shellSpy).toHaveBeenCalledWith('kubectl delete resource arg') - }) - - it('should run kubectl delete ns', async () => { - await kubectl.deleteNamespace('namespace') - expect(shellSpy).toHaveBeenCalledWith('kubectl delete ns namespace') - }) - - it('should run kubectl get', async () => { - await kubectl.get('resource', 'arg') - expect(shellSpy).toHaveBeenCalledWith('kubectl get resource arg') - }) - - it('should run kubectl get ns', async () => { - await kubectl.getNamespace('namespace') - expect(shellSpy).toHaveBeenCalledWith('kubectl get ns namespace') - }) - - it('should get IP of a pod', async () => { - await expect(kubectl.getPodIP('podName')).rejects.toThrow(FullstackTestingError) - expect(shellSpy).toHaveBeenCalledWith('kubectl get pod podName -o jsonpath=\'{.status.podIP}\'') - }) - - it('should get cluster IP of a service', async () => { - await expect(kubectl.getClusterIP('svcName')).rejects.toThrow(FullstackTestingError) - expect(shellSpy).toHaveBeenCalledWith('kubectl get svc svcName -o jsonpath=\'{.spec.clusterIP}\'') - }) - - it('should run kubectl wait', async () => { - await kubectl.wait('resource', 'arg') - expect(shellSpy).toHaveBeenCalledWith('kubectl wait resource arg') - }) - - it('should run kubectl exec', async () => { - await kubectl.exec('pod', 'arg') - expect(shellSpy).toHaveBeenCalledWith('kubectl exec pod arg') - }) - - it('should invoke bash command within a container', async () => { - await kubectl.execContainer('pod', 'container', 'make dir -p test') - expect(shellSpy).toHaveBeenCalledWith('kubectl exec pod -c container -- bash -c "make dir -p test"') - }) - - it('should run kubectl cp', async () => { - await kubectl.copy('from', 'to', '-c root-container') - expect(shellSpy).toHaveBeenCalledWith('kubectl cp from to -c root-container') - }) - - it('should run kubectl config', async () => { - await kubectl.config('set-context --current --namespace=test') - expect(shellSpy).toHaveBeenCalledWith('kubectl config set-context --current --namespace=test') - }) - - shellSpy.mockClear() -}) diff --git a/fullstack-network-manager/test/unit/core/platform_installer.test.mjs b/fullstack-network-manager/test/unit/core/platform_installer.test.mjs index e0ec7c4ce..e59df0633 100644 --- a/fullstack-network-manager/test/unit/core/platform_installer.test.mjs +++ b/fullstack-network-manager/test/unit/core/platform_installer.test.mjs @@ -1,6 +1,6 @@ import { describe, expect, it } from '@jest/globals' import * as core from '../../../src/core/index.mjs' -import { PlatformInstaller } from '../../../src/core/index.mjs' +import { ConfigManager, PlatformInstaller } from '../../../src/core/index.mjs' import * as fs from 'fs' import * as path from 'path' import * as os from 'os' @@ -10,8 +10,9 @@ import { } from '../../../src/core/errors.mjs' describe('PackageInstaller', () => { const testLogger = core.logging.NewLogger('debug') - const kubectl = new core.Kubectl(testLogger) - const installer = new PlatformInstaller(testLogger, kubectl) + const configManager = new ConfigManager(testLogger) + const kubectl2 = new core.Kubectl2(configManager, testLogger) + const installer = new PlatformInstaller(testLogger, kubectl2) describe('validatePlatformReleaseDir', () => { it('should fail for missing path', async () => {