Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): implement cluster setup command #452

Merged
merged 19 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions fullstack-network-manager/resources/dev-cluster.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
name: fst # this is overridden if CLUSTER_NAME env var is set. Check .env file
nodes:
- role: control-plane
labels:
fullstack-scheduling.io/role: network
62 changes: 24 additions & 38 deletions fullstack-network-manager/src/commands/base.mjs
Original file line number Diff line number Diff line change
@@ -1,57 +1,41 @@
"use strict"
import {exec} from "child_process";
import * as core from "../core/index.mjs"
import chalk from "chalk";

export const BaseCommand = class BaseCommand {
/**
* Check if 'kind' CLI program is installed or not
* @returns {Promise<boolean>}
*/
async checkKind() {
async checkDep(dep) {
try {
this.logger.debug("Checking if 'kind' is installed")
await this.runExec("kind --version")
this.logger.debug("OK: 'kind' is installed")
await this.runExec(dep)
} catch (e) {
this.logger.error("%s", e)
return false
}

return true
}
/**
* Check if 'kind' CLI program is installed or not
* @returns {Promise<boolean>}
*/
async checkKind() {
return this.checkDep(core.constants.KIND)
}

/**
* Check if 'helm' CLI program is installed or not
* @returns {Promise<boolean>}
*/
async checkHelm() {
try {
this.logger.debug("Checking if 'helm' is installed")
await this.runExec("helm version")
this.logger.debug("OK: 'helm' is installed")
} catch (e) {
this.logger.error("%s", e)
return false
}

return true
return this.checkDep(core.constants.HELM)
}

/**
* Check if 'kubectl' CLI program is installed or not
* @returns {Promise<boolean>}
*/
async checkKubectl() {
try {
this.logger.debug("Checking if 'kubectl' is installed")
await this.runExec("kubectl version")
this.logger.debug("OK: 'kubectl' is installed")
} catch (e) {
this.logger.error("%s", e)
return false
}

return true
return this.checkDep(core.constants.KUBECTL)
}

/**
Expand All @@ -60,39 +44,41 @@ export const BaseCommand = class BaseCommand {
* @returns {Promise<boolean>}
*/
async checkDependencies(deps = []) {
this.logger.info("Checking for required dependencies: %s", deps)
this.logger.debug("Checking for required dependencies: %s", deps)

for (let i = 0; i < deps.length; i++) {
let dep = deps[i]
this.logger.debug("Checking for dependency '%s'", dep)

let status = false
let check = this.checks.get(dep)
if (!check) {
this.logger.error("FAIL: Dependency '%s' is unknown", dep)
return false
if (check) {
status = await check()
}


let status = await check()
if (!status) {
this.logger.error("FAIL: Dependency '%s' is not found", dep)
this.logger.showUser(chalk.red(`FAIL: '${dep}' is not found`))
return false
}

this.logger.debug("PASS: Dependency '%s' is found", dep)
this.logger.showUser(chalk.green(`OK: '${dep}' is found`))
}

this.logger.info("PASS: All required dependencies are found: %s", deps)
this.logger.debug("All required dependencies are found: %s", deps)

return true
}

/**
* Run the specified bash command
* @param cmd is a bash command including args
* @returns {Promise<unknown>}
* @returns {Promise<string>}
*/
runExec(cmd) {
let self = this

return new Promise((resolve, reject) => {
self.logger.debug(`Invoking '${cmd}'...`)
exec(cmd, (error, stdout, stderr) => {
if (error) {
reject(error)
Expand Down
Loading
Loading