Skip to content

Commit

Permalink
fix: rename Kubectl2 to K8
Browse files Browse the repository at this point in the history
Signed-off-by: Lenin Mehedy <lenin.mehedy@swirldslabs.com>
  • Loading branch information
leninmehedy committed Jan 24, 2024
1 parent acd277f commit a911703
Show file tree
Hide file tree
Showing 18 changed files with 86 additions and 99 deletions.
7 changes: 0 additions & 7 deletions fullstack-network-manager/resources/dev-cluster.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions fullstack-network-manager/src/commands/base.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ 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.kubectl2) throw new Error('An instance of core/Kubectl2 is required')
if (!opts || !opts.k8) throw new Error('An instance of core/K8 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')
if (!opts || !opts.depManager) throw new Error('An instance of core/DependencyManager is required')

super(opts.logger)

this.helm = opts.helm
this.kubectl2 = opts.kubectl2
this.k8 = opts.k8
this.chartManager = opts.chartManager
this.configManager = opts.configManager
this.depManager = opts.depManager
Expand Down
6 changes: 3 additions & 3 deletions fullstack-network-manager/src/commands/chart.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export class ChartCommand extends BaseCommand {
config.enableTls, config.tlsClusterIssuerName, config.tlsClusterIssuerNamespace, config.enableHederaExplorerTls,
config.acmeClusterIssuer, config.selfSignedClusterIssuer)

