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.
Files changed (454) hide show
  1. package/.prettierrc.json +11 -0
  2. package/CHANGELOG.md +55 -0
  3. package/LICENSE +21 -0
  4. package/README.md +251 -0
  5. package/RELEASE.md +154 -0
  6. package/TODO.md +0 -0
  7. package/bin/kubeview-mcp.js +274 -0
  8. package/bin/setup.js +368 -0
  9. package/dist/src/cli/cli.d.ts +3 -0
  10. package/dist/src/cli/cli.d.ts.map +1 -0
  11. package/dist/src/cli/cli.js +23 -0
  12. package/dist/src/cli/cli.js.map +1 -0
  13. package/dist/src/index.d.ts +8 -0
  14. package/dist/src/index.d.ts.map +1 -0
  15. package/dist/src/index.js +45 -0
  16. package/dist/src/index.js.map +1 -0
  17. package/dist/src/kubernetes/BaseResourceOperations.d.ts +155 -0
  18. package/dist/src/kubernetes/BaseResourceOperations.d.ts.map +1 -0
  19. package/dist/src/kubernetes/BaseResourceOperations.js +136 -0
  20. package/dist/src/kubernetes/BaseResourceOperations.js.map +1 -0
  21. package/dist/src/kubernetes/CircuitBreaker.d.ts +182 -0
  22. package/dist/src/kubernetes/CircuitBreaker.d.ts.map +1 -0
  23. package/dist/src/kubernetes/CircuitBreaker.js +369 -0
  24. package/dist/src/kubernetes/CircuitBreaker.js.map +1 -0
  25. package/dist/src/kubernetes/ConnectionManager.d.ts +60 -0
  26. package/dist/src/kubernetes/ConnectionManager.d.ts.map +1 -0
  27. package/dist/src/kubernetes/ConnectionManager.js +77 -0
  28. package/dist/src/kubernetes/ConnectionManager.js.map +1 -0
  29. package/dist/src/kubernetes/ConnectionPool.d.ts +183 -0
  30. package/dist/src/kubernetes/ConnectionPool.d.ts.map +1 -0
  31. package/dist/src/kubernetes/ConnectionPool.js +437 -0
  32. package/dist/src/kubernetes/ConnectionPool.js.map +1 -0
  33. package/dist/src/kubernetes/ErrorHandler.d.ts +172 -0
  34. package/dist/src/kubernetes/ErrorHandler.d.ts.map +1 -0
  35. package/dist/src/kubernetes/ErrorHandler.js +328 -0
  36. package/dist/src/kubernetes/ErrorHandler.js.map +1 -0
  37. package/dist/src/kubernetes/ErrorHandling.d.ts +148 -0
  38. package/dist/src/kubernetes/ErrorHandling.d.ts.map +1 -0
  39. package/dist/src/kubernetes/ErrorHandling.js +304 -0
  40. package/dist/src/kubernetes/ErrorHandling.js.map +1 -0
  41. package/dist/src/kubernetes/KubernetesClient.d.ts +162 -0
  42. package/dist/src/kubernetes/KubernetesClient.d.ts.map +1 -0
  43. package/dist/src/kubernetes/KubernetesClient.js +382 -0
  44. package/dist/src/kubernetes/KubernetesClient.js.map +1 -0
  45. package/dist/src/kubernetes/ResourceOperations.d.ts +69 -0
  46. package/dist/src/kubernetes/ResourceOperations.d.ts.map +1 -0
  47. package/dist/src/kubernetes/ResourceOperations.js +99 -0
  48. package/dist/src/kubernetes/ResourceOperations.js.map +1 -0
  49. package/dist/src/kubernetes/RetryStrategy.d.ts +137 -0
  50. package/dist/src/kubernetes/RetryStrategy.d.ts.map +1 -0
  51. package/dist/src/kubernetes/RetryStrategy.js +277 -0
  52. package/dist/src/kubernetes/RetryStrategy.js.map +1 -0
  53. package/dist/src/kubernetes/RetryableOperation.d.ts +118 -0
  54. package/dist/src/kubernetes/RetryableOperation.d.ts.map +1 -0
  55. package/dist/src/kubernetes/RetryableOperation.js +233 -0
  56. package/dist/src/kubernetes/RetryableOperation.js.map +1 -0
  57. package/dist/src/kubernetes/index.d.ts +18 -0
  58. package/dist/src/kubernetes/index.d.ts.map +1 -0
  59. package/dist/src/kubernetes/index.js +28 -0
  60. package/dist/src/kubernetes/index.js.map +1 -0
  61. package/dist/src/kubernetes/resources/ConfigMapOperations.d.ts +60 -0
  62. package/dist/src/kubernetes/resources/ConfigMapOperations.d.ts.map +1 -0
  63. package/dist/src/kubernetes/resources/ConfigMapOperations.js +306 -0
  64. package/dist/src/kubernetes/resources/ConfigMapOperations.js.map +1 -0
  65. package/dist/src/kubernetes/resources/CustomResourceOperations.d.ts +55 -0
  66. package/dist/src/kubernetes/resources/CustomResourceOperations.d.ts.map +1 -0
  67. package/dist/src/kubernetes/resources/CustomResourceOperations.js +363 -0
  68. package/dist/src/kubernetes/resources/CustomResourceOperations.js.map +1 -0
  69. package/dist/src/kubernetes/resources/DeploymentOperations.d.ts +66 -0
  70. package/dist/src/kubernetes/resources/DeploymentOperations.d.ts.map +1 -0
  71. package/dist/src/kubernetes/resources/DeploymentOperations.js +234 -0
  72. package/dist/src/kubernetes/resources/DeploymentOperations.js.map +1 -0
  73. package/dist/src/kubernetes/resources/IngressOperations.d.ts +60 -0
  74. package/dist/src/kubernetes/resources/IngressOperations.d.ts.map +1 -0
  75. package/dist/src/kubernetes/resources/IngressOperations.js +224 -0
  76. package/dist/src/kubernetes/resources/IngressOperations.js.map +1 -0
  77. package/dist/src/kubernetes/resources/MetricOperations.d.ts +218 -0
  78. package/dist/src/kubernetes/resources/MetricOperations.d.ts.map +1 -0
  79. package/dist/src/kubernetes/resources/MetricOperations.js +893 -0
  80. package/dist/src/kubernetes/resources/MetricOperations.js.map +1 -0
  81. package/dist/src/kubernetes/resources/NamespaceOperations.d.ts +38 -0
  82. package/dist/src/kubernetes/resources/NamespaceOperations.d.ts.map +1 -0
  83. package/dist/src/kubernetes/resources/NamespaceOperations.js +101 -0
  84. package/dist/src/kubernetes/resources/NamespaceOperations.js.map +1 -0
  85. package/dist/src/kubernetes/resources/PersistentVolumeClaimOperations.d.ts +109 -0
  86. package/dist/src/kubernetes/resources/PersistentVolumeClaimOperations.d.ts.map +1 -0
  87. package/dist/src/kubernetes/resources/PersistentVolumeClaimOperations.js +383 -0
  88. package/dist/src/kubernetes/resources/PersistentVolumeClaimOperations.js.map +1 -0
  89. package/dist/src/kubernetes/resources/PersistentVolumeOperations.d.ts +97 -0
  90. package/dist/src/kubernetes/resources/PersistentVolumeOperations.d.ts.map +1 -0
  91. package/dist/src/kubernetes/resources/PersistentVolumeOperations.js +321 -0
  92. package/dist/src/kubernetes/resources/PersistentVolumeOperations.js.map +1 -0
  93. package/dist/src/kubernetes/resources/PodOperations.d.ts +99 -0
  94. package/dist/src/kubernetes/resources/PodOperations.d.ts.map +1 -0
  95. package/dist/src/kubernetes/resources/PodOperations.js +333 -0
  96. package/dist/src/kubernetes/resources/PodOperations.js.map +1 -0
  97. package/dist/src/kubernetes/resources/SecretOperations.d.ts +71 -0
  98. package/dist/src/kubernetes/resources/SecretOperations.d.ts.map +1 -0
  99. package/dist/src/kubernetes/resources/SecretOperations.js +254 -0
  100. package/dist/src/kubernetes/resources/SecretOperations.js.map +1 -0
  101. package/dist/src/kubernetes/resources/ServiceOperations.d.ts +64 -0
  102. package/dist/src/kubernetes/resources/ServiceOperations.d.ts.map +1 -0
  103. package/dist/src/kubernetes/resources/ServiceOperations.js +232 -0
  104. package/dist/src/kubernetes/resources/ServiceOperations.js.map +1 -0
  105. package/dist/src/kubernetes/utils/ResourceUtils.d.ts +238 -0
  106. package/dist/src/kubernetes/utils/ResourceUtils.d.ts.map +1 -0
  107. package/dist/src/kubernetes/utils/ResourceUtils.js +439 -0
  108. package/dist/src/kubernetes/utils/ResourceUtils.js.map +1 -0
  109. package/dist/src/plugins/ArgoCDToolsPlugin.d.ts +45 -0
  110. package/dist/src/plugins/ArgoCDToolsPlugin.d.ts.map +1 -0
  111. package/dist/src/plugins/ArgoCDToolsPlugin.js +155 -0
  112. package/dist/src/plugins/ArgoCDToolsPlugin.js.map +1 -0
  113. package/dist/src/plugins/ArgoToolsPlugin.d.ts +45 -0
  114. package/dist/src/plugins/ArgoToolsPlugin.d.ts.map +1 -0
  115. package/dist/src/plugins/ArgoToolsPlugin.js +149 -0
  116. package/dist/src/plugins/ArgoToolsPlugin.js.map +1 -0
  117. package/dist/src/plugins/HelmToolsPlugin.d.ts +41 -0
  118. package/dist/src/plugins/HelmToolsPlugin.d.ts.map +1 -0
  119. package/dist/src/plugins/HelmToolsPlugin.js +146 -0
  120. package/dist/src/plugins/HelmToolsPlugin.js.map +1 -0
  121. package/dist/src/plugins/KubernetesToolsPlugin.d.ts +44 -0
  122. package/dist/src/plugins/KubernetesToolsPlugin.d.ts.map +1 -0
  123. package/dist/src/plugins/KubernetesToolsPlugin.js +159 -0
  124. package/dist/src/plugins/KubernetesToolsPlugin.js.map +1 -0
  125. package/dist/src/plugins/SamplePlugin.d.ts +12 -0
  126. package/dist/src/plugins/SamplePlugin.d.ts.map +1 -0
  127. package/dist/src/plugins/SamplePlugin.js +51 -0
  128. package/dist/src/plugins/SamplePlugin.js.map +1 -0
  129. package/dist/src/plugins/index.d.ts +5 -0
  130. package/dist/src/plugins/index.d.ts.map +1 -0
  131. package/dist/src/plugins/index.js +5 -0
  132. package/dist/src/plugins/index.js.map +1 -0
  133. package/dist/src/server/MCPServer.d.ts +93 -0
  134. package/dist/src/server/MCPServer.d.ts.map +1 -0
  135. package/dist/src/server/MCPServer.js +398 -0
  136. package/dist/src/server/MCPServer.js.map +1 -0
  137. package/dist/src/tools/argo/ArgoCronListTool.d.ts +10 -0
  138. package/dist/src/tools/argo/ArgoCronListTool.d.ts.map +1 -0
  139. package/dist/src/tools/argo/ArgoCronListTool.js +70 -0
  140. package/dist/src/tools/argo/ArgoCronListTool.js.map +1 -0
  141. package/dist/src/tools/argo/ArgoGetTool.d.ts +10 -0
  142. package/dist/src/tools/argo/ArgoGetTool.d.ts.map +1 -0
  143. package/dist/src/tools/argo/ArgoGetTool.js +80 -0
  144. package/dist/src/tools/argo/ArgoGetTool.js.map +1 -0
  145. package/dist/src/tools/argo/ArgoListTool.d.ts +10 -0
  146. package/dist/src/tools/argo/ArgoListTool.d.ts.map +1 -0
  147. package/dist/src/tools/argo/ArgoListTool.js +133 -0
  148. package/dist/src/tools/argo/ArgoListTool.js.map +1 -0
  149. package/dist/src/tools/argo/ArgoLogsTool.d.ts +10 -0
  150. package/dist/src/tools/argo/ArgoLogsTool.d.ts.map +1 -0
  151. package/dist/src/tools/argo/ArgoLogsTool.js +117 -0
  152. package/dist/src/tools/argo/ArgoLogsTool.js.map +1 -0
  153. package/dist/src/tools/argo/BaseTool.d.ts +60 -0
  154. package/dist/src/tools/argo/BaseTool.d.ts.map +1 -0
  155. package/dist/src/tools/argo/BaseTool.js +51 -0
  156. package/dist/src/tools/argo/BaseTool.js.map +1 -0
  157. package/dist/src/tools/argo/index.d.ts +7 -0
  158. package/dist/src/tools/argo/index.d.ts.map +1 -0
  159. package/dist/src/tools/argo/index.js +6 -0
  160. package/dist/src/tools/argo/index.js.map +1 -0
  161. package/dist/src/tools/argocd/ArgoCDAppGetTool.d.ts +10 -0
  162. package/dist/src/tools/argocd/ArgoCDAppGetTool.d.ts.map +1 -0
  163. package/dist/src/tools/argocd/ArgoCDAppGetTool.js +97 -0
  164. package/dist/src/tools/argocd/ArgoCDAppGetTool.js.map +1 -0
  165. package/dist/src/tools/argocd/ArgoCDAppHistoryTool.d.ts +10 -0
  166. package/dist/src/tools/argocd/ArgoCDAppHistoryTool.d.ts.map +1 -0
  167. package/dist/src/tools/argocd/ArgoCDAppHistoryTool.js +80 -0
  168. package/dist/src/tools/argocd/ArgoCDAppHistoryTool.js.map +1 -0
  169. package/dist/src/tools/argocd/ArgoCDAppListTool.d.ts +10 -0
  170. package/dist/src/tools/argocd/ArgoCDAppListTool.d.ts.map +1 -0
  171. package/dist/src/tools/argocd/ArgoCDAppListTool.js +128 -0
  172. package/dist/src/tools/argocd/ArgoCDAppListTool.js.map +1 -0
  173. package/dist/src/tools/argocd/ArgoCDAppLogsTool.d.ts +10 -0
  174. package/dist/src/tools/argocd/ArgoCDAppLogsTool.d.ts.map +1 -0
  175. package/dist/src/tools/argocd/ArgoCDAppLogsTool.js +143 -0
  176. package/dist/src/tools/argocd/ArgoCDAppLogsTool.js.map +1 -0
  177. package/dist/src/tools/argocd/ArgoCDAppResourcesTool.d.ts +10 -0
  178. package/dist/src/tools/argocd/ArgoCDAppResourcesTool.d.ts.map +1 -0
  179. package/dist/src/tools/argocd/ArgoCDAppResourcesTool.js +123 -0
  180. package/dist/src/tools/argocd/ArgoCDAppResourcesTool.js.map +1 -0
  181. package/dist/src/tools/argocd/BaseTool.d.ts +71 -0
  182. package/dist/src/tools/argocd/BaseTool.d.ts.map +1 -0
  183. package/dist/src/tools/argocd/BaseTool.js +62 -0
  184. package/dist/src/tools/argocd/BaseTool.js.map +1 -0
  185. package/dist/src/tools/argocd/index.d.ts +8 -0
  186. package/dist/src/tools/argocd/index.d.ts.map +1 -0
  187. package/dist/src/tools/argocd/index.js +7 -0
  188. package/dist/src/tools/argocd/index.js.map +1 -0
  189. package/dist/src/tools/helm/BaseTool.d.ts +51 -0
  190. package/dist/src/tools/helm/BaseTool.d.ts.map +1 -0
  191. package/dist/src/tools/helm/BaseTool.js +42 -0
  192. package/dist/src/tools/helm/BaseTool.js.map +1 -0
  193. package/dist/src/tools/helm/HelmGetHooksTool.d.ts +10 -0
  194. package/dist/src/tools/helm/HelmGetHooksTool.d.ts.map +1 -0
  195. package/dist/src/tools/helm/HelmGetHooksTool.js +38 -0
  196. package/dist/src/tools/helm/HelmGetHooksTool.js.map +1 -0
  197. package/dist/src/tools/helm/HelmGetManifestTool.d.ts +10 -0
  198. package/dist/src/tools/helm/HelmGetManifestTool.d.ts.map +1 -0
  199. package/dist/src/tools/helm/HelmGetManifestTool.js +38 -0
  200. package/dist/src/tools/helm/HelmGetManifestTool.js.map +1 -0
  201. package/dist/src/tools/helm/HelmGetNotesTool.d.ts +10 -0
  202. package/dist/src/tools/helm/HelmGetNotesTool.d.ts.map +1 -0
  203. package/dist/src/tools/helm/HelmGetNotesTool.js +38 -0
  204. package/dist/src/tools/helm/HelmGetNotesTool.js.map +1 -0
  205. package/dist/src/tools/helm/HelmGetResourcesTool.d.ts +13 -0
  206. package/dist/src/tools/helm/HelmGetResourcesTool.d.ts.map +1 -0
  207. package/dist/src/tools/helm/HelmGetResourcesTool.js +124 -0
  208. package/dist/src/tools/helm/HelmGetResourcesTool.js.map +1 -0
  209. package/dist/src/tools/helm/HelmGetValuesTool.d.ts +10 -0
  210. package/dist/src/tools/helm/HelmGetValuesTool.d.ts.map +1 -0
  211. package/dist/src/tools/helm/HelmGetValuesTool.js +54 -0
  212. package/dist/src/tools/helm/HelmGetValuesTool.js.map +1 -0
  213. package/dist/src/tools/helm/HelmHistoryTool.d.ts +10 -0
  214. package/dist/src/tools/helm/HelmHistoryTool.d.ts.map +1 -0
  215. package/dist/src/tools/helm/HelmHistoryTool.js +49 -0
  216. package/dist/src/tools/helm/HelmHistoryTool.js.map +1 -0
  217. package/dist/src/tools/helm/HelmListTool.d.ts +10 -0
  218. package/dist/src/tools/helm/HelmListTool.d.ts.map +1 -0
  219. package/dist/src/tools/helm/HelmListTool.js +107 -0
  220. package/dist/src/tools/helm/HelmListTool.js.map +1 -0
  221. package/dist/src/tools/helm/HelmListWithResourcesTool.d.ts +14 -0
  222. package/dist/src/tools/helm/HelmListWithResourcesTool.d.ts.map +1 -0
  223. package/dist/src/tools/helm/HelmListWithResourcesTool.js +175 -0
  224. package/dist/src/tools/helm/HelmListWithResourcesTool.js.map +1 -0
  225. package/dist/src/tools/helm/HelmStatusTool.d.ts +10 -0
  226. package/dist/src/tools/helm/HelmStatusTool.d.ts.map +1 -0
  227. package/dist/src/tools/helm/HelmStatusTool.js +54 -0
  228. package/dist/src/tools/helm/HelmStatusTool.js.map +1 -0
  229. package/dist/src/tools/helm/index.d.ts +12 -0
  230. package/dist/src/tools/helm/index.d.ts.map +1 -0
  231. package/dist/src/tools/helm/index.js +11 -0
  232. package/dist/src/tools/helm/index.js.map +1 -0
  233. package/dist/src/tools/kubernetes/BaseTool.d.ts +48 -0
  234. package/dist/src/tools/kubernetes/BaseTool.d.ts.map +1 -0
  235. package/dist/src/tools/kubernetes/BaseTool.js +55 -0
  236. package/dist/src/tools/kubernetes/BaseTool.js.map +1 -0
  237. package/dist/src/tools/kubernetes/GetConfigMapTool.d.ts +11 -0
  238. package/dist/src/tools/kubernetes/GetConfigMapTool.d.ts.map +1 -0
  239. package/dist/src/tools/kubernetes/GetConfigMapTool.js +28 -0
  240. package/dist/src/tools/kubernetes/GetConfigMapTool.js.map +1 -0
  241. package/dist/src/tools/kubernetes/GetContainerLogsTool.d.ts +15 -0
  242. package/dist/src/tools/kubernetes/GetContainerLogsTool.d.ts.map +1 -0
  243. package/dist/src/tools/kubernetes/GetContainerLogsTool.js +119 -0
  244. package/dist/src/tools/kubernetes/GetContainerLogsTool.js.map +1 -0
  245. package/dist/src/tools/kubernetes/GetDeploymentsTool.d.ts +11 -0
  246. package/dist/src/tools/kubernetes/GetDeploymentsTool.d.ts.map +1 -0
  247. package/dist/src/tools/kubernetes/GetDeploymentsTool.js +30 -0
  248. package/dist/src/tools/kubernetes/GetDeploymentsTool.js.map +1 -0
  249. package/dist/src/tools/kubernetes/GetEventsTool.d.ts +11 -0
  250. package/dist/src/tools/kubernetes/GetEventsTool.d.ts.map +1 -0
  251. package/dist/src/tools/kubernetes/GetEventsTool.js +123 -0
  252. package/dist/src/tools/kubernetes/GetEventsTool.js.map +1 -0
  253. package/dist/src/tools/kubernetes/GetIngressTool.d.ts +11 -0
  254. package/dist/src/tools/kubernetes/GetIngressTool.d.ts.map +1 -0
  255. package/dist/src/tools/kubernetes/GetIngressTool.js +35 -0
  256. package/dist/src/tools/kubernetes/GetIngressTool.js.map +1 -0
  257. package/dist/src/tools/kubernetes/GetMetricsTool.d.ts +11 -0
  258. package/dist/src/tools/kubernetes/GetMetricsTool.d.ts.map +1 -0
  259. package/dist/src/tools/kubernetes/GetMetricsTool.js +40 -0
  260. package/dist/src/tools/kubernetes/GetMetricsTool.js.map +1 -0
  261. package/dist/src/tools/kubernetes/GetNamespacesTool.d.ts +11 -0
  262. package/dist/src/tools/kubernetes/GetNamespacesTool.d.ts.map +1 -0
  263. package/dist/src/tools/kubernetes/GetNamespacesTool.js +33 -0
  264. package/dist/src/tools/kubernetes/GetNamespacesTool.js.map +1 -0
  265. package/dist/src/tools/kubernetes/GetPersistentVolumeClaimsTool.d.ts +11 -0
  266. package/dist/src/tools/kubernetes/GetPersistentVolumeClaimsTool.d.ts.map +1 -0
  267. package/dist/src/tools/kubernetes/GetPersistentVolumeClaimsTool.js +92 -0
  268. package/dist/src/tools/kubernetes/GetPersistentVolumeClaimsTool.js.map +1 -0
  269. package/dist/src/tools/kubernetes/GetPersistentVolumesTool.d.ts +11 -0
  270. package/dist/src/tools/kubernetes/GetPersistentVolumesTool.d.ts.map +1 -0
  271. package/dist/src/tools/kubernetes/GetPersistentVolumesTool.js +88 -0
  272. package/dist/src/tools/kubernetes/GetPersistentVolumesTool.js.map +1 -0
  273. package/dist/src/tools/kubernetes/GetPodMetricsTool.d.ts +11 -0
  274. package/dist/src/tools/kubernetes/GetPodMetricsTool.d.ts.map +1 -0
  275. package/dist/src/tools/kubernetes/GetPodMetricsTool.js +100 -0
  276. package/dist/src/tools/kubernetes/GetPodMetricsTool.js.map +1 -0
  277. package/dist/src/tools/kubernetes/GetPodsTool.d.ts +11 -0
  278. package/dist/src/tools/kubernetes/GetPodsTool.d.ts.map +1 -0
  279. package/dist/src/tools/kubernetes/GetPodsTool.js +35 -0
  280. package/dist/src/tools/kubernetes/GetPodsTool.js.map +1 -0
  281. package/dist/src/tools/kubernetes/GetResourceTool.d.ts +12 -0
  282. package/dist/src/tools/kubernetes/GetResourceTool.d.ts.map +1 -0
  283. package/dist/src/tools/kubernetes/GetResourceTool.js +79 -0
  284. package/dist/src/tools/kubernetes/GetResourceTool.js.map +1 -0
  285. package/dist/src/tools/kubernetes/GetSecretsTool.d.ts +11 -0
  286. package/dist/src/tools/kubernetes/GetSecretsTool.d.ts.map +1 -0
  287. package/dist/src/tools/kubernetes/GetSecretsTool.js +49 -0
  288. package/dist/src/tools/kubernetes/GetSecretsTool.js.map +1 -0
  289. package/dist/src/tools/kubernetes/GetServicesTool.d.ts +11 -0
  290. package/dist/src/tools/kubernetes/GetServicesTool.d.ts.map +1 -0
  291. package/dist/src/tools/kubernetes/GetServicesTool.js +35 -0
  292. package/dist/src/tools/kubernetes/GetServicesTool.js.map +1 -0
  293. package/dist/src/tools/kubernetes/index.d.ts +17 -0
  294. package/dist/src/tools/kubernetes/index.d.ts.map +1 -0
  295. package/dist/src/tools/kubernetes/index.js +16 -0
  296. package/dist/src/tools/kubernetes/index.js.map +1 -0
  297. package/dist/src/utils/CliUtils.d.ts +24 -0
  298. package/dist/src/utils/CliUtils.d.ts.map +1 -0
  299. package/dist/src/utils/CliUtils.js +159 -0
  300. package/dist/src/utils/CliUtils.js.map +1 -0
  301. package/dist/tests/__mocks__/@kubernetes/client-node.d.ts +34 -0
  302. package/dist/tests/__mocks__/@kubernetes/client-node.d.ts.map +1 -0
  303. package/dist/tests/__mocks__/@kubernetes/client-node.js +20 -0
  304. package/dist/tests/__mocks__/@kubernetes/client-node.js.map +1 -0
  305. package/dist/tests/argo/ArgoGetTool.test.d.ts +2 -0
  306. package/dist/tests/argo/ArgoGetTool.test.d.ts.map +1 -0
  307. package/dist/tests/argo/ArgoGetTool.test.js +141 -0
  308. package/dist/tests/argo/ArgoGetTool.test.js.map +1 -0
  309. package/dist/tests/helm/BaseTool.test.d.ts +2 -0
  310. package/dist/tests/helm/BaseTool.test.d.ts.map +1 -0
  311. package/dist/tests/helm/BaseTool.test.js +241 -0
  312. package/dist/tests/helm/BaseTool.test.js.map +1 -0
  313. package/dist/tests/index.test.d.ts +2 -0
  314. package/dist/tests/index.test.d.ts.map +1 -0
  315. package/dist/tests/index.test.js +7 -0
  316. package/dist/tests/index.test.js.map +1 -0
  317. package/dist/tests/kubernetes/ConfigMapOperations.test.d.ts +2 -0
  318. package/dist/tests/kubernetes/ConfigMapOperations.test.d.ts.map +1 -0
  319. package/dist/tests/kubernetes/ConfigMapOperations.test.js +460 -0
  320. package/dist/tests/kubernetes/ConfigMapOperations.test.js.map +1 -0
  321. package/dist/tests/kubernetes/ConnectionManager.test.d.ts +2 -0
  322. package/dist/tests/kubernetes/ConnectionManager.test.d.ts.map +1 -0
  323. package/dist/tests/kubernetes/ConnectionManager.test.js +97 -0
  324. package/dist/tests/kubernetes/ConnectionManager.test.js.map +1 -0
  325. package/dist/tests/kubernetes/ConnectionPool.test.d.ts +2 -0
  326. package/dist/tests/kubernetes/ConnectionPool.test.d.ts.map +1 -0
  327. package/dist/tests/kubernetes/ConnectionPool.test.js +328 -0
  328. package/dist/tests/kubernetes/ConnectionPool.test.js.map +1 -0
  329. package/dist/tests/kubernetes/DeploymentOperations.test.d.ts +2 -0
  330. package/dist/tests/kubernetes/DeploymentOperations.test.d.ts.map +1 -0
  331. package/dist/tests/kubernetes/DeploymentOperations.test.js +196 -0
  332. package/dist/tests/kubernetes/DeploymentOperations.test.js.map +1 -0
  333. package/dist/tests/kubernetes/ErrorHandling.test.d.ts +2 -0
  334. package/dist/tests/kubernetes/ErrorHandling.test.d.ts.map +1 -0
  335. package/dist/tests/kubernetes/ErrorHandling.test.js +329 -0
  336. package/dist/tests/kubernetes/ErrorHandling.test.js.map +1 -0
  337. package/dist/tests/kubernetes/GetPodMetricsTool.test.d.ts +2 -0
  338. package/dist/tests/kubernetes/GetPodMetricsTool.test.d.ts.map +1 -0
  339. package/dist/tests/kubernetes/GetPodMetricsTool.test.js +150 -0
  340. package/dist/tests/kubernetes/GetPodMetricsTool.test.js.map +1 -0
  341. package/dist/tests/kubernetes/KubernetesClient.test.d.ts +2 -0
  342. package/dist/tests/kubernetes/KubernetesClient.test.d.ts.map +1 -0
  343. package/dist/tests/kubernetes/KubernetesClient.test.js +371 -0
  344. package/dist/tests/kubernetes/KubernetesClient.test.js.map +1 -0
  345. package/dist/tests/kubernetes/MetricOperations.parsing.test.d.ts +2 -0
  346. package/dist/tests/kubernetes/MetricOperations.parsing.test.d.ts.map +1 -0
  347. package/dist/tests/kubernetes/MetricOperations.parsing.test.js +49 -0
  348. package/dist/tests/kubernetes/MetricOperations.parsing.test.js.map +1 -0
  349. package/dist/tests/kubernetes/NamespaceOperations.test.d.ts +2 -0
  350. package/dist/tests/kubernetes/NamespaceOperations.test.d.ts.map +1 -0
  351. package/dist/tests/kubernetes/NamespaceOperations.test.js +115 -0
  352. package/dist/tests/kubernetes/NamespaceOperations.test.js.map +1 -0
  353. package/dist/tests/kubernetes/PodOperations.test.d.ts +2 -0
  354. package/dist/tests/kubernetes/PodOperations.test.d.ts.map +1 -0
  355. package/dist/tests/kubernetes/PodOperations.test.js +209 -0
  356. package/dist/tests/kubernetes/PodOperations.test.js.map +1 -0
  357. package/dist/tests/kubernetes/RetryStrategy.test.d.ts +2 -0
  358. package/dist/tests/kubernetes/RetryStrategy.test.d.ts.map +1 -0
  359. package/dist/tests/kubernetes/RetryStrategy.test.js +419 -0
  360. package/dist/tests/kubernetes/RetryStrategy.test.js.map +1 -0
  361. package/dist/tests/kubernetes/ServiceOperations.test.d.ts +2 -0
  362. package/dist/tests/kubernetes/ServiceOperations.test.d.ts.map +1 -0
  363. package/dist/tests/kubernetes/ServiceOperations.test.js +159 -0
  364. package/dist/tests/kubernetes/ServiceOperations.test.js.map +1 -0
  365. package/dist/tests/plugins/KubernetesToolsPlugin.test.d.ts +2 -0
  366. package/dist/tests/plugins/KubernetesToolsPlugin.test.d.ts.map +1 -0
  367. package/dist/tests/plugins/KubernetesToolsPlugin.test.js +153 -0
  368. package/dist/tests/plugins/KubernetesToolsPlugin.test.js.map +1 -0
  369. package/dist/tests/server/MCPServer.integration.test.d.ts +2 -0
  370. package/dist/tests/server/MCPServer.integration.test.d.ts.map +1 -0
  371. package/dist/tests/server/MCPServer.integration.test.js +244 -0
  372. package/dist/tests/server/MCPServer.integration.test.js.map +1 -0
  373. package/dist/tests/server/MCPServer.test.d.ts +2 -0
  374. package/dist/tests/server/MCPServer.test.d.ts.map +1 -0
  375. package/dist/tests/server/MCPServer.test.js +257 -0
  376. package/dist/tests/server/MCPServer.test.js.map +1 -0
  377. package/package.json +85 -0
  378. package/src/cli/cli.ts +25 -0
  379. package/src/cli/run-command.js +391 -0
  380. package/src/index.ts +46 -0
  381. package/src/kubernetes/BaseResourceOperations.ts +286 -0
  382. package/src/kubernetes/CircuitBreaker.ts +485 -0
  383. package/src/kubernetes/ConnectionManager.ts +114 -0
  384. package/src/kubernetes/ConnectionPool.ts +551 -0
  385. package/src/kubernetes/ErrorHandler.ts +436 -0
  386. package/src/kubernetes/ErrorHandling.ts +401 -0
  387. package/src/kubernetes/KubernetesClient.ts +500 -0
  388. package/src/kubernetes/README.md +349 -0
  389. package/src/kubernetes/ResourceOperations.ts +116 -0
  390. package/src/kubernetes/RetryStrategy.ts +365 -0
  391. package/src/kubernetes/RetryableOperation.ts +313 -0
  392. package/src/kubernetes/docs/ResourceOperations.md +606 -0
  393. package/src/kubernetes/index.ts +116 -0
  394. package/src/kubernetes/resources/ConfigMapOperations.ts +367 -0
  395. package/src/kubernetes/resources/CustomResourceOperations.ts +392 -0
  396. package/src/kubernetes/resources/DeploymentOperations.ts +294 -0
  397. package/src/kubernetes/resources/IngressOperations.ts +277 -0
  398. package/src/kubernetes/resources/MetricOperations.ts +1159 -0
  399. package/src/kubernetes/resources/NamespaceOperations.ts +129 -0
  400. package/src/kubernetes/resources/PersistentVolumeClaimOperations.ts +516 -0
  401. package/src/kubernetes/resources/PersistentVolumeOperations.ts +438 -0
  402. package/src/kubernetes/resources/PodOperations.ts +417 -0
  403. package/src/kubernetes/resources/SecretOperations.ts +304 -0
  404. package/src/kubernetes/resources/ServiceOperations.ts +283 -0
  405. package/src/kubernetes/utils/ResourceUtils.ts +553 -0
  406. package/src/plugins/ArgoCDToolsPlugin.ts +189 -0
  407. package/src/plugins/ArgoToolsPlugin.ts +180 -0
  408. package/src/plugins/HelmToolsPlugin.ts +180 -0
  409. package/src/plugins/KubernetesToolsPlugin.ts +198 -0
  410. package/src/plugins/SamplePlugin.ts +60 -0
  411. package/src/plugins/index.ts +4 -0
  412. package/src/server/MCPServer.ts +500 -0
  413. package/src/tools/argo/ArgoCronListTool.ts +78 -0
  414. package/src/tools/argo/ArgoGetTool.ts +91 -0
  415. package/src/tools/argo/ArgoListTool.ts +143 -0
  416. package/src/tools/argo/ArgoLogsTool.ts +131 -0
  417. package/src/tools/argo/BaseTool.ts +69 -0
  418. package/src/tools/argo/index.ts +6 -0
  419. package/src/tools/argocd/ArgoCDAppGetTool.ts +109 -0
  420. package/src/tools/argocd/ArgoCDAppHistoryTool.ts +91 -0
  421. package/src/tools/argocd/ArgoCDAppListTool.ts +144 -0
  422. package/src/tools/argocd/ArgoCDAppLogsTool.ts +162 -0
  423. package/src/tools/argocd/ArgoCDAppResourcesTool.ts +139 -0
  424. package/src/tools/argocd/BaseTool.ts +83 -0
  425. package/src/tools/argocd/index.ts +7 -0
  426. package/src/tools/helm/BaseTool.ts +60 -0
  427. package/src/tools/helm/HelmGetHooksTool.ts +44 -0
  428. package/src/tools/helm/HelmGetManifestTool.ts +44 -0
  429. package/src/tools/helm/HelmGetNotesTool.ts +44 -0
  430. package/src/tools/helm/HelmGetResourcesTool.ts +140 -0
  431. package/src/tools/helm/HelmGetValuesTool.ts +62 -0
  432. package/src/tools/helm/HelmHistoryTool.ts +56 -0
  433. package/src/tools/helm/HelmListTool.ts +107 -0
  434. package/src/tools/helm/HelmListWithResourcesTool.ts +194 -0
  435. package/src/tools/helm/HelmStatusTool.ts +62 -0
  436. package/src/tools/helm/index.ts +11 -0
  437. package/src/tools/kubernetes/BaseTool.ts +76 -0
  438. package/src/tools/kubernetes/GetConfigMapTool.ts +33 -0
  439. package/src/tools/kubernetes/GetContainerLogsTool.ts +140 -0
  440. package/src/tools/kubernetes/GetDeploymentsTool.ts +33 -0
  441. package/src/tools/kubernetes/GetEventsTool.ts +133 -0
  442. package/src/tools/kubernetes/GetIngressTool.ts +39 -0
  443. package/src/tools/kubernetes/GetMetricsTool.ts +53 -0
  444. package/src/tools/kubernetes/GetNamespacesTool.ts +36 -0
  445. package/src/tools/kubernetes/GetPersistentVolumeClaimsTool.ts +113 -0
  446. package/src/tools/kubernetes/GetPersistentVolumesTool.ts +107 -0
  447. package/src/tools/kubernetes/GetPodMetricsTool.ts +113 -0
  448. package/src/tools/kubernetes/GetPodsTool.ts +39 -0
  449. package/src/tools/kubernetes/GetResourceTool.ts +90 -0
  450. package/src/tools/kubernetes/GetSecretsTool.ts +55 -0
  451. package/src/tools/kubernetes/GetServicesTool.ts +39 -0
  452. package/src/tools/kubernetes/index.ts +16 -0
  453. package/src/utils/CliUtils.ts +207 -0
  454. 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 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AAE;QACtC,EAAE,CAAC,yCAAyC,EAAE,KAAK,IAAI,EAAE;YACvD,MAAM,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,EAAe,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CACjE,qDAAqD,CACtD,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,yCAAyC,EAAE,KAAK,IAAI,EAAE;YACvD,MAAM,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,EAAe,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CACjE,qDAAqD,CACtD,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,wCAAwC,EAAE,KAAK,IAAI,EAAE;YACtD,MAAM,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAC/D,oDAAoD,CACrD,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,yCAAyC,EAAE,KAAK,IAAI,EAAE;YACvD,MAAM,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAC5D,qDAAqD,CACtD,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=RetryStrategy.test.d.ts.map
@@ -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