From 4a13b779c1eadd3ed0928dfc00a042473a852ccf Mon Sep 17 00:00:00 2001 From: kahirokunn Date: Tue, 18 Jun 2024 13:33:26 +0900 Subject: [PATCH] feat(kubekit-client): enhance error handling, bump version --- packages/kubekit-client/package.json | 2 +- packages/kubekit-client/src/client/index.ts | 23 +++++++++++++++------ packages/kubekit-client/src/lib/error.ts | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/packages/kubekit-client/package.json b/packages/kubekit-client/package.json index 7970643b..a7499f7c 100644 --- a/packages/kubekit-client/package.json +++ b/packages/kubekit-client/package.json @@ -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", diff --git a/packages/kubekit-client/src/client/index.ts b/packages/kubekit-client/src/client/index.ts index c194ed78..0f24770a 100644 --- a/packages/kubekit-client/src/client/index.ts +++ b/packages/kubekit-client/src/client/index.ts @@ -187,10 +187,7 @@ export async function apiClient( interceptors: [] as Interceptor[], ...removeNullableProperties(extraOptions), }; - options.interceptors = [ - ...globalInterceptors, - ...options.interceptors, - ] + options.interceptors = [...globalInterceptors, ...options.interceptors]; if (options.interceptors.length === 0) { options.interceptors = [defaultAuthorizationInterceptor]; } @@ -397,8 +394,22 @@ export async function apiClient( 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 ( diff --git a/packages/kubekit-client/src/lib/error.ts b/packages/kubekit-client/src/lib/error.ts index 159cc839..b5b793a6 100644 --- a/packages/kubekit-client/src/lib/error.ts +++ b/packages/kubekit-client/src/lib/error.ts @@ -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;