if (!await this.kubectl2.hasNamespace(config.namespace)) {
if (!await this.k8.hasNamespace(config.namespace)) {
throw new FullstackTestingError(`namespace ${config.namespace} does not exist`)
}

Expand Down Expand Up @@ -137,7 +137,7 @@ export class ChartCommand extends BaseCommand {
subTasks.push({
title: `Node: ${chalk.yellow(nodeId)} (Pod: ${podName})`,
task: () =>
self.kubectl2.waitForPod(constants.POD_STATUS_RUNNING, [
self.k8.waitForPod(constants.POD_STATUS_RUNNING, [
'fullstack.hedera.com/type=network-node',
`fullstack.hedera.com/node-name=${nodeId}`
], 1, 60 * 15, 1000) // timeout 15 minutes
Expand Down Expand Up @@ -224,7 +224,7 @@ export class ChartCommand extends BaseCommand {
{
title: 'Waiting for network pods to be ready',
task: async (ctx, _) => {
await this.kubectl2.waitForPod(constants.POD_STATUS_RUNNING, [
await this.k8.waitForPod(constants.POD_STATUS_RUNNING, [
'fullstack.hedera.com/type=network-node'
], 1)
}
Expand Down
4 changes: 2 additions & 2 deletions fullstack-network-manager/src/commands/cluster.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as prompts from './prompts.mjs'
*/
export class ClusterCommand extends BaseCommand {
async showClusterList () {
this.logger.showList('Clusters', await this.kubectl2.getClusters())
this.logger.showList('Clusters', await this.k8.getClusters())
return true
}

Expand All @@ -21,7 +21,7 @@ export class ClusterCommand extends BaseCommand {
*/
async getClusterInfo () {
try {
const cluster = this.kubectl2.getKubeConfig().getCurrentCluster()
const cluster = this.k8.getKubeConfig().getCurrentCluster()
this.logger.showJSON(`Cluster Information (${cluster.name})`, cluster)
this.logger.showUser('\n')
return true
Expand Down
24 changes: 12 additions & 12 deletions fullstack-network-manager/src/commands/node.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class NodeCommand extends BaseCommand {
const podName = Templates.renderNetworkPodName(nodeId)

try {
await this.kubectl2.waitForPod(constants.POD_STATUS_RUNNING, [
await this.k8.waitForPod(constants.POD_STATUS_RUNNING, [
'fullstack.hedera.com/type=network-node',
`fullstack.hedera.com/node-name=${nodeId}`
], 1)
Expand All @@ -47,7 +47,7 @@ export class NodeCommand extends BaseCommand {

while (attempt < maxAttempt) {
try {
const output = await this.kubectl2.execContainer(podName, constants.ROOT_CONTAINER, ['tail', '-10', logfilePath])
const output = await this.k8.execContainer(podName, constants.ROOT_CONTAINER, ['tail', '-10', logfilePath])
if (output.indexOf(`Now current platform status = ${status}`) > 0) {
this.logger.debug(`Node ${nodeId} is ${status} [ attempt: ${attempt}/${maxAttempt}]`)
isActive = true
Expand All @@ -58,10 +58,10 @@ export class NodeCommand extends BaseCommand {
this.logger.warn(`error in checking if node ${nodeId} is ${status}: ${e.message}. Trying again... [ attempt: ${attempt}/${maxAttempt} ]`)

// ls the HAPI path for debugging
await this.kubectl2.execContainer(podName, constants.ROOT_CONTAINER, `ls -la ${constants.HEDERA_HAPI_PATH}`)
await this.k8.execContainer(podName, constants.ROOT_CONTAINER, `ls -la ${constants.HEDERA_HAPI_PATH}`)

// ls the logs directory for debugging
await this.kubectl2.execContainer(podName, constants.ROOT_CONTAINER, `ls -la ${constants.HEDERA_HAPI_PATH}/logs`)
await this.k8.execContainer(podName, constants.ROOT_CONTAINER, `ls -la ${constants.HEDERA_HAPI_PATH}/logs`)
}
attempt += 1
await sleep(1000)
Expand Down Expand Up @@ -112,7 +112,7 @@ export class NodeCommand extends BaseCommand {
task: async (ctx, task) => {
self.configManager.load(argv)
const namespace = self.configManager.getFlag(flags.namespace)
const namespaces = await self.kubectl2.getNamespaces()
const namespaces = await self.k8.getNamespaces()

const config = {
namespace: await prompts.promptSelectNamespaceArg(task, namespace, namespaces),
Expand All @@ -123,7 +123,7 @@ export class NodeCommand extends BaseCommand {
chainId: await prompts.promptChainId(task, argv.chainId)
}

if (!await this.kubectl2.hasNamespace(config.namespace)) {
if (!await this.k8.hasNamespace(config.namespace)) {
throw new FullstackTestingError(`namespace ${config.namespace} does not exist`)
}

Expand Down Expand Up @@ -238,14 +238,14 @@ export class NodeCommand extends BaseCommand {
self.configManager.load(argv)

const namespace = self.configManager.getFlag(flags.namespace)
const namespaces = await self.kubectl2.getNamespaces()
const namespaces = await self.k8.getNamespaces()

ctx.config = {
namespace: await prompts.promptSelectNamespaceArg(task, namespace, namespaces),
nodeIds: await prompts.promptNodeIdsArg(task, argv.nodeIds)
}

if (!await this.kubectl2.hasNamespace(ctx.config.namespace)) {
if (!await this.k8.hasNamespace(ctx.config.namespace)) {
throw new FullstackTestingError(`namespace ${ctx.config.namespace} does not exist`)
}
}
Expand All @@ -262,7 +262,7 @@ export class NodeCommand extends BaseCommand {
const podName = ctx.config.podNames[nodeId]
subTasks.push({
title: `Start node: ${chalk.yellow(nodeId)}`,
task: () => self.kubectl2.execContainer(podName, constants.ROOT_CONTAINER, ['systemctl', 'restart', 'network-node'])
task: () => self.k8.execContainer(podName, constants.ROOT_CONTAINER, ['systemctl', 'restart', 'network-node'])
})
}

Expand Down Expand Up @@ -321,13 +321,13 @@ export class NodeCommand extends BaseCommand {
const namespace = self.configManager.getFlag(flags.namespace)

// get existing choices
const namespaces = await self.kubectl2.getNamespaces()
const namespaces = await self.k8.getNamespaces()
ctx.config = {
namespace: await prompts.promptSelectNamespaceArg(task, namespace, namespaces),
nodeIds: await prompts.promptNodeIdsArg(task, argv.nodeIds)
}

if (!await this.kubectl2.hasNamespace(ctx.config.namespace)) {
if (!await this.k8.hasNamespace(ctx.config.namespace)) {
throw new FullstackTestingError(`namespace ${ctx.config.namespace} does not exist`)
}
}
Expand All @@ -344,7 +344,7 @@ export class NodeCommand extends BaseCommand {
const podName = ctx.config.podNames[nodeId]
subTasks.push({
title: `Stop node: ${chalk.yellow(nodeId)}`,
task: () => self.kubectl2.execContainer(podName, constants.ROOT_CONTAINER, 'systemctl stop network-node')
task: () => self.k8.execContainer(podName, constants.ROOT_CONTAINER, 'systemctl stop network-node')
})
}

Expand Down
6 changes: 3 additions & 3 deletions fullstack-network-manager/src/commands/relay.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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.kubectl2.getNamespaces()
const namespaces = await self.k8.getNamespaces()
ctx.config = {
chartDir: await prompts.promptChartDir(task, chartDir),
namespace: await prompts.promptSelectNamespaceArg(task, namespace, namespaces),
Expand Down Expand Up @@ -131,7 +131,7 @@ export class RelayCommand extends BaseCommand {

await this.chartManager.install(namespace, releaseName, chartPath, '', valuesArg)

await this.kubectl2.waitForPod(constants.POD_STATUS_RUNNING, [
await this.k8.waitForPod(constants.POD_STATUS_RUNNING, [
'app=hedera-json-rpc-relay',
`app.kubernetes.io/instance=${releaseName}`
], 1, 120, 1000)
Expand Down Expand Up @@ -167,7 +167,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.kubectl2.getNamespaces()
const namespaces = await self.k8.getNamespaces()
ctx.config = {
namespace: await prompts.promptSelectNamespaceArg(task, namespace, namespaces),
nodeIds: await prompts.promptNodeIdsArg(task, nodeIds)
Expand Down
2 changes: 0 additions & 2 deletions fullstack-network-manager/src/core/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ export const USER_SANITIZED = USER.replace(/[\W_]+/g, '-')
export const FST_HOME_DIR = `${process.env.HOME}/.fsnetman`
export const FST_LOGS_DIR = `${FST_HOME_DIR}/logs`
export const FST_CACHE_DIR = `${FST_HOME_DIR}/cache`
export const CLUSTER_NAME = 'kind-fst' // since by default we use kind to create cluster we use 'kind-' prefix
export const CONTEXT_NAME = CLUSTER_NAME // since by default we use kind to create cluster we use 'kind-' prefix
export const DEFAULT_NAMESPACE = 'default'
export const RELEASE_NAME = 'fst'
export const NAMESPACE_NAME = `fst-${USER_SANITIZED}`
Expand Down
4 changes: 2 additions & 2 deletions fullstack-network-manager/src/core/index.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as logging from './logging.mjs'
import * as constants from './constants.mjs'
import { Helm } from './helm.mjs'
import { Kubectl2 } from './kubectl2.mjs'
import { K8 } from './k8.mjs'
import { PackageDownloader } from './package_downloader.mjs'
import { PlatformInstaller } from './platform_installer.mjs'
import { Zippy } from './zippy.mjs'
Expand All @@ -15,7 +15,7 @@ export {
logging,
constants,
Helm,
Kubectl2,
K8,
PackageDownloader,
PlatformInstaller,
Zippy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { v4 as uuid4 } from 'uuid'
* Note: Take care if the same instance is used for parallel execution, as the behaviour may be unpredictable.
* For parallel execution, create separate instances by invoking clone()
*/
export class Kubectl2 {
export class K8 {
constructor (configManager, logger) {
if (!configManager) throw new MissingArgumentError('An instance of core/ConfigManager is required')
if (!logger) throw new MissingArgumentError('An instance of core/Logger is required')
Expand All @@ -30,10 +30,10 @@ export class Kubectl2 {
* Clone a new instance with the same config manager and logger
* Internally it instantiates a new kube API client
*
* @return {Kubectl2}
* @return {K8}
*/
clone () {
const c = new Kubectl2(this.configManager, this.logger)
const c = new K8(this.configManager, this.logger)
return c.init()
}

Expand Down
26 changes: 13 additions & 13 deletions fullstack-network-manager/src/core/platform_installer.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@ import { Templates } from './templates.mjs'
* PlatformInstaller install platform code in the root-container of a network pod
*/
export class PlatformInstaller {
constructor (logger, kubectl2) {
constructor (logger, k8) {
if (!logger) throw new MissingArgumentError('an instance of core/Logger is required')
if (!kubectl2) throw new MissingArgumentError('an instance of core/Kubectl2 is required')
if (!k8) throw new MissingArgumentError('an instance of core/K8 is required')

this.logger = logger
this.kubectl2 = kubectl2
this.k8 = k8
}

async setupHapiDirectories (podName, containerName = constants.ROOT_CONTAINER) {
if (!podName) throw new MissingArgumentError('podName is required')

try {
// reset HAPI_PATH
await this.kubectl2.execContainer(podName, containerName, `rm -rf ${constants.HEDERA_SERVICES_PATH}`)
await this.k8.execContainer(podName, containerName, `rm -rf ${constants.HEDERA_SERVICES_PATH}`)

const paths = [
`${constants.HEDERA_HAPI_PATH}/data/keys`,
`${constants.HEDERA_HAPI_PATH}/data/config`
]

for (const p of paths) {
await this.kubectl2.execContainer(podName, containerName, `mkdir -p ${p}`)
await this.k8.execContainer(podName, containerName, `mkdir -p ${p}`)
}

await this.setPathPermission(podName, constants.HEDERA_SERVICES_PATH)
Expand Down Expand Up @@ -103,9 +103,9 @@ export class PlatformInstaller {

try {
await this.copyFiles(podName, [extractScriptSrc], constants.HEDERA_USER_HOME_DIR)
await this.kubectl2.execContainer(podName, constants.ROOT_CONTAINER, `chmod +x ${extractScript}`)
await this.k8.execContainer(podName, constants.ROOT_CONTAINER, `chmod +x ${extractScript}`)
await this.setupHapiDirectories(podName)
await this.kubectl2.execContainer(podName, constants.ROOT_CONTAINER, [extractScript, buildZip, constants.HEDERA_HAPI_PATH])
await this.k8.execContainer(podName, constants.ROOT_CONTAINER, [extractScript, buildZip, constants.HEDERA_HAPI_PATH])

return true
} catch (e) {
Expand All @@ -118,10 +118,10 @@ export class PlatformInstaller {
try {
for (const srcPath of srcFiles) {
self.logger.debug(`Copying file into ${podName}: ${srcPath} -> ${destDir}`)
await this.kubectl2.copyTo(podName, container, srcPath, destDir)
await this.k8.copyTo(podName, container, srcPath, destDir)
}

const fileList = await this.kubectl2.execContainer(podName, container, `ls ${destDir}`)
const fileList = await this.k8.execContainer(podName, container, `ls ${destDir}`)

// create full path
if (fileList) {
Expand Down Expand Up @@ -213,8 +213,8 @@ export class PlatformInstaller {

try {
const recursiveFlag = recursive ? '-R' : ''
await this.kubectl2.execContainer(podName, container, `chown ${recursiveFlag} hedera:hedera ${destPath}`)
await this.kubectl2.execContainer(podName, container, `chmod ${recursiveFlag} ${mode} ${destPath}`)
await this.k8.execContainer(podName, container, `chown ${recursiveFlag} hedera:hedera ${destPath}`)
await this.k8.execContainer(podName, container, `chmod ${recursiveFlag} ${mode} ${destPath}`)
return true
} catch (e) {
throw new FullstackTestingError(`failed to set permission in '${podName}': ${destPath}`, e)
Expand Down Expand Up @@ -286,8 +286,8 @@ export class PlatformInstaller {
const nodeName = nodeId
const nodeNickName = nodeId

const internalIP = await self.kubectl2.getPodIP(podName)
const externalIP = await self.kubectl2.getClusterIP(svcName)
const internalIP = await self.k8.getPodIP(podName)
const externalIP = await self.k8.getClusterIP(svcName)

const account = `${accountIdPrefix}.${accountIdSeq}`
if (minorVersion >= 40) {
Expand Down
10 changes: 5 additions & 5 deletions fullstack-network-manager/src/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
logging
} from './core/index.mjs'
import 'dotenv/config'
import { Kubectl2 } from './core/kubectl2.mjs'
import { K8 } from './core/k8.mjs'

export function main (argv) {
const logger = logging.NewLogger('debug')
Expand All @@ -24,12 +24,12 @@ export function main (argv) {
const chartManager = new ChartManager(helm, logger)
const configManager = new ConfigManager(logger)
const depManager = new DependencyManager(logger)
const kubectl2 = new Kubectl2(configManager, logger)
const platformInstaller = new PlatformInstaller(logger, kubectl2)
const k8 = new K8(configManager, logger)
const platformInstaller = new PlatformInstaller(logger, k8)

// set cluster and namespace in the global configManager from kubernetes context
// so that we don't need to prompt the user
const kubeConfig = kubectl2.getKubeConfig()
const kubeConfig = k8.getKubeConfig()
const context = kubeConfig.getContextObject(kubeConfig.getCurrentContext())
const cluster = kubeConfig.getCurrentCluster()
configManager.setFlag(flags.clusterName, cluster.name)
Expand All @@ -48,7 +48,7 @@ export function main (argv) {
const opts = {
logger,
helm,
kubectl2,
k8,
downloader,
platformInstaller,
chartManager,
Expand Down
10 changes: 5 additions & 5 deletions fullstack-network-manager/test/e2e/commands/node.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
ChartManager,
ConfigManager,
Helm,
Kubectl2,
K8,
PackageDownloader,
PlatformInstaller,
constants,
Expand Down Expand Up @@ -51,7 +51,7 @@ class TestHelper {
for (let nodeId of nodeIds) {
nodeId = nodeId.trim()
const podName = Templates.renderNetworkPodName(nodeId)
const server = await nodeCmd.kubectl2.portForward(podName, localPort, grpcPort)
const server = await nodeCmd.k8.portForward(podName, localPort, grpcPort)
TestHelper.portForwards.push(server)

// check if the port is actually accessible
Expand Down Expand Up @@ -95,13 +95,13 @@ describe('NodeCommand', () => {
const configManager = new ConfigManager(testLogger)
const packageDownloader = new PackageDownloader(testLogger)
const depManager = new DependencyManager(testLogger)
const kubectl2 = new Kubectl2(configManager, testLogger)
const platformInstaller = new PlatformInstaller(testLogger, kubectl2)
const k8 = new K8(configManager, testLogger)
const platformInstaller = new PlatformInstaller(testLogger, k8)

const nodeCmd = new NodeCommand({
logger: testLogger,
helm,
kubectl2,
k8,
chartManager,
configManager,
downloader: packageDownloader,
Expand Down
Loading

0 comments on commit a911703

Please sign in to comment.