Skip to content

Commit

Permalink
feat(kubekit-client): enhance error handling, bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
kahirokunn committed Jun 18, 2024
1 parent 11394db commit 4a13b77
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/kubekit-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@kubekit/client",
"version": "0.2.14",
"version": "0.2.16",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"author": "kahirokunn",
Expand Down
23 changes: 17 additions & 6 deletions packages/kubekit-client/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,7 @@ export async function apiClient<Response>(
interceptors: [] as Interceptor[],
...removeNullableProperties(extraOptions),
};
options.interceptors = [
...globalInterceptors,
...options.interceptors,
]
options.interceptors = [...globalInterceptors, ...options.interceptors];
if (options.interceptors.length === 0) {
options.interceptors = [defaultAuthorizationInterceptor];
}
Expand Down Expand Up @@ -397,8 +394,22 @@ export async function apiClient<Response>(
await options.onError(error);

// When Invalid, it will not pass no matter how many times it is re-run, so it is terminated without retry.
if (isKubernetesError(error) && error.reason === "Invalid") {
throw error
if (isKubernetesError(error) && error.reason === 'Invalid') {
if (
error.details.causes.some((cause) =>
cause.message.includes(
'sendInitialEvents is forbidden for watch unless the WatchList feature gate is enabled'
)
)
) {
console.info(`Error: sendInitialEvents is forbidden for watch unless the WatchList feature gate is enabled.
To resolve this issue, enable the WatchList feature gate in your k8s api-server.
For k3d, you can enable the feature gate with the following command:
$ k3d cluster create kubekit --k3s-arg '--kube-apiserver-arg=feature-gates=WatchList=true@server:*'`);
}
throw error;
}

if (
Expand Down
2 changes: 1 addition & 1 deletion packages/kubekit-client/src/lib/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export type KubernetesError = {
}[];
};
code: number;
}
};

export function isKubernetesError(obj: unknown): obj is KubernetesError {
if (typeof obj !== 'object' || obj === null) return false;
Expand Down

0 comments on commit 4a13b77

Please sign in to comment.