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

fix: bind debug logs to fluent-client watch log handler #450

Merged
merged 2 commits into from
Dec 22, 2023
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
12 changes: 8 additions & 4 deletions src/lib/watch-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import { K8s } from "kubernetes-fluent-client";
import { WatchPhase } from "kubernetes-fluent-client/dist/fluent/types";

import { WatchCfg } from "kubernetes-fluent-client/dist/fluent/watch";

import { Capability } from "./capability";
import Log from "./logger";
import { Binding, Event } from "./types";
Expand Down Expand Up @@ -37,15 +37,19 @@ async function runBinding(binding: Binding) {
Log.error(e, "Watch failed after 3 attempts, giving up");
process.exit(1);
},
// pino binding explodes unless we wrap it
logFn: (obj: unknown, msg?: string, ...args: unknown[]) => Log.debug(obj, msg, ...args),
};

// Watch the resource
await K8s(binding.model, binding.filters).Watch((obj, type) => {
await K8s(binding.model, binding.filters).Watch(async (obj, type) => {
Log.debug(obj, `Watch event ${type} received`);

// If the type matches the phase, call the watch callback
if (phaseMatch.includes(type)) {
try {
// This may be a promise, but we don't need to wait for it
void binding.watchCallback?.(obj, type);
// Perform the watch callback
await binding.watchCallback?.(obj, type);
} catch (e) {
// Errors in the watch callback should not crash the controller
Log.error(e, "Error executing watch callback");
Expand Down
1 change: 1 addition & 0 deletions src/templates/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"enableTurboSourcemaps": true,
"resolveSourceMapLocations": [
"${workspaceFolder}/**",
"node_modules/kubernetes-fluent-client/**",
"node_modules/pepr/**"
]
}
Expand Down