Skip to content

Commit 8350de5

Browse files
committed
fix: log and rethrow whenever are listFunctions fail
these calls aren't wrapped and end up as unhandled rejections, with little to no logging for their source and cause. this commit wraps these calls with some logs so we can at least explain future unhandled rejections coming from this area.
1 parent 3b96a7d commit 8350de5

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/supervisor/watchers/handlers/index.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,17 @@ export function setupInformer(namespace: string, workloadKind: WorkloadKind) {
9595
const workloadMetadata = workloadWatchMetadata[workloadKind];
9696
const namespacedEndpoint = workloadMetadata.endpoint.replace('{namespace}', namespace);
9797

98-
const informer = makeInformer<KubernetesObject>(kubeConfig, namespacedEndpoint,
99-
workloadMetadata.listFactory(namespace));
98+
const listMethod = workloadMetadata.listFactory(namespace);
99+
const loggedListMethod = async () => {
100+
try {
101+
return await listMethod();
102+
} catch (err) {
103+
logger.error({err, namespace, workloadKind}, 'error while listing entities on namespace');
104+
throw err;
105+
}
106+
};
107+
108+
const informer = makeInformer<KubernetesObject>(kubeConfig, namespacedEndpoint, loggedListMethod);
100109

101110
for (const informerVerb of Object.keys(workloadMetadata.handlers)) {
102111
informer.on(informerVerb, async (watchedWorkload) => {

src/supervisor/watchers/index.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { makeInformer, ADD } from '@kubernetes/client-node';
22
import { V1Namespace } from '@kubernetes/client-node';
3+
34
import config = require('../../common/config');
45
import logger = require('../../common/logger');
56
import { WorkloadKind } from '../types';
@@ -51,7 +52,18 @@ export function isKubernetesInternalNamespace(namespace: string): boolean {
5152
}
5253

5354
function setupWatchesForCluster(): void {
54-
const informer = makeInformer(kubeConfig, '/api/v1/namespaces', () => k8sApi.coreClient.listNamespace());
55+
const informer = makeInformer(
56+
kubeConfig,
57+
'/api/v1/namespaces',
58+
async () => {
59+
try {
60+
return await k8sApi.coreClient.listNamespace();
61+
} catch (err) {
62+
logger.error({err}, 'error while listing namespaces');
63+
throw err;
64+
}
65+
},
66+
);
5567

5668
informer.on(ADD, (namespace: V1Namespace) => {
5769
try {

0 commit comments

Comments
 (0)