Skip to content

Commit

Permalink
chore: fix unparsable lines in monitor command (#907)
Browse files Browse the repository at this point in the history
## Description

After debugging, adding in checks to ensure fields are defined and a
slight sleep which helps to get complete JSON. I have not experience the
issue since implementing the fix.

The issue #894 details the findings from debugging in a
[comment](#894 (comment))

## Related Issue

Fixes #894 
<!-- or -->
Relates to #

## Type of change

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Other (security config, docs update, etc)

## Checklist before merging

- [x] Test, docs, adr added or updated as needed
- [x] [Contributor Guide
Steps](https://docs.pepr.dev/main/contribute/#submitting-a-pull-request)
followed

---------

Signed-off-by: Case Wylie <cmwylie19@defenseunicorns.com>
  • Loading branch information
cmwylie19 authored Jun 26, 2024
1 parent d380468 commit be862dc
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
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

0 comments on commit be862dc

Please sign in to comment.