Skip to content

Commit

Permalink
feat: add kube diff and kube dryrun
Browse files Browse the repository at this point in the history
  • Loading branch information
vanhtuan0409 committed Nov 23, 2023
1 parent e3e7d8f commit a27b241
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 8 deletions.
2 changes: 1 addition & 1 deletion js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@anduintransaction/rivendell",
"version": "0.4.2",
"version": "0.4.3",
"repository": {
"type": "git",
"url": "git+https://github.com/anduintransaction/rivendell.git"
Expand Down
47 changes: 40 additions & 7 deletions js/src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,17 @@ export class NoopRunner extends Runner {

export class KubeRunner extends Runner {
kubeCtx: string;
dryRun: boolean;
namespace: string;

static KUBECTL_BIN = "kubectl";

constructor(
kubeCtx: string = "",
namespace: string = "default",
dryRun: boolean = false,
) {
super();
this.kubeCtx = kubeCtx;
this.namespace = namespace;
this.dryRun = dryRun;
}

commonArgs() {
Expand Down Expand Up @@ -124,8 +121,6 @@ export class KubeRunner extends Runner {
}

async wait(w: WaitStep) {
if (this.dryRun) return;

switch (w.wait.kind.toLowerCase()) {
case "job": {
await this.waitForJob(w.wait.name, w.wait.timeout);
Expand Down Expand Up @@ -162,10 +157,48 @@ export class KubeRunner extends Runner {

const args = this.commonArgs();
args.push("apply", "-f", "-");
if (this.dryRun) {
args.push("--dry-run=server");
const manifest = yaml.stringify(step.object);
execFileSync(KubeRunner.KUBECTL_BIN, args, {
input: manifest,
stdio: ["pipe", "inherit", "inherit"],
});
}
}

export class KubeDryrunRunner extends KubeRunner {
override async wait(_: WaitStep): Promise<void> {
return Promise.resolve();
}

override async deploy(step: DeployStep) {
if (step.object.kind.toLowerCase() === "job") {
// skip
return;
}

const args = this.commonArgs();
args.push("apply", "--dry-run=server", "-f", "-");
const manifest = yaml.stringify(step.object);
execFileSync(KubeRunner.KUBECTL_BIN, args, {
input: manifest,
stdio: ["pipe", "inherit", "inherit"],
});
}
}

export class KubeDiffRunner extends KubeRunner {
override async wait(_: WaitStep): Promise<void> {
return Promise.resolve();
}

override async deploy(step: DeployStep) {
if (step.object.kind.toLowerCase() === "job") {
// skip
return;
}

const args = this.commonArgs();
args.push("diff", "-f", "-");
const manifest = yaml.stringify(step.object);
execFileSync(KubeRunner.KUBECTL_BIN, args, {
input: manifest,
Expand Down

0 comments on commit a27b241

Please sign in to comment.