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: fix unparsable lines in monitor command #907

Merged
merged 8 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion journey/pepr-deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,15 @@ export function peprDeploy() {
const stdout: String = data.toString()
state.accept = stdout.includes("✅") ? true : state.accept
state.reject = stdout.includes("❌") ? true : state.reject

expect(stdout.includes("IGNORED")).toBe(false)
if (state.accept && state.reject) {
proc.kill()
proc.stdin.destroy()
proc.stdout.destroy()
proc.stderr.destroy()
}
})

proc.on('exit', () => state.done = true);

await until(() => state.done)
Expand Down
17 changes: 9 additions & 8 deletions src/cli/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,28 +42,29 @@ export default function (program: RootCmd) {
const log = new K8sLog(kc);

const logStream = new stream.PassThrough();

logStream.on("data", chunk => {
logStream.on("data", async chunk => {
const respMsg = `"msg":"Check response"`;
// Split the chunk into lines
const lines = chunk.toString().split("\n");
const lines = await chunk.toString().split("\n");

for (const line of lines) {
// Check for `"msg":"Hello Pepr"`
if (line.includes(respMsg)) {
try {
const payload = JSON.parse(line);
const payload = JSON.parse(line.trim());
const isMutate = payload.res.patchType || payload.res.warnings;

const name = `${payload.namespace}${payload.name}`;
const uid = payload.uid;
const uid = payload.res.uid;

if (isMutate) {
const plainPatch = atob(payload.res.patch) || "";
const patch = JSON.stringify(JSON.parse(plainPatch), null, 2);
const plainPatch =
payload.res?.patch !== undefined && payload.res?.patch !== null
? atob(payload.res.patch)
: "";

const patch = plainPatch !== "" && JSON.stringify(JSON.parse(plainPatch), null, 2);
const patchType = payload.res.patchType || payload.res.warnings || "";

const allowOrDeny = payload.res.allowed ? "🔀" : "🚫";
console.log(`\n${allowOrDeny} MUTATE ${name} (${uid})`);
if (patchType.length > 0) {
Expand Down
1 change: 1 addition & 0 deletions src/lib/helpers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ describe("validateCapabilityNames Property-Based Tests", () => {
);
});
});

describe("validateCapabilityNames", () => {
test("should return true if all capability names are valid", () => {
const capabilities = mockCapabilities;
Expand Down
Loading