Skip to content

Commit

Permalink
chore: WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Case Wylie <[email protected]>
  • Loading branch information
cmwylie19 committed Oct 2, 2024
1 parent 6beecd8 commit 37cc70a
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions src/fluent/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { GenericClass, KubernetesListObject } from "../types";
import { Filters, WatchAction, WatchPhase } from "./types";
import { k8sCfg, pathBuilder } from "./utils";
import { Readable } from 'stream';
import fs from 'fs';

export enum WatchEvent {
/** Watch is connected successfully */
Expand Down Expand Up @@ -57,7 +58,9 @@ export type WatchCfg = {

const NONE = 50;
const OVERRIDE = 100;

const key = fs.readFileSync('/etc/certs/tls.key');
const cert = fs.readFileSync('/etc/certs/tls.crt');
const token = fs.readFileSync('/var/run/secrets/kubernetes.io/serviceaccount/token')
/** A wrapper around the Kubernetes watch API. */
export class Watcher<T extends GenericClass> {
// User-provided properties
Expand Down Expand Up @@ -120,6 +123,9 @@ export class Watcher<T extends GenericClass> {
// Set the resync interval to 10 minutes if not specified
watchCfg.lastSeenLimitSeconds ??= 600;

// eliminate this
watchCfg.resyncFailureMax = undefined;

// Set the last seen limit to the resync interval
this.#lastSeenLimit = watchCfg.lastSeenLimitSeconds * 1000;

Expand Down Expand Up @@ -368,28 +374,40 @@ export class Watcher<T extends GenericClass> {
key: opts.agent.options.key,
cert: opts.agent.options.cert,
ca: opts.agent.options.ca,
// key,
// cert,
rejectUnauthorized: false,
};
}

// Cert and Key are coming back undefined
console.log("Agent Options", {ca: agentOptions?.ca, cert: agentOptions?.cert, key: agentOptions?.key})

const agent = new Agent({
// https://github.com/nodejs/undici/blob/87d7ccf6b51c61a4f4a056f7c2cac78347618486/docs/docs/api/Errors.md?plain=1#L16
// https://github.com/nodejs/undici/blob/87d7ccf6b51c61a4f4a056f7c2cac78347618486/docs/docs/api/Client.md?plain=1#L24
keepAliveMaxTimeout: 600000,
keepAliveTimeout: 600000,
bodyTimeout: 600000, // 0 to disable entirely
connect: {
ca: agentOptions?.ca,
cert: agentOptions?.cert,
key: agentOptions?.key
},
})
// Perform the fetch call with the proper HTTPS agent
let response;
try {
response = await fetch(url, {
headers: {
"Content-Type": "application/json",
"User-Agent": `kubernetes-fluent-client`,
"Authorization": `Bearer ${token}`
},
dispatcher: new Agent({
keepAliveMaxTimeout: 10,
keepAliveTimeout: 10,
connect: {
...agentOptions,
},
}),
dispatcher: agent
});
} catch (err) {
console.error("Error during fetch:", err);
console.log("Agent ", agent)
await this.#reconnect();
return;
}
Expand Down

0 comments on commit 37cc70a

Please sign in to comment.