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: updates based on KFC changes #825

Merged
merged 5 commits into from
May 23, 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
2 changes: 1 addition & 1 deletion docs/030_user-guide/120_customization.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ The Watch configuration is a part of the Pepr module that allows you to watch fo
| `PEPR_RETRYMAX` | The maximum number of times to retry the watch, the retry count is reset on success. | default: `"5"` |
| `PEPR_RETRYDELAYSECONDS` | The delay between retries in seconds. | default: `"10"` |
| `PEPR_RESYNCINTERVALSECONDS` | Amount of seconds to wait before a forced-resyncing of the watch list | default: `"300"` (5 mins) |
| `PEPR_ALLOWWATCHBOOKMARKS` | Whether to allow [watch bookmarks](https://kubernetes.io/docs/reference/using-api/api-concepts/#watch-bookmarks).| default: `"true"` or `"false"` |



## Customizing with Helm
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@types/ramda": "0.30.0",
"express": "4.19.2",
"fast-json-patch": "3.1.1",
"kubernetes-fluent-client": "2.5.1",
"kubernetes-fluent-client": "2.6.0",
"pino": "9.1.0",
"pino-pretty": "11.0.0",
"prom-client": "15.1.2",
Expand Down
31 changes: 15 additions & 16 deletions src/lib/watch-processor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,6 @@ describe("WatchProcessor", () => {
expect(exitSpy).toHaveBeenCalledWith(1);
});

it("should watch for the resource_update event", async () => {
mockEvents.mockImplementation((eventName: string | symbol, listener: (msg: string) => void) => {
if (eventName === WatchEvent.RESOURCE_VERSION) {
expect(listener).toBeInstanceOf(Function);
listener("45");
}
});

setupWatch(capabilities);
});

it("should watch for the give_up event", async () => {
const exitSpy = jest.spyOn(process, "exit").mockImplementation(() => {
return undefined as never;
Expand Down Expand Up @@ -227,11 +216,21 @@ describe("logEvent function", () => {
expect(Log.debug).toHaveBeenCalledWith(`Watch event ${WatchEvent.CONNECT} received. ${url}.`);
});

it("should handle BOOKMARK events", () => {
const mockObj = { id: "123", type: "Pod" } as KubernetesObject;
const message = "Changes up to the given resourceVersion have been sent";
logEvent(WatchEvent.BOOKMARK, message, mockObj);
expect(Log.debug).toHaveBeenCalledWith(mockObj, `Watch event ${WatchEvent.BOOKMARK} received. ${message}.`);
it("should handle LIST_ERROR events", () => {
const message = "LIST_ERROR";
logEvent(WatchEvent.LIST_ERROR, message);
expect(Log.debug).toHaveBeenCalledWith(`Watch event ${WatchEvent.LIST_ERROR} received. ${message}.`);
});
it("should handle LIST events", () => {
const podList = {
kind: "PodList",
apiVersion: "v1",
metadata: { resourceVersion: "10245" },
items: [],
};
const message = JSON.stringify(podList, undefined, 2);
logEvent(WatchEvent.LIST, message);
expect(Log.debug).toHaveBeenCalledWith(`Watch event ${WatchEvent.LIST} received. ${message}.`);
});

it("should handle DATA_ERROR events", () => {
Expand Down
12 changes: 2 additions & 10 deletions src/lib/watch-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const watchCfg: WatchCfg = {
resyncIntervalSec: process.env.PEPR_RESYNCINTERVALSECONDS
? parseInt(process.env.PEPR_RESYNCINTERVALSECONDS, 10)
: 300,
allowWatchBookmarks: process.env.PEPR_ALLOWWATCHBOOKMARKS === "false" ? false : true,
};

// Map the event to the watch phase
Expand Down Expand Up @@ -95,24 +94,17 @@ async function runBinding(binding: Binding, capabilityNamespaces: string[]) {

watcher.events.on(WatchEvent.CONNECT, url => logEvent(WatchEvent.CONNECT, url));

watcher.events.on(WatchEvent.BOOKMARK, obj =>
logEvent(WatchEvent.BOOKMARK, "Changes up to the given resourceVersion have been sent", obj),
);

watcher.events.on(WatchEvent.DATA_ERROR, err => logEvent(WatchEvent.DATA_ERROR, err.message));
watcher.events.on(WatchEvent.RESOURCE_VERSION, resourceVersion =>
logEvent(WatchEvent.RESOURCE_VERSION, `${resourceVersion}`),
);
watcher.events.on(WatchEvent.RECONNECT, (err, retryCount) =>
logEvent(WatchEvent.RECONNECT, err ? `Reconnecting after ${retryCount} attempts` : ""),
);
watcher.events.on(WatchEvent.RECONNECT_PENDING, () => logEvent(WatchEvent.RECONNECT_PENDING));
watcher.events.on(WatchEvent.GIVE_UP, err => logEvent(WatchEvent.GIVE_UP, err.message));
watcher.events.on(WatchEvent.ABORT, err => logEvent(WatchEvent.ABORT, err.message));
watcher.events.on(WatchEvent.OLD_RESOURCE_VERSION, err => logEvent(WatchEvent.OLD_RESOURCE_VERSION, err));
watcher.events.on(WatchEvent.RESYNC, err => logEvent(WatchEvent.RESYNC, err.message));
watcher.events.on(WatchEvent.NETWORK_ERROR, err => logEvent(WatchEvent.NETWORK_ERROR, err.message));

watcher.events.on(WatchEvent.LIST_ERROR, err => logEvent(WatchEvent.LIST_ERROR, err.message));
watcher.events.on(WatchEvent.LIST, list => logEvent(WatchEvent.LIST, JSON.stringify(list, undefined, 2)));
// Start the watch
try {
await watcher.start();
Expand Down
Loading