kubeview-mcp 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierrc.json +11 -0
- package/CHANGELOG.md +55 -0
- package/LICENSE +21 -0
- package/README.md +251 -0
- package/RELEASE.md +154 -0
- package/TODO.md +0 -0
- package/bin/kubeview-mcp.js +274 -0
- package/bin/setup.js +368 -0
- package/dist/src/cli/cli.d.ts +3 -0
- package/dist/src/cli/cli.d.ts.map +1 -0
- package/dist/src/cli/cli.js +23 -0
- package/dist/src/cli/cli.js.map +1 -0
- package/dist/src/index.d.ts +8 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +45 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/kubernetes/BaseResourceOperations.d.ts +155 -0
- package/dist/src/kubernetes/BaseResourceOperations.d.ts.map +1 -0
- package/dist/src/kubernetes/BaseResourceOperations.js +136 -0
- package/dist/src/kubernetes/BaseResourceOperations.js.map +1 -0
- package/dist/src/kubernetes/CircuitBreaker.d.ts +182 -0
- package/dist/src/kubernetes/CircuitBreaker.d.ts.map +1 -0
- package/dist/src/kubernetes/CircuitBreaker.js +369 -0
- package/dist/src/kubernetes/CircuitBreaker.js.map +1 -0
- package/dist/src/kubernetes/ConnectionManager.d.ts +60 -0
- package/dist/src/kubernetes/ConnectionManager.d.ts.map +1 -0
- package/dist/src/kubernetes/ConnectionManager.js +77 -0
- package/dist/src/kubernetes/ConnectionManager.js.map +1 -0
- package/dist/src/kubernetes/ConnectionPool.d.ts +183 -0
- package/dist/src/kubernetes/ConnectionPool.d.ts.map +1 -0
- package/dist/src/kubernetes/ConnectionPool.js +437 -0
- package/dist/src/kubernetes/ConnectionPool.js.map +1 -0
- package/dist/src/kubernetes/ErrorHandler.d.ts +172 -0
- package/dist/src/kubernetes/ErrorHandler.d.ts.map +1 -0
- package/dist/src/kubernetes/ErrorHandler.js +328 -0
- package/dist/src/kubernetes/ErrorHandler.js.map +1 -0
- package/dist/src/kubernetes/ErrorHandling.d.ts +148 -0
- package/dist/src/kubernetes/ErrorHandling.d.ts.map +1 -0
- package/dist/src/kubernetes/ErrorHandling.js +304 -0
- package/dist/src/kubernetes/ErrorHandling.js.map +1 -0
- package/dist/src/kubernetes/KubernetesClient.d.ts +162 -0
- package/dist/src/kubernetes/KubernetesClient.d.ts.map +1 -0
- package/dist/src/kubernetes/KubernetesClient.js +382 -0
- package/dist/src/kubernetes/KubernetesClient.js.map +1 -0
- package/dist/src/kubernetes/ResourceOperations.d.ts +69 -0
- package/dist/src/kubernetes/ResourceOperations.d.ts.map +1 -0
- package/dist/src/kubernetes/ResourceOperations.js +99 -0
- package/dist/src/kubernetes/ResourceOperations.js.map +1 -0
- package/dist/src/kubernetes/RetryStrategy.d.ts +137 -0
- package/dist/src/kubernetes/RetryStrategy.d.ts.map +1 -0
- package/dist/src/kubernetes/RetryStrategy.js +277 -0
- package/dist/src/kubernetes/RetryStrategy.js.map +1 -0
- package/dist/src/kubernetes/RetryableOperation.d.ts +118 -0
- package/dist/src/kubernetes/RetryableOperation.d.ts.map +1 -0
- package/dist/src/kubernetes/RetryableOperation.js +233 -0
- package/dist/src/kubernetes/RetryableOperation.js.map +1 -0
- package/dist/src/kubernetes/index.d.ts +18 -0
- package/dist/src/kubernetes/index.d.ts.map +1 -0
- package/dist/src/kubernetes/index.js +28 -0
- package/dist/src/kubernetes/index.js.map +1 -0
- package/dist/src/kubernetes/resources/ConfigMapOperations.d.ts +60 -0
- package/dist/src/kubernetes/resources/ConfigMapOperations.d.ts.map +1 -0
- package/dist/src/kubernetes/resources/ConfigMapOperations.js +306 -0
- package/dist/src/kubernetes/resources/ConfigMapOperations.js.map +1 -0
- package/dist/src/kubernetes/resources/CustomResourceOperations.d.ts +55 -0
- package/dist/src/kubernetes/resources/CustomResourceOperations.d.ts.map +1 -0
- package/dist/src/kubernetes/resources/CustomResourceOperations.js +363 -0
- package/dist/src/kubernetes/resources/CustomResourceOperations.js.map +1 -0
- package/dist/src/kubernetes/resources/DeploymentOperations.d.ts +66 -0
- package/dist/src/kubernetes/resources/DeploymentOperations.d.ts.map +1 -0
- package/dist/src/kubernetes/resources/DeploymentOperations.js +234 -0
- package/dist/src/kubernetes/resources/DeploymentOperations.js.map +1 -0
- package/dist/src/kubernetes/resources/IngressOperations.d.ts +60 -0
- package/dist/src/kubernetes/resources/IngressOperations.d.ts.map +1 -0
- package/dist/src/kubernetes/resources/IngressOperations.js +224 -0
- package/dist/src/kubernetes/resources/IngressOperations.js.map +1 -0
- package/dist/src/kubernetes/resources/MetricOperations.d.ts +218 -0
- package/dist/src/kubernetes/resources/MetricOperations.d.ts.map +1 -0
- package/dist/src/kubernetes/resources/MetricOperations.js +893 -0
- package/dist/src/kubernetes/resources/MetricOperations.js.map +1 -0
- package/dist/src/kubernetes/resources/NamespaceOperations.d.ts +38 -0
- package/dist/src/kubernetes/resources/NamespaceOperations.d.ts.map +1 -0
- package/dist/src/kubernetes/resources/NamespaceOperations.js +101 -0
- package/dist/src/kubernetes/resources/NamespaceOperations.js.map +1 -0
- package/dist/src/kubernetes/resources/PersistentVolumeClaimOperations.d.ts +109 -0
- package/dist/src/kubernetes/resources/PersistentVolumeClaimOperations.d.ts.map +1 -0
- package/dist/src/kubernetes/resources/PersistentVolumeClaimOperations.js +383 -0
- package/dist/src/kubernetes/resources/PersistentVolumeClaimOperations.js.map +1 -0
- package/dist/src/kubernetes/resources/PersistentVolumeOperations.d.ts +97 -0
- package/dist/src/kubernetes/resources/PersistentVolumeOperations.d.ts.map +1 -0
- package/dist/src/kubernetes/resources/PersistentVolumeOperations.js +321 -0
- package/dist/src/kubernetes/resources/PersistentVolumeOperations.js.map +1 -0
- package/dist/src/kubernetes/resources/PodOperations.d.ts +99 -0
- package/dist/src/kubernetes/resources/PodOperations.d.ts.map +1 -0
- package/dist/src/kubernetes/resources/PodOperations.js +333 -0
- package/dist/src/kubernetes/resources/PodOperations.js.map +1 -0
- package/dist/src/kubernetes/resources/SecretOperations.d.ts +71 -0
- package/dist/src/kubernetes/resources/SecretOperations.d.ts.map +1 -0
- package/dist/src/kubernetes/resources/SecretOperations.js +254 -0
- package/dist/src/kubernetes/resources/SecretOperations.js.map +1 -0
- package/dist/src/kubernetes/resources/ServiceOperations.d.ts +64 -0
- package/dist/src/kubernetes/resources/ServiceOperations.d.ts.map +1 -0
- package/dist/src/kubernetes/resources/ServiceOperations.js +232 -0
- package/dist/src/kubernetes/resources/ServiceOperations.js.map +1 -0
- package/dist/src/kubernetes/utils/ResourceUtils.d.ts +238 -0
- package/dist/src/kubernetes/utils/ResourceUtils.d.ts.map +1 -0
- package/dist/src/kubernetes/utils/ResourceUtils.js +439 -0
- package/dist/src/kubernetes/utils/ResourceUtils.js.map +1 -0
- package/dist/src/plugins/ArgoCDToolsPlugin.d.ts +45 -0
- package/dist/src/plugins/ArgoCDToolsPlugin.d.ts.map +1 -0
- package/dist/src/plugins/ArgoCDToolsPlugin.js +155 -0
- package/dist/src/plugins/ArgoCDToolsPlugin.js.map +1 -0
- package/dist/src/plugins/ArgoToolsPlugin.d.ts +45 -0
- package/dist/src/plugins/ArgoToolsPlugin.d.ts.map +1 -0
- package/dist/src/plugins/ArgoToolsPlugin.js +149 -0
- package/dist/src/plugins/ArgoToolsPlugin.js.map +1 -0
- package/dist/src/plugins/HelmToolsPlugin.d.ts +41 -0
- package/dist/src/plugins/HelmToolsPlugin.d.ts.map +1 -0
- package/dist/src/plugins/HelmToolsPlugin.js +146 -0
- package/dist/src/plugins/HelmToolsPlugin.js.map +1 -0
- package/dist/src/plugins/KubernetesToolsPlugin.d.ts +44 -0
- package/dist/src/plugins/KubernetesToolsPlugin.d.ts.map +1 -0
- package/dist/src/plugins/KubernetesToolsPlugin.js +159 -0
- package/dist/src/plugins/KubernetesToolsPlugin.js.map +1 -0
- package/dist/src/plugins/SamplePlugin.d.ts +12 -0
- package/dist/src/plugins/SamplePlugin.d.ts.map +1 -0
- package/dist/src/plugins/SamplePlugin.js +51 -0
- package/dist/src/plugins/SamplePlugin.js.map +1 -0
- package/dist/src/plugins/index.d.ts +5 -0
- package/dist/src/plugins/index.d.ts.map +1 -0
- package/dist/src/plugins/index.js +5 -0
- package/dist/src/plugins/index.js.map +1 -0
- package/dist/src/server/MCPServer.d.ts +93 -0
- package/dist/src/server/MCPServer.d.ts.map +1 -0
- package/dist/src/server/MCPServer.js +398 -0
- package/dist/src/server/MCPServer.js.map +1 -0
- package/dist/src/tools/argo/ArgoCronListTool.d.ts +10 -0
- package/dist/src/tools/argo/ArgoCronListTool.d.ts.map +1 -0
- package/dist/src/tools/argo/ArgoCronListTool.js +70 -0
- package/dist/src/tools/argo/ArgoCronListTool.js.map +1 -0
- package/dist/src/tools/argo/ArgoGetTool.d.ts +10 -0
- package/dist/src/tools/argo/ArgoGetTool.d.ts.map +1 -0
- package/dist/src/tools/argo/ArgoGetTool.js +80 -0
- package/dist/src/tools/argo/ArgoGetTool.js.map +1 -0
- package/dist/src/tools/argo/ArgoListTool.d.ts +10 -0
- package/dist/src/tools/argo/ArgoListTool.d.ts.map +1 -0
- package/dist/src/tools/argo/ArgoListTool.js +133 -0
- package/dist/src/tools/argo/ArgoListTool.js.map +1 -0
- package/dist/src/tools/argo/ArgoLogsTool.d.ts +10 -0
- package/dist/src/tools/argo/ArgoLogsTool.d.ts.map +1 -0
- package/dist/src/tools/argo/ArgoLogsTool.js +117 -0
- package/dist/src/tools/argo/ArgoLogsTool.js.map +1 -0
- package/dist/src/tools/argo/BaseTool.d.ts +60 -0
- package/dist/src/tools/argo/BaseTool.d.ts.map +1 -0
- package/dist/src/tools/argo/BaseTool.js +51 -0
- package/dist/src/tools/argo/BaseTool.js.map +1 -0
- package/dist/src/tools/argo/index.d.ts +7 -0
- package/dist/src/tools/argo/index.d.ts.map +1 -0
- package/dist/src/tools/argo/index.js +6 -0
- package/dist/src/tools/argo/index.js.map +1 -0
- package/dist/src/tools/argocd/ArgoCDAppGetTool.d.ts +10 -0
- package/dist/src/tools/argocd/ArgoCDAppGetTool.d.ts.map +1 -0
- package/dist/src/tools/argocd/ArgoCDAppGetTool.js +97 -0
- package/dist/src/tools/argocd/ArgoCDAppGetTool.js.map +1 -0
- package/dist/src/tools/argocd/ArgoCDAppHistoryTool.d.ts +10 -0
- package/dist/src/tools/argocd/ArgoCDAppHistoryTool.d.ts.map +1 -0
- package/dist/src/tools/argocd/ArgoCDAppHistoryTool.js +80 -0
- package/dist/src/tools/argocd/ArgoCDAppHistoryTool.js.map +1 -0
- package/dist/src/tools/argocd/ArgoCDAppListTool.d.ts +10 -0
- package/dist/src/tools/argocd/ArgoCDAppListTool.d.ts.map +1 -0
- package/dist/src/tools/argocd/ArgoCDAppListTool.js +128 -0
- package/dist/src/tools/argocd/ArgoCDAppListTool.js.map +1 -0
- package/dist/src/tools/argocd/ArgoCDAppLogsTool.d.ts +10 -0
- package/dist/src/tools/argocd/ArgoCDAppLogsTool.d.ts.map +1 -0
- package/dist/src/tools/argocd/ArgoCDAppLogsTool.js +143 -0
- package/dist/src/tools/argocd/ArgoCDAppLogsTool.js.map +1 -0
- package/dist/src/tools/argocd/ArgoCDAppResourcesTool.d.ts +10 -0
- package/dist/src/tools/argocd/ArgoCDAppResourcesTool.d.ts.map +1 -0
- package/dist/src/tools/argocd/ArgoCDAppResourcesTool.js +123 -0
- package/dist/src/tools/argocd/ArgoCDAppResourcesTool.js.map +1 -0
- package/dist/src/tools/argocd/BaseTool.d.ts +71 -0
- package/dist/src/tools/argocd/BaseTool.d.ts.map +1 -0
- package/dist/src/tools/argocd/BaseTool.js +62 -0
- package/dist/src/tools/argocd/BaseTool.js.map +1 -0
- package/dist/src/tools/argocd/index.d.ts +8 -0
- package/dist/src/tools/argocd/index.d.ts.map +1 -0
- package/dist/src/tools/argocd/index.js +7 -0
- package/dist/src/tools/argocd/index.js.map +1 -0
- package/dist/src/tools/helm/BaseTool.d.ts +51 -0
- package/dist/src/tools/helm/BaseTool.d.ts.map +1 -0
- package/dist/src/tools/helm/BaseTool.js +42 -0
- package/dist/src/tools/helm/BaseTool.js.map +1 -0
- package/dist/src/tools/helm/HelmGetHooksTool.d.ts +10 -0
- package/dist/src/tools/helm/HelmGetHooksTool.d.ts.map +1 -0
- package/dist/src/tools/helm/HelmGetHooksTool.js +38 -0
- package/dist/src/tools/helm/HelmGetHooksTool.js.map +1 -0
- package/dist/src/tools/helm/HelmGetManifestTool.d.ts +10 -0
- package/dist/src/tools/helm/HelmGetManifestTool.d.ts.map +1 -0
- package/dist/src/tools/helm/HelmGetManifestTool.js +38 -0
- package/dist/src/tools/helm/HelmGetManifestTool.js.map +1 -0
- package/dist/src/tools/helm/HelmGetNotesTool.d.ts +10 -0
- package/dist/src/tools/helm/HelmGetNotesTool.d.ts.map +1 -0
- package/dist/src/tools/helm/HelmGetNotesTool.js +38 -0
- package/dist/src/tools/helm/HelmGetNotesTool.js.map +1 -0
- package/dist/src/tools/helm/HelmGetResourcesTool.d.ts +13 -0
- package/dist/src/tools/helm/HelmGetResourcesTool.d.ts.map +1 -0
- package/dist/src/tools/helm/HelmGetResourcesTool.js +124 -0
- package/dist/src/tools/helm/HelmGetResourcesTool.js.map +1 -0
- package/dist/src/tools/helm/HelmGetValuesTool.d.ts +10 -0
- package/dist/src/tools/helm/HelmGetValuesTool.d.ts.map +1 -0
- package/dist/src/tools/helm/HelmGetValuesTool.js +54 -0
- package/dist/src/tools/helm/HelmGetValuesTool.js.map +1 -0
- package/dist/src/tools/helm/HelmHistoryTool.d.ts +10 -0
- package/dist/src/tools/helm/HelmHistoryTool.d.ts.map +1 -0
- package/dist/src/tools/helm/HelmHistoryTool.js +49 -0
- package/dist/src/tools/helm/HelmHistoryTool.js.map +1 -0
- package/dist/src/tools/helm/HelmListTool.d.ts +10 -0
- package/dist/src/tools/helm/HelmListTool.d.ts.map +1 -0
- package/dist/src/tools/helm/HelmListTool.js +107 -0
- package/dist/src/tools/helm/HelmListTool.js.map +1 -0
- package/dist/src/tools/helm/HelmListWithResourcesTool.d.ts +14 -0
- package/dist/src/tools/helm/HelmListWithResourcesTool.d.ts.map +1 -0
- package/dist/src/tools/helm/HelmListWithResourcesTool.js +175 -0
- package/dist/src/tools/helm/HelmListWithResourcesTool.js.map +1 -0
- package/dist/src/tools/helm/HelmStatusTool.d.ts +10 -0
- package/dist/src/tools/helm/HelmStatusTool.d.ts.map +1 -0
- package/dist/src/tools/helm/HelmStatusTool.js +54 -0
- package/dist/src/tools/helm/HelmStatusTool.js.map +1 -0
- package/dist/src/tools/helm/index.d.ts +12 -0
- package/dist/src/tools/helm/index.d.ts.map +1 -0
- package/dist/src/tools/helm/index.js +11 -0
- package/dist/src/tools/helm/index.js.map +1 -0
- package/dist/src/tools/kubernetes/BaseTool.d.ts +48 -0
- package/dist/src/tools/kubernetes/BaseTool.d.ts.map +1 -0
- package/dist/src/tools/kubernetes/BaseTool.js +55 -0
- package/dist/src/tools/kubernetes/BaseTool.js.map +1 -0
- package/dist/src/tools/kubernetes/GetConfigMapTool.d.ts +11 -0
- package/dist/src/tools/kubernetes/GetConfigMapTool.d.ts.map +1 -0
- package/dist/src/tools/kubernetes/GetConfigMapTool.js +28 -0
- package/dist/src/tools/kubernetes/GetConfigMapTool.js.map +1 -0
- package/dist/src/tools/kubernetes/GetContainerLogsTool.d.ts +15 -0
- package/dist/src/tools/kubernetes/GetContainerLogsTool.d.ts.map +1 -0
- package/dist/src/tools/kubernetes/GetContainerLogsTool.js +119 -0
- package/dist/src/tools/kubernetes/GetContainerLogsTool.js.map +1 -0
- package/dist/src/tools/kubernetes/GetDeploymentsTool.d.ts +11 -0
- package/dist/src/tools/kubernetes/GetDeploymentsTool.d.ts.map +1 -0
- package/dist/src/tools/kubernetes/GetDeploymentsTool.js +30 -0
- package/dist/src/tools/kubernetes/GetDeploymentsTool.js.map +1 -0
- package/dist/src/tools/kubernetes/GetEventsTool.d.ts +11 -0
- package/dist/src/tools/kubernetes/GetEventsTool.d.ts.map +1 -0
- package/dist/src/tools/kubernetes/GetEventsTool.js +123 -0
- package/dist/src/tools/kubernetes/GetEventsTool.js.map +1 -0
- package/dist/src/tools/kubernetes/GetIngressTool.d.ts +11 -0
- package/dist/src/tools/kubernetes/GetIngressTool.d.ts.map +1 -0
- package/dist/src/tools/kubernetes/GetIngressTool.js +35 -0
- package/dist/src/tools/kubernetes/GetIngressTool.js.map +1 -0
- package/dist/src/tools/kubernetes/GetMetricsTool.d.ts +11 -0
- package/dist/src/tools/kubernetes/GetMetricsTool.d.ts.map +1 -0
- package/dist/src/tools/kubernetes/GetMetricsTool.js +40 -0
- package/dist/src/tools/kubernetes/GetMetricsTool.js.map +1 -0
- package/dist/src/tools/kubernetes/GetNamespacesTool.d.ts +11 -0
- package/dist/src/tools/kubernetes/GetNamespacesTool.d.ts.map +1 -0
- package/dist/src/tools/kubernetes/GetNamespacesTool.js +33 -0
- package/dist/src/tools/kubernetes/GetNamespacesTool.js.map +1 -0
- package/dist/src/tools/kubernetes/GetPersistentVolumeClaimsTool.d.ts +11 -0
- package/dist/src/tools/kubernetes/GetPersistentVolumeClaimsTool.d.ts.map +1 -0
- package/dist/src/tools/kubernetes/GetPersistentVolumeClaimsTool.js +92 -0
- package/dist/src/tools/kubernetes/GetPersistentVolumeClaimsTool.js.map +1 -0
- package/dist/src/tools/kubernetes/GetPersistentVolumesTool.d.ts +11 -0
- package/dist/src/tools/kubernetes/GetPersistentVolumesTool.d.ts.map +1 -0
- package/dist/src/tools/kubernetes/GetPersistentVolumesTool.js +88 -0
- package/dist/src/tools/kubernetes/GetPersistentVolumesTool.js.map +1 -0
- package/dist/src/tools/kubernetes/GetPodMetricsTool.d.ts +11 -0
- package/dist/src/tools/kubernetes/GetPodMetricsTool.d.ts.map +1 -0
- package/dist/src/tools/kubernetes/GetPodMetricsTool.js +100 -0
- package/dist/src/tools/kubernetes/GetPodMetricsTool.js.map +1 -0
- package/dist/src/tools/kubernetes/GetPodsTool.d.ts +11 -0
- package/dist/src/tools/kubernetes/GetPodsTool.d.ts.map +1 -0
- package/dist/src/tools/kubernetes/GetPodsTool.js +35 -0
- package/dist/src/tools/kubernetes/GetPodsTool.js.map +1 -0
- package/dist/src/tools/kubernetes/GetResourceTool.d.ts +12 -0
- package/dist/src/tools/kubernetes/GetResourceTool.d.ts.map +1 -0
- package/dist/src/tools/kubernetes/GetResourceTool.js +79 -0
- package/dist/src/tools/kubernetes/GetResourceTool.js.map +1 -0
- package/dist/src/tools/kubernetes/GetSecretsTool.d.ts +11 -0
- package/dist/src/tools/kubernetes/GetSecretsTool.d.ts.map +1 -0
- package/dist/src/tools/kubernetes/GetSecretsTool.js +49 -0
- package/dist/src/tools/kubernetes/GetSecretsTool.js.map +1 -0
- package/dist/src/tools/kubernetes/GetServicesTool.d.ts +11 -0
- package/dist/src/tools/kubernetes/GetServicesTool.d.ts.map +1 -0
- package/dist/src/tools/kubernetes/GetServicesTool.js +35 -0
- package/dist/src/tools/kubernetes/GetServicesTool.js.map +1 -0
- package/dist/src/tools/kubernetes/index.d.ts +17 -0
- package/dist/src/tools/kubernetes/index.d.ts.map +1 -0
- package/dist/src/tools/kubernetes/index.js +16 -0
- package/dist/src/tools/kubernetes/index.js.map +1 -0
- package/dist/src/utils/CliUtils.d.ts +24 -0
- package/dist/src/utils/CliUtils.d.ts.map +1 -0
- package/dist/src/utils/CliUtils.js +159 -0
- package/dist/src/utils/CliUtils.js.map +1 -0
- package/dist/tests/__mocks__/@kubernetes/client-node.d.ts +34 -0
- package/dist/tests/__mocks__/@kubernetes/client-node.d.ts.map +1 -0
- package/dist/tests/__mocks__/@kubernetes/client-node.js +20 -0
- package/dist/tests/__mocks__/@kubernetes/client-node.js.map +1 -0
- package/dist/tests/argo/ArgoGetTool.test.d.ts +2 -0
- package/dist/tests/argo/ArgoGetTool.test.d.ts.map +1 -0
- package/dist/tests/argo/ArgoGetTool.test.js +141 -0
- package/dist/tests/argo/ArgoGetTool.test.js.map +1 -0
- package/dist/tests/helm/BaseTool.test.d.ts +2 -0
- package/dist/tests/helm/BaseTool.test.d.ts.map +1 -0
- package/dist/tests/helm/BaseTool.test.js +241 -0
- package/dist/tests/helm/BaseTool.test.js.map +1 -0
- package/dist/tests/index.test.d.ts +2 -0
- package/dist/tests/index.test.d.ts.map +1 -0
- package/dist/tests/index.test.js +7 -0
- package/dist/tests/index.test.js.map +1 -0
- package/dist/tests/kubernetes/ConfigMapOperations.test.d.ts +2 -0
- package/dist/tests/kubernetes/ConfigMapOperations.test.d.ts.map +1 -0
- package/dist/tests/kubernetes/ConfigMapOperations.test.js +460 -0
- package/dist/tests/kubernetes/ConfigMapOperations.test.js.map +1 -0
- package/dist/tests/kubernetes/ConnectionManager.test.d.ts +2 -0
- package/dist/tests/kubernetes/ConnectionManager.test.d.ts.map +1 -0
- package/dist/tests/kubernetes/ConnectionManager.test.js +97 -0
- package/dist/tests/kubernetes/ConnectionManager.test.js.map +1 -0
- package/dist/tests/kubernetes/ConnectionPool.test.d.ts +2 -0
- package/dist/tests/kubernetes/ConnectionPool.test.d.ts.map +1 -0
- package/dist/tests/kubernetes/ConnectionPool.test.js +328 -0
- package/dist/tests/kubernetes/ConnectionPool.test.js.map +1 -0
- package/dist/tests/kubernetes/DeploymentOperations.test.d.ts +2 -0
- package/dist/tests/kubernetes/DeploymentOperations.test.d.ts.map +1 -0
- package/dist/tests/kubernetes/DeploymentOperations.test.js +196 -0
- package/dist/tests/kubernetes/DeploymentOperations.test.js.map +1 -0
- package/dist/tests/kubernetes/ErrorHandling.test.d.ts +2 -0
- package/dist/tests/kubernetes/ErrorHandling.test.d.ts.map +1 -0
- package/dist/tests/kubernetes/ErrorHandling.test.js +329 -0
- package/dist/tests/kubernetes/ErrorHandling.test.js.map +1 -0
- package/dist/tests/kubernetes/GetPodMetricsTool.test.d.ts +2 -0
- package/dist/tests/kubernetes/GetPodMetricsTool.test.d.ts.map +1 -0
- package/dist/tests/kubernetes/GetPodMetricsTool.test.js +150 -0
- package/dist/tests/kubernetes/GetPodMetricsTool.test.js.map +1 -0
- package/dist/tests/kubernetes/KubernetesClient.test.d.ts +2 -0
- package/dist/tests/kubernetes/KubernetesClient.test.d.ts.map +1 -0
- package/dist/tests/kubernetes/KubernetesClient.test.js +371 -0
- package/dist/tests/kubernetes/KubernetesClient.test.js.map +1 -0
- package/dist/tests/kubernetes/MetricOperations.parsing.test.d.ts +2 -0
- package/dist/tests/kubernetes/MetricOperations.parsing.test.d.ts.map +1 -0
- package/dist/tests/kubernetes/MetricOperations.parsing.test.js +49 -0
- package/dist/tests/kubernetes/MetricOperations.parsing.test.js.map +1 -0
- package/dist/tests/kubernetes/NamespaceOperations.test.d.ts +2 -0
- package/dist/tests/kubernetes/NamespaceOperations.test.d.ts.map +1 -0
- package/dist/tests/kubernetes/NamespaceOperations.test.js +115 -0
- package/dist/tests/kubernetes/NamespaceOperations.test.js.map +1 -0
- package/dist/tests/kubernetes/PodOperations.test.d.ts +2 -0
- package/dist/tests/kubernetes/PodOperations.test.d.ts.map +1 -0
- package/dist/tests/kubernetes/PodOperations.test.js +209 -0
- package/dist/tests/kubernetes/PodOperations.test.js.map +1 -0
- package/dist/tests/kubernetes/RetryStrategy.test.d.ts +2 -0
- package/dist/tests/kubernetes/RetryStrategy.test.d.ts.map +1 -0
- package/dist/tests/kubernetes/RetryStrategy.test.js +419 -0
- package/dist/tests/kubernetes/RetryStrategy.test.js.map +1 -0
- package/dist/tests/kubernetes/ServiceOperations.test.d.ts +2 -0
- package/dist/tests/kubernetes/ServiceOperations.test.d.ts.map +1 -0
- package/dist/tests/kubernetes/ServiceOperations.test.js +159 -0
- package/dist/tests/kubernetes/ServiceOperations.test.js.map +1 -0
- package/dist/tests/plugins/KubernetesToolsPlugin.test.d.ts +2 -0
- package/dist/tests/plugins/KubernetesToolsPlugin.test.d.ts.map +1 -0
- package/dist/tests/plugins/KubernetesToolsPlugin.test.js +153 -0
- package/dist/tests/plugins/KubernetesToolsPlugin.test.js.map +1 -0
- package/dist/tests/server/MCPServer.integration.test.d.ts +2 -0
- package/dist/tests/server/MCPServer.integration.test.d.ts.map +1 -0
- package/dist/tests/server/MCPServer.integration.test.js +244 -0
- package/dist/tests/server/MCPServer.integration.test.js.map +1 -0
- package/dist/tests/server/MCPServer.test.d.ts +2 -0
- package/dist/tests/server/MCPServer.test.d.ts.map +1 -0
- package/dist/tests/server/MCPServer.test.js +257 -0
- package/dist/tests/server/MCPServer.test.js.map +1 -0
- package/package.json +85 -0
- package/src/cli/cli.ts +25 -0
- package/src/cli/run-command.js +391 -0
- package/src/index.ts +46 -0
- package/src/kubernetes/BaseResourceOperations.ts +286 -0
- package/src/kubernetes/CircuitBreaker.ts +485 -0
- package/src/kubernetes/ConnectionManager.ts +114 -0
- package/src/kubernetes/ConnectionPool.ts +551 -0
- package/src/kubernetes/ErrorHandler.ts +436 -0
- package/src/kubernetes/ErrorHandling.ts +401 -0
- package/src/kubernetes/KubernetesClient.ts +500 -0
- package/src/kubernetes/README.md +349 -0
- package/src/kubernetes/ResourceOperations.ts +116 -0
- package/src/kubernetes/RetryStrategy.ts +365 -0
- package/src/kubernetes/RetryableOperation.ts +313 -0
- package/src/kubernetes/docs/ResourceOperations.md +606 -0
- package/src/kubernetes/index.ts +116 -0
- package/src/kubernetes/resources/ConfigMapOperations.ts +367 -0
- package/src/kubernetes/resources/CustomResourceOperations.ts +392 -0
- package/src/kubernetes/resources/DeploymentOperations.ts +294 -0
- package/src/kubernetes/resources/IngressOperations.ts +277 -0
- package/src/kubernetes/resources/MetricOperations.ts +1159 -0
- package/src/kubernetes/resources/NamespaceOperations.ts +129 -0
- package/src/kubernetes/resources/PersistentVolumeClaimOperations.ts +516 -0
- package/src/kubernetes/resources/PersistentVolumeOperations.ts +438 -0
- package/src/kubernetes/resources/PodOperations.ts +417 -0
- package/src/kubernetes/resources/SecretOperations.ts +304 -0
- package/src/kubernetes/resources/ServiceOperations.ts +283 -0
- package/src/kubernetes/utils/ResourceUtils.ts +553 -0
- package/src/plugins/ArgoCDToolsPlugin.ts +189 -0
- package/src/plugins/ArgoToolsPlugin.ts +180 -0
- package/src/plugins/HelmToolsPlugin.ts +180 -0
- package/src/plugins/KubernetesToolsPlugin.ts +198 -0
- package/src/plugins/SamplePlugin.ts +60 -0
- package/src/plugins/index.ts +4 -0
- package/src/server/MCPServer.ts +500 -0
- package/src/tools/argo/ArgoCronListTool.ts +78 -0
- package/src/tools/argo/ArgoGetTool.ts +91 -0
- package/src/tools/argo/ArgoListTool.ts +143 -0
- package/src/tools/argo/ArgoLogsTool.ts +131 -0
- package/src/tools/argo/BaseTool.ts +69 -0
- package/src/tools/argo/index.ts +6 -0
- package/src/tools/argocd/ArgoCDAppGetTool.ts +109 -0
- package/src/tools/argocd/ArgoCDAppHistoryTool.ts +91 -0
- package/src/tools/argocd/ArgoCDAppListTool.ts +144 -0
- package/src/tools/argocd/ArgoCDAppLogsTool.ts +162 -0
- package/src/tools/argocd/ArgoCDAppResourcesTool.ts +139 -0
- package/src/tools/argocd/BaseTool.ts +83 -0
- package/src/tools/argocd/index.ts +7 -0
- package/src/tools/helm/BaseTool.ts +60 -0
- package/src/tools/helm/HelmGetHooksTool.ts +44 -0
- package/src/tools/helm/HelmGetManifestTool.ts +44 -0
- package/src/tools/helm/HelmGetNotesTool.ts +44 -0
- package/src/tools/helm/HelmGetResourcesTool.ts +140 -0
- package/src/tools/helm/HelmGetValuesTool.ts +62 -0
- package/src/tools/helm/HelmHistoryTool.ts +56 -0
- package/src/tools/helm/HelmListTool.ts +107 -0
- package/src/tools/helm/HelmListWithResourcesTool.ts +194 -0
- package/src/tools/helm/HelmStatusTool.ts +62 -0
- package/src/tools/helm/index.ts +11 -0
- package/src/tools/kubernetes/BaseTool.ts +76 -0
- package/src/tools/kubernetes/GetConfigMapTool.ts +33 -0
- package/src/tools/kubernetes/GetContainerLogsTool.ts +140 -0
- package/src/tools/kubernetes/GetDeploymentsTool.ts +33 -0
- package/src/tools/kubernetes/GetEventsTool.ts +133 -0
- package/src/tools/kubernetes/GetIngressTool.ts +39 -0
- package/src/tools/kubernetes/GetMetricsTool.ts +53 -0
- package/src/tools/kubernetes/GetNamespacesTool.ts +36 -0
- package/src/tools/kubernetes/GetPersistentVolumeClaimsTool.ts +113 -0
- package/src/tools/kubernetes/GetPersistentVolumesTool.ts +107 -0
- package/src/tools/kubernetes/GetPodMetricsTool.ts +113 -0
- package/src/tools/kubernetes/GetPodsTool.ts +39 -0
- package/src/tools/kubernetes/GetResourceTool.ts +90 -0
- package/src/tools/kubernetes/GetSecretsTool.ts +55 -0
- package/src/tools/kubernetes/GetServicesTool.ts +39 -0
- package/src/tools/kubernetes/index.ts +16 -0
- package/src/utils/CliUtils.ts +207 -0
- package/tsconfig.json +36 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
import { PodOperations } from '../../src/kubernetes/resources/PodOperations';
|
|
2
|
+
import * as k8s from '@kubernetes/client-node';
|
|
3
|
+
import { WatchEventType } from '../../src/kubernetes/BaseResourceOperations';
|
|
4
|
+
// Mock KubernetesClient and Watch
|
|
5
|
+
jest.mock('../../src/kubernetes/KubernetesClient');
|
|
6
|
+
jest.mock('@kubernetes/client-node', () => ({
|
|
7
|
+
...jest.requireActual('@kubernetes/client-node'),
|
|
8
|
+
Watch: jest.fn(),
|
|
9
|
+
}));
|
|
10
|
+
describe('PodOperations', () => {
|
|
11
|
+
let mockClient;
|
|
12
|
+
let podOperations;
|
|
13
|
+
let mockCoreV1Api;
|
|
14
|
+
let mockCustomObjectsApi;
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
// Reset all mocks
|
|
17
|
+
jest.clearAllMocks();
|
|
18
|
+
// Setup mock CoreV1Api
|
|
19
|
+
mockCoreV1Api = {
|
|
20
|
+
readNamespacedPod: jest.fn(),
|
|
21
|
+
listNamespacedPod: jest.fn(),
|
|
22
|
+
listPodForAllNamespaces: jest.fn(),
|
|
23
|
+
readNamespacedPodLog: jest.fn(),
|
|
24
|
+
};
|
|
25
|
+
// Setup mock CustomObjectsApi
|
|
26
|
+
mockCustomObjectsApi = {
|
|
27
|
+
getNamespacedCustomObject: jest.fn(),
|
|
28
|
+
};
|
|
29
|
+
// Setup mock client
|
|
30
|
+
mockClient = {
|
|
31
|
+
core: mockCoreV1Api,
|
|
32
|
+
kubeConfig: {
|
|
33
|
+
makeApiClient: jest.fn().mockReturnValue(mockCustomObjectsApi),
|
|
34
|
+
},
|
|
35
|
+
logger: {
|
|
36
|
+
error: jest.fn(),
|
|
37
|
+
},
|
|
38
|
+
config: {
|
|
39
|
+
logger: {
|
|
40
|
+
error: jest.fn(),
|
|
41
|
+
info: jest.fn(),
|
|
42
|
+
warn: jest.fn(),
|
|
43
|
+
debug: jest.fn(),
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
// Create PodOperations instance
|
|
48
|
+
podOperations = new PodOperations(mockClient);
|
|
49
|
+
});
|
|
50
|
+
describe('Read-only Operations', () => {
|
|
51
|
+
describe('get', () => {
|
|
52
|
+
it('should get a pod by name', async () => {
|
|
53
|
+
const mockPod = { metadata: { name: 'test-pod' } };
|
|
54
|
+
mockCoreV1Api.readNamespacedPod.mockResolvedValue(mockPod);
|
|
55
|
+
const result = await podOperations.get('test-pod', { namespace: 'default' });
|
|
56
|
+
expect(result).toBe(mockPod);
|
|
57
|
+
expect(mockCoreV1Api.readNamespacedPod).toHaveBeenCalledWith({
|
|
58
|
+
name: 'test-pod',
|
|
59
|
+
namespace: 'default',
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
it('should handle errors when getting a pod', async () => {
|
|
63
|
+
const error = new Error('Not found');
|
|
64
|
+
mockCoreV1Api.readNamespacedPod.mockRejectedValue(error);
|
|
65
|
+
await expect(podOperations.get('test-pod')).rejects.toThrow();
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
describe('list', () => {
|
|
69
|
+
it('should list pods in a namespace', async () => {
|
|
70
|
+
const mockPodList = { items: [{ metadata: { name: 'test-pod' } }] };
|
|
71
|
+
mockCoreV1Api.listNamespacedPod.mockResolvedValue(mockPodList);
|
|
72
|
+
const result = await podOperations.list({ namespace: 'default' });
|
|
73
|
+
expect(result).toBe(mockPodList);
|
|
74
|
+
expect(mockCoreV1Api.listNamespacedPod).toHaveBeenCalledWith(expect.objectContaining({
|
|
75
|
+
namespace: 'default',
|
|
76
|
+
}));
|
|
77
|
+
});
|
|
78
|
+
it('should list pods across all namespaces', async () => {
|
|
79
|
+
const mockPodList = { items: [{ metadata: { name: 'test-pod' } }] };
|
|
80
|
+
mockCoreV1Api.listPodForAllNamespaces.mockResolvedValue(mockPodList);
|
|
81
|
+
const result = await podOperations.list();
|
|
82
|
+
expect(result).toBe(mockPodList);
|
|
83
|
+
expect(mockCoreV1Api.listPodForAllNamespaces).toHaveBeenCalled();
|
|
84
|
+
});
|
|
85
|
+
it('should handle errors when listing pods', async () => {
|
|
86
|
+
const error = new Error('List failed');
|
|
87
|
+
mockCoreV1Api.listNamespacedPod.mockRejectedValue(error);
|
|
88
|
+
await expect(podOperations.list({ namespace: 'default' })).rejects.toThrow();
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
describe('watch', () => {
|
|
92
|
+
it('should watch pods for changes', async () => {
|
|
93
|
+
const mockCallback = jest.fn();
|
|
94
|
+
const abortFn = jest.fn();
|
|
95
|
+
const mockWatchInstance = {
|
|
96
|
+
watch: jest.fn().mockImplementation((_path, _opts, onData, _onError) => {
|
|
97
|
+
onData('ADDED', { metadata: { name: 'test-pod' } });
|
|
98
|
+
return { abort: abortFn };
|
|
99
|
+
}),
|
|
100
|
+
};
|
|
101
|
+
k8s.Watch.mockReturnValue(mockWatchInstance);
|
|
102
|
+
const cleanup = podOperations.watch(mockCallback, { namespace: 'default' });
|
|
103
|
+
// Wait for async startWatch to complete
|
|
104
|
+
await new Promise((r) => setImmediate(r));
|
|
105
|
+
cleanup();
|
|
106
|
+
expect(abortFn).toHaveBeenCalled();
|
|
107
|
+
});
|
|
108
|
+
it('should handle watch errors', () => {
|
|
109
|
+
const mockCallback = jest.fn();
|
|
110
|
+
const error = new Error('Watch error');
|
|
111
|
+
const mockWatchInstance = {
|
|
112
|
+
watch: jest.fn().mockImplementation((_path, _opts, _onData, onError) => {
|
|
113
|
+
onError(error);
|
|
114
|
+
return { abort: jest.fn() };
|
|
115
|
+
}),
|
|
116
|
+
};
|
|
117
|
+
k8s.Watch.mockImplementation(() => mockWatchInstance);
|
|
118
|
+
podOperations.watch(mockCallback, { namespace: 'default' });
|
|
119
|
+
expect(mockCallback).toHaveBeenCalledWith({
|
|
120
|
+
type: WatchEventType.ERROR,
|
|
121
|
+
object: error,
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
describe('getLogs', () => {
|
|
126
|
+
it('should get pod logs', async () => {
|
|
127
|
+
const mockLogs = 'test logs';
|
|
128
|
+
mockCoreV1Api.readNamespacedPodLog.mockResolvedValue(mockLogs);
|
|
129
|
+
const result = await podOperations.getLogs('test-pod', {
|
|
130
|
+
namespace: 'default',
|
|
131
|
+
container: 'test-container',
|
|
132
|
+
follow: true,
|
|
133
|
+
tailLines: 100,
|
|
134
|
+
previous: false,
|
|
135
|
+
timestamps: true,
|
|
136
|
+
});
|
|
137
|
+
expect(result).toBe(mockLogs);
|
|
138
|
+
expect(mockCoreV1Api.readNamespacedPodLog).toHaveBeenCalledWith({
|
|
139
|
+
name: 'test-pod',
|
|
140
|
+
namespace: 'default',
|
|
141
|
+
container: 'test-container',
|
|
142
|
+
follow: true,
|
|
143
|
+
tailLines: 100,
|
|
144
|
+
previous: false,
|
|
145
|
+
timestamps: true,
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
it('should handle errors when getting logs', async () => {
|
|
149
|
+
const error = new Error('Logs not available');
|
|
150
|
+
mockCoreV1Api.readNamespacedPodLog.mockRejectedValue(error);
|
|
151
|
+
await expect(podOperations.getLogs('test-pod')).rejects.toThrow();
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
describe('streamLogs', () => {
|
|
155
|
+
it('should stream pod logs', () => {
|
|
156
|
+
const mockLogs = 'test logs';
|
|
157
|
+
mockCoreV1Api.readNamespacedPodLog.mockResolvedValue(mockLogs);
|
|
158
|
+
const onData = jest.fn();
|
|
159
|
+
const cleanup = podOperations.streamLogs('test-pod', onData, {
|
|
160
|
+
namespace: 'default',
|
|
161
|
+
container: 'test-container',
|
|
162
|
+
follow: true,
|
|
163
|
+
});
|
|
164
|
+
expect(mockCoreV1Api.readNamespacedPodLog).toHaveBeenCalledWith({
|
|
165
|
+
name: 'test-pod',
|
|
166
|
+
namespace: 'default',
|
|
167
|
+
container: 'test-container',
|
|
168
|
+
follow: true,
|
|
169
|
+
});
|
|
170
|
+
cleanup();
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
describe('getMetrics', () => {
|
|
174
|
+
it('should get pod metrics', async () => {
|
|
175
|
+
const mockMetrics = { usage: { cpu: '100m', memory: '100Mi' } };
|
|
176
|
+
mockCustomObjectsApi.getNamespacedCustomObject.mockResolvedValue(mockMetrics);
|
|
177
|
+
const result = await podOperations.getMetrics('test-pod', { namespace: 'default' });
|
|
178
|
+
expect(result).toBe(mockMetrics);
|
|
179
|
+
expect(mockCustomObjectsApi.getNamespacedCustomObject).toHaveBeenCalledWith({
|
|
180
|
+
group: 'metrics.k8s.io',
|
|
181
|
+
version: 'v1beta1',
|
|
182
|
+
namespace: 'default',
|
|
183
|
+
plural: 'pods',
|
|
184
|
+
name: 'test-pod',
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
it('should handle errors when getting metrics', async () => {
|
|
188
|
+
const error = new Error('Metrics not available');
|
|
189
|
+
mockCustomObjectsApi.getNamespacedCustomObject.mockRejectedValue(error);
|
|
190
|
+
await expect(podOperations.getMetrics('test-pod')).rejects.toThrow();
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
describe('Unsupported Operations', () => {
|
|
195
|
+
it('should throw error for create operation', async () => {
|
|
196
|
+
await expect(podOperations.create({})).rejects.toThrow('Create operation is not supported in read-only mode');
|
|
197
|
+
});
|
|
198
|
+
it('should throw error for update operation', async () => {
|
|
199
|
+
await expect(podOperations.update({})).rejects.toThrow('Update operation is not supported in read-only mode');
|
|
200
|
+
});
|
|
201
|
+
it('should throw error for patch operation', async () => {
|
|
202
|
+
await expect(podOperations.patch('test-pod', {})).rejects.toThrow('Patch operation is not supported in read-only mode');
|
|
203
|
+
});
|
|
204
|
+
it('should throw error for delete operation', async () => {
|
|
205
|
+
await expect(podOperations.delete('test-pod')).rejects.toThrow('Delete operation is not supported in read-only mode');
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
});
|
|
209
|
+
//# sourceMappingURL=PodOperations.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PodOperations.test.js","sourceRoot":"","sources":["../../../tests/kubernetes/PodOperations.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,8CAA8C,CAAC;AAE7E,OAAO,KAAK,GAAG,MAAM,yBAAyB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,6CAA6C,CAAC;AAE7E,kCAAkC;AAClC,IAAI,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAC;AACnD,IAAI,CAAC,IAAI,CAAC,yBAAyB,EAAE,GAAG,EAAE,CAAC,CAAC;IAC1C,GAAG,IAAI,CAAC,aAAa,CAAC,yBAAyB,CAAC;IAChD,KAAK,EAAE,IAAI,CAAC,EAAE,EAAE;CACjB,CAAC,CAAC,CAAC;AAEJ,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,IAAI,UAAyC,CAAC;IAC9C,IAAI,aAA4B,CAAC;IACjC,IAAI,aAAyC,CAAC;IAC9C,IAAI,oBAAuD,CAAC;IAE5D,UAAU,CAAC,GAAG,EAAE;QACd,kBAAkB;QAClB,IAAI,CAAC,aAAa,EAAE,CAAC;QAErB,uBAAuB;QACvB,aAAa,GAAG;YACd,iBAAiB,EAAE,IAAI,CAAC,EAAE,EAAE;YAC5B,iB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,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RetryStrategy.test.d.ts","sourceRoot":"","sources":["../../../tests/kubernetes/RetryStrategy.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,419 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
+
};
|
|
10
|
+
import { RetryStrategy, RetryBuilder, RETRY_PRESETS, Retryable, } from '../../src/kubernetes/RetryStrategy';
|
|
11
|
+
import { KubernetesError, NetworkError, TimeoutError } from '../../src/kubernetes/ErrorHandling';
|
|
12
|
+
describe('RetryStrategy', () => {
|
|
13
|
+
describe('Basic Retry Operations', () => {
|
|
14
|
+
it('should succeed on first attempt', async () => {
|
|
15
|
+
const strategy = new RetryStrategy({ maxAttempts: 3 });
|
|
16
|
+
let attempts = 0;
|
|
17
|
+
const result = await strategy.execute(async () => {
|
|
18
|
+
attempts++;
|
|
19
|
+
return 'success';
|
|
20
|
+
});
|
|
21
|
+
expect(result.success).toBe(true);
|
|
22
|
+
expect(result.value).toBe('success');
|
|
23
|
+
expect(result.attempts).toBe(1);
|
|
24
|
+
expect(attempts).toBe(1);
|
|
25
|
+
});
|
|
26
|
+
it('should retry on failure and succeed', async () => {
|
|
27
|
+
const strategy = new RetryStrategy({
|
|
28
|
+
maxAttempts: 3,
|
|
29
|
+
initialDelayMs: 10,
|
|
30
|
+
jitterFactor: 0,
|
|
31
|
+
isRetryable: () => true,
|
|
32
|
+
});
|
|
33
|
+
let attempts = 0;
|
|
34
|
+
const result = await strategy.execute(async () => {
|
|
35
|
+
attempts++;
|
|
36
|
+
if (attempts < 3) {
|
|
37
|
+
throw new Error('Temporary failure');
|
|
38
|
+
}
|
|
39
|
+
return 'success';
|
|
40
|
+
});
|
|
41
|
+
expect(result.success).toBe(true);
|
|
42
|
+
expect(result.value).toBe('success');
|
|
43
|
+
expect(result.attempts).toBe(3);
|
|
44
|
+
expect(attempts).toBe(3);
|
|
45
|
+
});
|
|
46
|
+
it('should fail after max attempts', async () => {
|
|
47
|
+
const strategy = new RetryStrategy({
|
|
48
|
+
maxAttempts: 3,
|
|
49
|
+
initialDelayMs: 10,
|
|
50
|
+
jitterFactor: 0,
|
|
51
|
+
isRetryable: () => true,
|
|
52
|
+
});
|
|
53
|
+
let attempts = 0;
|
|
54
|
+
const result = await strategy.execute(async () => {
|
|
55
|
+
attempts++;
|
|
56
|
+
throw new Error(`Failure ${attempts}`);
|
|
57
|
+
});
|
|
58
|
+
expect(result.success).toBe(false);
|
|
59
|
+
expect(result.error).toBeInstanceOf(Error);
|
|
60
|
+
expect(result.error.message).toBe('Failure 3');
|
|
61
|
+
expect(result.attempts).toBe(3);
|
|
62
|
+
expect(attempts).toBe(3);
|
|
63
|
+
});
|
|
64
|
+
it('should not retry non-retryable errors', async () => {
|
|
65
|
+
const strategy = new RetryStrategy({
|
|
66
|
+
maxAttempts: 3,
|
|
67
|
+
initialDelayMs: 10,
|
|
68
|
+
});
|
|
69
|
+
let attempts = 0;
|
|
70
|
+
const result = await strategy.execute(async () => {
|
|
71
|
+
attempts++;
|
|
72
|
+
throw new KubernetesError('Auth failed', 'AUTH_ERROR', 401, false);
|
|
73
|
+
});
|
|
74
|
+
expect(result.success).toBe(false);
|
|
75
|
+
expect(result.attempts).toBe(1);
|
|
76
|
+
expect(attempts).toBe(1);
|
|
77
|
+
});
|
|
78
|
+
it('should retry retryable Kubernetes errors', async () => {
|
|
79
|
+
const strategy = new RetryStrategy({
|
|
80
|
+
maxAttempts: 3,
|
|
81
|
+
initialDelayMs: 10,
|
|
82
|
+
jitterFactor: 0,
|
|
83
|
+
});
|
|
84
|
+
let attempts = 0;
|
|
85
|
+
const result = await strategy.execute(async () => {
|
|
86
|
+
attempts++;
|
|
87
|
+
if (attempts < 2) {
|
|
88
|
+
throw new NetworkError('Network issue');
|
|
89
|
+
}
|
|
90
|
+
return 'recovered';
|
|
91
|
+
});
|
|
92
|
+
expect(result.success).toBe(true);
|
|
93
|
+
expect(result.value).toBe('recovered');
|
|
94
|
+
expect(result.attempts).toBe(2);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
describe('Exponential Backoff', () => {
|
|
98
|
+
it('should apply exponential backoff', async () => {
|
|
99
|
+
const delays = [];
|
|
100
|
+
const strategy = new RetryStrategy({
|
|
101
|
+
maxAttempts: 4,
|
|
102
|
+
initialDelayMs: 100,
|
|
103
|
+
backoffMultiplier: 2,
|
|
104
|
+
jitterFactor: 0,
|
|
105
|
+
onRetry: (_attempt, _error, nextDelay) => {
|
|
106
|
+
delays.push(nextDelay);
|
|
107
|
+
},
|
|
108
|
+
isRetryable: () => true,
|
|
109
|
+
});
|
|
110
|
+
await strategy.execute(async () => {
|
|
111
|
+
throw new Error('Always fails');
|
|
112
|
+
});
|
|
113
|
+
expect(delays).toHaveLength(3); // 3 retries after initial attempt
|
|
114
|
+
expect(delays[0]).toBe(100); // 100ms
|
|
115
|
+
expect(delays[1]).toBe(200); // 100 * 2
|
|
116
|
+
expect(delays[2]).toBe(400); // 100 * 2^2
|
|
117
|
+
});
|
|
118
|
+
it('should respect maxDelayMs', async () => {
|
|
119
|
+
const delays = [];
|
|
120
|
+
const strategy = new RetryStrategy({
|
|
121
|
+
maxAttempts: 5,
|
|
122
|
+
initialDelayMs: 100,
|
|
123
|
+
maxDelayMs: 300,
|
|
124
|
+
backoffMultiplier: 2,
|
|
125
|
+
jitterFactor: 0,
|
|
126
|
+
onRetry: (_attempt, _error, nextDelay) => {
|
|
127
|
+
delays.push(nextDelay);
|
|
128
|
+
},
|
|
129
|
+
isRetryable: () => true,
|
|
130
|
+
});
|
|
131
|
+
await strategy.execute(async () => {
|
|
132
|
+
throw new Error('Always fails');
|
|
133
|
+
});
|
|
134
|
+
expect(delays[0]).toBe(100);
|
|
135
|
+
expect(delays[1]).toBe(200);
|
|
136
|
+
expect(delays[2]).toBe(300); // Capped at maxDelayMs
|
|
137
|
+
expect(delays[3]).toBe(300); // Still capped
|
|
138
|
+
});
|
|
139
|
+
it('should apply jitter', async () => {
|
|
140
|
+
const delays = [];
|
|
141
|
+
const strategy = new RetryStrategy({
|
|
142
|
+
maxAttempts: 3,
|
|
143
|
+
initialDelayMs: 1000,
|
|
144
|
+
jitterFactor: 0.5,
|
|
145
|
+
onRetry: (_attempt, _error, nextDelay) => {
|
|
146
|
+
delays.push(nextDelay);
|
|
147
|
+
},
|
|
148
|
+
isRetryable: () => true,
|
|
149
|
+
});
|
|
150
|
+
await strategy.execute(async () => {
|
|
151
|
+
throw new Error('Always fails');
|
|
152
|
+
});
|
|
153
|
+
// With 0.5 jitter factor, delay should be between 500ms and 1500ms
|
|
154
|
+
expect(delays[0]).toBeGreaterThanOrEqual(500);
|
|
155
|
+
expect(delays[0]).toBeLessThanOrEqual(1500);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
describe('Timeout Handling', () => {
|
|
159
|
+
it('should timeout long-running operations', async () => {
|
|
160
|
+
const strategy = new RetryStrategy({
|
|
161
|
+
maxAttempts: 1,
|
|
162
|
+
timeoutMs: 100,
|
|
163
|
+
isRetryable: () => true,
|
|
164
|
+
});
|
|
165
|
+
const result = await strategy.execute(async () => {
|
|
166
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
167
|
+
return 'should not reach';
|
|
168
|
+
});
|
|
169
|
+
expect(result.success).toBe(false);
|
|
170
|
+
expect(result.error).toBeInstanceOf(Error);
|
|
171
|
+
expect(result.error.message).toContain('timed out');
|
|
172
|
+
});
|
|
173
|
+
it('should stop retrying when total timeout exceeded', async () => {
|
|
174
|
+
let attempts = 0;
|
|
175
|
+
const strategy = new RetryStrategy({
|
|
176
|
+
maxAttempts: 10,
|
|
177
|
+
initialDelayMs: 100,
|
|
178
|
+
timeoutMs: 250, // Total timeout
|
|
179
|
+
jitterFactor: 0,
|
|
180
|
+
});
|
|
181
|
+
const result = await strategy.execute(async () => {
|
|
182
|
+
attempts++;
|
|
183
|
+
throw new Error('Retry me');
|
|
184
|
+
});
|
|
185
|
+
expect(result.success).toBe(false);
|
|
186
|
+
expect(attempts).toBeLessThan(10); // Should stop before max attempts
|
|
187
|
+
expect(result.totalTimeMs).toBeLessThanOrEqual(300); // Some buffer for execution
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
describe('Custom Retry Logic', () => {
|
|
191
|
+
it('should use custom isRetryable function', async () => {
|
|
192
|
+
let attempts = 0;
|
|
193
|
+
const strategy = new RetryStrategy({
|
|
194
|
+
maxAttempts: 3,
|
|
195
|
+
initialDelayMs: 10,
|
|
196
|
+
isRetryable: (error) => {
|
|
197
|
+
return error.message.includes('retry');
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
// Should retry
|
|
201
|
+
const result1 = await strategy.execute(async () => {
|
|
202
|
+
attempts++;
|
|
203
|
+
if (attempts < 2) {
|
|
204
|
+
throw new Error('Please retry this');
|
|
205
|
+
}
|
|
206
|
+
return 'success';
|
|
207
|
+
});
|
|
208
|
+
expect(result1.success).toBe(true);
|
|
209
|
+
expect(attempts).toBe(2);
|
|
210
|
+
// Should not retry
|
|
211
|
+
attempts = 0;
|
|
212
|
+
const result2 = await strategy.execute(async () => {
|
|
213
|
+
attempts++;
|
|
214
|
+
throw new Error('Do not attempt again');
|
|
215
|
+
});
|
|
216
|
+
expect(result2.success).toBe(false);
|
|
217
|
+
expect(attempts).toBe(1);
|
|
218
|
+
});
|
|
219
|
+
it('should call onRetry callback', async () => {
|
|
220
|
+
const retryEvents = [];
|
|
221
|
+
const strategy = new RetryStrategy({
|
|
222
|
+
maxAttempts: 3,
|
|
223
|
+
initialDelayMs: 10,
|
|
224
|
+
jitterFactor: 0,
|
|
225
|
+
onRetry: (_attempt, _error, nextDelay) => {
|
|
226
|
+
retryEvents.push({
|
|
227
|
+
attempt: _attempt,
|
|
228
|
+
error: _error.message,
|
|
229
|
+
nextDelay,
|
|
230
|
+
});
|
|
231
|
+
},
|
|
232
|
+
isRetryable: () => true,
|
|
233
|
+
});
|
|
234
|
+
await strategy.execute(async () => {
|
|
235
|
+
throw new Error('Failure');
|
|
236
|
+
});
|
|
237
|
+
expect(retryEvents).toHaveLength(2); // 2 retries after initial
|
|
238
|
+
expect(retryEvents[0].attempt).toBe(1);
|
|
239
|
+
expect(retryEvents[0].error).toBe('Failure');
|
|
240
|
+
expect(retryEvents[1].attempt).toBe(2);
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
describe('Retry Presets', () => {
|
|
244
|
+
it('should use FAST preset', async () => {
|
|
245
|
+
const strategy = new RetryStrategy(RETRY_PRESETS.FAST);
|
|
246
|
+
const start = Date.now();
|
|
247
|
+
await strategy.execute(async () => {
|
|
248
|
+
throw new Error('Fast fail');
|
|
249
|
+
});
|
|
250
|
+
const duration = Date.now() - start;
|
|
251
|
+
expect(duration).toBeLessThan(2000); // Fast preset should complete quickly
|
|
252
|
+
});
|
|
253
|
+
it('should use AGGRESSIVE preset', async () => {
|
|
254
|
+
const strategy = new RetryStrategy({ ...RETRY_PRESETS.AGGRESSIVE, isRetryable: () => true });
|
|
255
|
+
let attempts = 0;
|
|
256
|
+
await strategy.execute(async () => {
|
|
257
|
+
attempts++;
|
|
258
|
+
throw new Error('Need many retries');
|
|
259
|
+
});
|
|
260
|
+
expect(attempts).toBe(5); // Aggressive preset has 5 max attempts
|
|
261
|
+
}, 20000);
|
|
262
|
+
it('should use NONE preset', async () => {
|
|
263
|
+
const strategy = new RetryStrategy(RETRY_PRESETS.NONE);
|
|
264
|
+
let attempts = 0;
|
|
265
|
+
const result = await strategy.execute(async () => {
|
|
266
|
+
attempts++;
|
|
267
|
+
throw new Error('No retry');
|
|
268
|
+
});
|
|
269
|
+
expect(result.success).toBe(false);
|
|
270
|
+
expect(attempts).toBe(1); // No retries
|
|
271
|
+
});
|
|
272
|
+
});
|
|
273
|
+
describe('RetryBuilder', () => {
|
|
274
|
+
it('should build retry strategy with fluent API', async () => {
|
|
275
|
+
const strategy = new RetryBuilder()
|
|
276
|
+
.withMaxAttempts(2)
|
|
277
|
+
.withInitialDelay(50)
|
|
278
|
+
.withMaxDelay(100)
|
|
279
|
+
.withBackoffMultiplier(2)
|
|
280
|
+
.withJitterFactor(0)
|
|
281
|
+
.withTimeout(1000)
|
|
282
|
+
.withRetryableCheck(() => true)
|
|
283
|
+
.build();
|
|
284
|
+
let attempts = 0;
|
|
285
|
+
const result = await strategy.execute(async () => {
|
|
286
|
+
attempts++;
|
|
287
|
+
if (attempts < 2) {
|
|
288
|
+
throw new Error('Retry once');
|
|
289
|
+
}
|
|
290
|
+
return 'built';
|
|
291
|
+
});
|
|
292
|
+
expect(result.success).toBe(true);
|
|
293
|
+
expect(result.value).toBe('built');
|
|
294
|
+
expect(attempts).toBe(2);
|
|
295
|
+
});
|
|
296
|
+
it('should build with preset', async () => {
|
|
297
|
+
const strategy = new RetryBuilder()
|
|
298
|
+
.withPreset('FAST')
|
|
299
|
+
.withMaxAttempts(2) // Override preset
|
|
300
|
+
.withRetryableCheck(() => true)
|
|
301
|
+
.build();
|
|
302
|
+
let attempts = 0;
|
|
303
|
+
await strategy.execute(async () => {
|
|
304
|
+
attempts++;
|
|
305
|
+
throw new Error('Fail');
|
|
306
|
+
});
|
|
307
|
+
expect(attempts).toBe(2); // Our override
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
describe('Wrap Function', () => {
|
|
311
|
+
it('should wrap function with retry logic', async () => {
|
|
312
|
+
const strategy = new RetryStrategy({
|
|
313
|
+
maxAttempts: 3,
|
|
314
|
+
initialDelayMs: 10,
|
|
315
|
+
isRetryable: () => true,
|
|
316
|
+
});
|
|
317
|
+
let attempts = 0;
|
|
318
|
+
const unreliableFunction = async (value) => {
|
|
319
|
+
attempts++;
|
|
320
|
+
if (attempts < 2) {
|
|
321
|
+
throw new Error('Temporary issue');
|
|
322
|
+
}
|
|
323
|
+
return `Processed: ${value}`;
|
|
324
|
+
};
|
|
325
|
+
const reliableFunction = strategy.wrap(unreliableFunction);
|
|
326
|
+
const result = await reliableFunction('test');
|
|
327
|
+
expect(result).toBe('Processed: test');
|
|
328
|
+
expect(attempts).toBe(2);
|
|
329
|
+
});
|
|
330
|
+
it('should throw on wrapped function failure', async () => {
|
|
331
|
+
const strategy = new RetryStrategy({
|
|
332
|
+
maxAttempts: 2,
|
|
333
|
+
initialDelayMs: 10,
|
|
334
|
+
});
|
|
335
|
+
const alwaysFails = async () => {
|
|
336
|
+
throw new Error('Permanent failure');
|
|
337
|
+
};
|
|
338
|
+
const wrapped = strategy.wrap(alwaysFails);
|
|
339
|
+
await expect(wrapped()).rejects.toThrow('Permanent failure');
|
|
340
|
+
});
|
|
341
|
+
});
|
|
342
|
+
describe('Retryable Decorator', () => {
|
|
343
|
+
it('should make method retryable', async () => {
|
|
344
|
+
class TestService {
|
|
345
|
+
attempts = 0;
|
|
346
|
+
async unreliableMethod() {
|
|
347
|
+
this.attempts++;
|
|
348
|
+
if (this.attempts < 2) {
|
|
349
|
+
throw new TimeoutError('Timeout');
|
|
350
|
+
}
|
|
351
|
+
return 'success';
|
|
352
|
+
}
|
|
353
|
+
async noRetryMethod() {
|
|
354
|
+
this.attempts++;
|
|
355
|
+
throw new Error('Should not retry');
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
__decorate([
|
|
359
|
+
Retryable({
|
|
360
|
+
maxAttempts: 3,
|
|
361
|
+
initialDelayMs: 10,
|
|
362
|
+
jitterFactor: 0,
|
|
363
|
+
}),
|
|
364
|
+
__metadata("design:type", Function),
|
|
365
|
+
__metadata("design:paramtypes", []),
|
|
366
|
+
__metadata("design:returntype", Promise)
|
|
367
|
+
], TestService.prototype, "unreliableMethod", null);
|
|
368
|
+
__decorate([
|
|
369
|
+
Retryable(RETRY_PRESETS.NONE),
|
|
370
|
+
__metadata("design:type", Function),
|
|
371
|
+
__metadata("design:paramtypes", []),
|
|
372
|
+
__metadata("design:returntype", Promise)
|
|
373
|
+
], TestService.prototype, "noRetryMethod", null);
|
|
374
|
+
const service = new TestService();
|
|
375
|
+
// Test retryable method
|
|
376
|
+
const result = await service.unreliableMethod();
|
|
377
|
+
expect(result).toBe('success');
|
|
378
|
+
expect(service.attempts).toBe(2);
|
|
379
|
+
// Test no-retry method
|
|
380
|
+
service.attempts = 0;
|
|
381
|
+
await expect(service.noRetryMethod()).rejects.toThrow('Should not retry');
|
|
382
|
+
expect(service.attempts).toBe(1);
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
describe('Error Type Detection', () => {
|
|
386
|
+
it('should retry on network-related error messages', async () => {
|
|
387
|
+
const networkErrors = [
|
|
388
|
+
'ECONNREFUSED: Connection refused',
|
|
389
|
+
'ENOTFOUND: DNS lookup failed',
|
|
390
|
+
'ETIMEDOUT: Request timed out',
|
|
391
|
+
'ECONNRESET: Connection reset',
|
|
392
|
+
'EPIPE: Broken pipe',
|
|
393
|
+
'Network error occurred',
|
|
394
|
+
'Request timeout',
|
|
395
|
+
'socket hang up',
|
|
396
|
+
'Service Unavailable',
|
|
397
|
+
'Bad Gateway',
|
|
398
|
+
'Gateway Timeout',
|
|
399
|
+
];
|
|
400
|
+
for (const errorMessage of networkErrors) {
|
|
401
|
+
const strategy = new RetryStrategy({
|
|
402
|
+
maxAttempts: 2,
|
|
403
|
+
initialDelayMs: 1,
|
|
404
|
+
});
|
|
405
|
+
let attempts = 0;
|
|
406
|
+
const result = await strategy.execute(async () => {
|
|
407
|
+
attempts++;
|
|
408
|
+
if (attempts < 2) {
|
|
409
|
+
throw new Error(errorMessage);
|
|
410
|
+
}
|
|
411
|
+
return 'recovered';
|
|
412
|
+
});
|
|
413
|
+
expect(result.success).toBe(true);
|
|
414
|
+
expect(attempts).toBe(2);
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
});
|
|
419
|
+
//# sourceMappingURL=RetryStrategy.test.js.map
|