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

chore: remove webhooks after exiting npx pepr dev #816

Merged
merged 8 commits into from
May 21, 2024
Merged
Changes from 4 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
20 changes: 19 additions & 1 deletion src/cli/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { validateCapabilityNames } from "../lib/helpers";
import { Assets } from "../lib/assets";
import { buildModule, loadModule } from "./build";
import { RootCmd } from "./root";

import { K8s, kind } from "kubernetes-fluent-client";
import { PeprStore } from "../lib/k8s";
export default function (program: RootCmd) {
program
.command("dev")
Expand Down Expand Up @@ -49,6 +50,9 @@ export default function (program: RootCmd) {

try {
let program: ChildProcess;
const name = `pepr-${cfg.pepr.uuid}`;
const scheduleStore = `pepr-${cfg.pepr.uuid}-schedule`;
const store = `pepr-${cfg.pepr.uuid}-store`;

// Run the processed javascript file
const runFork = async () => {
Expand Down Expand Up @@ -77,6 +81,20 @@ export default function (program: RootCmd) {
},
stdio: "inherit",
});

program.on("close", async () => {
await Promise.all([
K8s(kind.MutatingWebhookConfiguration).Delete(name),
K8s(kind.ValidatingWebhookConfiguration).Delete(name),
K8s(PeprStore).InNamespace("pepr-system").Delete(scheduleStore),
K8s(PeprStore).InNamespace("pepr-system").Delete(store),
]);
});

// listen for CTRL+C and remove webhooks
process.on("SIGINT", () => {
console.debug(`Received SIGINT, removing webhooks`);
});
};

await buildModule(async r => {
Expand Down
Loading