typekro 0.1.0 → 0.2.2

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 (436) hide show
  1. package/LICENSE +201 -185
  2. package/README.md +581 -563
  3. package/dist/.tsbuildinfo +1 -1
  4. package/dist/alchemy/deployers.d.ts +1 -1
  5. package/dist/alchemy/deployers.d.ts.map +1 -1
  6. package/dist/alchemy/deployers.js +25 -20
  7. package/dist/alchemy/deployers.js.map +1 -1
  8. package/dist/alchemy/deployment.d.ts +3 -3
  9. package/dist/alchemy/deployment.d.ts.map +1 -1
  10. package/dist/alchemy/deployment.js +2 -2
  11. package/dist/alchemy/deployment.js.map +1 -1
  12. package/dist/alchemy/index.d.ts +4 -4
  13. package/dist/alchemy/index.d.ts.map +1 -1
  14. package/dist/alchemy/index.js +6 -6
  15. package/dist/alchemy/index.js.map +1 -1
  16. package/dist/alchemy/resolver.d.ts +3 -3
  17. package/dist/alchemy/resolver.d.ts.map +1 -1
  18. package/dist/alchemy/resolver.js +70 -17
  19. package/dist/alchemy/resolver.js.map +1 -1
  20. package/dist/alchemy/resource-registration.d.ts.map +1 -1
  21. package/dist/alchemy/resource-registration.js +3 -3
  22. package/dist/alchemy/resource-registration.js.map +1 -1
  23. package/dist/alchemy/type-inference.d.ts.map +1 -1
  24. package/dist/alchemy/type-inference.js.map +1 -1
  25. package/dist/alchemy/types.d.ts +2 -2
  26. package/dist/alchemy/types.d.ts.map +1 -1
  27. package/dist/alchemy/utilities.d.ts.map +1 -1
  28. package/dist/alchemy/utilities.js.map +1 -1
  29. package/dist/alchemy/wrapper.d.ts.map +1 -1
  30. package/dist/alchemy/wrapper.js +2 -2
  31. package/dist/alchemy/wrapper.js.map +1 -1
  32. package/dist/core/composition/composition.d.ts +1 -85
  33. package/dist/core/composition/composition.d.ts.map +1 -1
  34. package/dist/core/composition/composition.js +3 -214
  35. package/dist/core/composition/composition.js.map +1 -1
  36. package/dist/core/composition/imperative.d.ts +39 -0
  37. package/dist/core/composition/imperative.d.ts.map +1 -0
  38. package/dist/core/composition/imperative.js +219 -0
  39. package/dist/core/composition/imperative.js.map +1 -0
  40. package/dist/core/composition/index.d.ts +5 -3
  41. package/dist/core/composition/index.d.ts.map +1 -1
  42. package/dist/core/composition/index.js +4 -2
  43. package/dist/core/composition/index.js.map +1 -1
  44. package/dist/core/composition/typekro-runtime/index.d.ts +1 -1
  45. package/dist/core/composition/typekro-runtime/index.d.ts.map +1 -1
  46. package/dist/core/composition/typekro-runtime/typekro-runtime.d.ts.map +1 -1
  47. package/dist/core/composition/typekro-runtime/typekro-runtime.js +3 -3
  48. package/dist/core/composition/typekro-runtime/typekro-runtime.js.map +1 -1
  49. package/dist/core/composition/types.d.ts +0 -237
  50. package/dist/core/composition/types.d.ts.map +1 -1
  51. package/dist/core/composition/types.js +6 -0
  52. package/dist/core/composition/types.js.map +1 -1
  53. package/dist/core/constants/brands.d.ts.map +1 -1
  54. package/dist/core/constants/brands.js +3 -9
  55. package/dist/core/constants/brands.js.map +1 -1
  56. package/dist/core/dependencies/resolver.d.ts.map +1 -1
  57. package/dist/core/dependencies/resolver.js +3 -3
  58. package/dist/core/dependencies/resolver.js.map +1 -1
  59. package/dist/core/dependencies/type-guards.d.ts +3 -3
  60. package/dist/core/dependencies/type-guards.d.ts.map +1 -1
  61. package/dist/core/dependencies/type-guards.js +3 -3
  62. package/dist/core/dependencies/type-guards.js.map +1 -1
  63. package/dist/core/deployment/debug-logger.d.ts +119 -0
  64. package/dist/core/deployment/debug-logger.d.ts.map +1 -0
  65. package/dist/core/deployment/debug-logger.js +372 -0
  66. package/dist/core/deployment/debug-logger.js.map +1 -0
  67. package/dist/core/deployment/deployment-strategies.d.ts +1 -1
  68. package/dist/core/deployment/deployment-strategies.d.ts.map +1 -1
  69. package/dist/core/deployment/deployment-strategies.js +1 -1
  70. package/dist/core/deployment/deployment-strategies.js.map +1 -1
  71. package/dist/core/deployment/direct-factory.d.ts +11 -5
  72. package/dist/core/deployment/direct-factory.d.ts.map +1 -1
  73. package/dist/core/deployment/direct-factory.js +22 -12
  74. package/dist/core/deployment/direct-factory.js.map +1 -1
  75. package/dist/core/deployment/engine.d.ts +9 -6
  76. package/dist/core/deployment/engine.d.ts.map +1 -1
  77. package/dist/core/deployment/engine.js +184 -95
  78. package/dist/core/deployment/engine.js.map +1 -1
  79. package/dist/core/deployment/event-filter.d.ts +142 -0
  80. package/dist/core/deployment/event-filter.d.ts.map +1 -0
  81. package/dist/core/deployment/event-filter.js +420 -0
  82. package/dist/core/deployment/event-filter.js.map +1 -0
  83. package/dist/core/deployment/event-monitor.d.ts +197 -0
  84. package/dist/core/deployment/event-monitor.d.ts.map +1 -0
  85. package/dist/core/deployment/event-monitor.js +738 -0
  86. package/dist/core/deployment/event-monitor.js.map +1 -0
  87. package/dist/core/deployment/event-streamer.d.ts +112 -0
  88. package/dist/core/deployment/event-streamer.d.ts.map +1 -0
  89. package/dist/core/deployment/event-streamer.js +348 -0
  90. package/dist/core/deployment/event-streamer.js.map +1 -0
  91. package/dist/core/deployment/index.d.ts +5 -5
  92. package/dist/core/deployment/index.d.ts.map +1 -1
  93. package/dist/core/deployment/index.js +5 -5
  94. package/dist/core/deployment/index.js.map +1 -1
  95. package/dist/core/deployment/kro-factory.d.ts +2 -8
  96. package/dist/core/deployment/kro-factory.d.ts.map +1 -1
  97. package/dist/core/deployment/kro-factory.js +63 -109
  98. package/dist/core/deployment/kro-factory.js.map +1 -1
  99. package/dist/core/deployment/readiness.d.ts +6 -0
  100. package/dist/core/deployment/readiness.d.ts.map +1 -1
  101. package/dist/core/deployment/readiness.js +45 -1
  102. package/dist/core/deployment/readiness.js.map +1 -1
  103. package/dist/core/deployment/rollback-manager.d.ts.map +1 -1
  104. package/dist/core/deployment/rollback-manager.js +3 -3
  105. package/dist/core/deployment/rollback-manager.js.map +1 -1
  106. package/dist/core/deployment/shared-utilities.d.ts +1 -1
  107. package/dist/core/deployment/shared-utilities.d.ts.map +1 -1
  108. package/dist/core/deployment/shared-utilities.js +2 -0
  109. package/dist/core/deployment/shared-utilities.js.map +1 -1
  110. package/dist/core/deployment/status-hydrator.d.ts.map +1 -1
  111. package/dist/core/deployment/status-hydrator.js +31 -12
  112. package/dist/core/deployment/status-hydrator.js.map +1 -1
  113. package/dist/core/deployment/strategies/alchemy-strategy.d.ts +4 -4
  114. package/dist/core/deployment/strategies/alchemy-strategy.d.ts.map +1 -1
  115. package/dist/core/deployment/strategies/alchemy-strategy.js +9 -9
  116. package/dist/core/deployment/strategies/alchemy-strategy.js.map +1 -1
  117. package/dist/core/deployment/strategies/base-strategy.d.ts +7 -4
  118. package/dist/core/deployment/strategies/base-strategy.d.ts.map +1 -1
  119. package/dist/core/deployment/strategies/base-strategy.js +257 -11
  120. package/dist/core/deployment/strategies/base-strategy.js.map +1 -1
  121. package/dist/core/deployment/strategies/direct-strategy.d.ts +4 -3
  122. package/dist/core/deployment/strategies/direct-strategy.d.ts.map +1 -1
  123. package/dist/core/deployment/strategies/direct-strategy.js +4 -4
  124. package/dist/core/deployment/strategies/direct-strategy.js.map +1 -1
  125. package/dist/core/deployment/strategies/index.d.ts +1 -1
  126. package/dist/core/deployment/strategies/index.d.ts.map +1 -1
  127. package/dist/core/deployment/strategies/index.js +1 -1
  128. package/dist/core/deployment/strategies/index.js.map +1 -1
  129. package/dist/core/deployment/strategies/kro-strategy.d.ts +1 -1
  130. package/dist/core/deployment/strategies/kro-strategy.d.ts.map +1 -1
  131. package/dist/core/deployment/strategies/kro-strategy.js +14 -14
  132. package/dist/core/deployment/strategies/kro-strategy.js.map +1 -1
  133. package/dist/core/errors.d.ts +136 -0
  134. package/dist/core/errors.d.ts.map +1 -1
  135. package/dist/core/errors.js +362 -0
  136. package/dist/core/errors.js.map +1 -1
  137. package/dist/core/evaluation/cel-optimizer.d.ts.map +1 -1
  138. package/dist/core/evaluation/cel-optimizer.js +33 -11
  139. package/dist/core/evaluation/cel-optimizer.js.map +1 -1
  140. package/dist/core/factory.d.ts.map +1 -1
  141. package/dist/core/factory.js.map +1 -1
  142. package/dist/core/kubernetes/api.d.ts +13 -2
  143. package/dist/core/kubernetes/api.d.ts.map +1 -1
  144. package/dist/core/kubernetes/api.js +21 -8
  145. package/dist/core/kubernetes/api.js.map +1 -1
  146. package/dist/core/kubernetes/client-provider.d.ts +192 -0
  147. package/dist/core/kubernetes/client-provider.d.ts.map +1 -1
  148. package/dist/core/kubernetes/client-provider.js +423 -22
  149. package/dist/core/kubernetes/client-provider.js.map +1 -1
  150. package/dist/core/logging/config.d.ts.map +1 -1
  151. package/dist/core/logging/config.js.map +1 -1
  152. package/dist/core/logging/index.d.ts +1 -1
  153. package/dist/core/logging/index.d.ts.map +1 -1
  154. package/dist/core/logging/index.js +1 -1
  155. package/dist/core/logging/index.js.map +1 -1
  156. package/dist/core/logging/logger.d.ts +1 -1
  157. package/dist/core/logging/logger.d.ts.map +1 -1
  158. package/dist/core/logging/logger.js.map +1 -1
  159. package/dist/core/readiness/cluster-state.d.ts.map +1 -1
  160. package/dist/core/readiness/cluster-state.js +12 -6
  161. package/dist/core/readiness/cluster-state.js.map +1 -1
  162. package/dist/core/references/cel-evaluator.js +1 -1
  163. package/dist/core/references/cel-evaluator.js.map +1 -1
  164. package/dist/core/references/cel.d.ts.map +1 -1
  165. package/dist/core/references/cel.js +1 -1
  166. package/dist/core/references/cel.js.map +1 -1
  167. package/dist/core/references/external-refs.d.ts +1 -1
  168. package/dist/core/references/external-refs.js +1 -1
  169. package/dist/core/references/index.d.ts +4 -4
  170. package/dist/core/references/index.d.ts.map +1 -1
  171. package/dist/core/references/index.js +6 -6
  172. package/dist/core/references/index.js.map +1 -1
  173. package/dist/core/references/resolver.d.ts +1 -1
  174. package/dist/core/references/resolver.d.ts.map +1 -1
  175. package/dist/core/references/resolver.js +69 -44
  176. package/dist/core/references/resolver.js.map +1 -1
  177. package/dist/core/references/schema-proxy.d.ts.map +1 -1
  178. package/dist/core/references/schema-proxy.js +2 -4
  179. package/dist/core/references/schema-proxy.js.map +1 -1
  180. package/dist/core/serialization/core.d.ts +1 -1
  181. package/dist/core/serialization/core.d.ts.map +1 -1
  182. package/dist/core/serialization/core.js +122 -16
  183. package/dist/core/serialization/core.js.map +1 -1
  184. package/dist/core/serialization/schema.js +1 -1
  185. package/dist/core/serialization/schema.js.map +1 -1
  186. package/dist/core/serialization/validation.js +1 -1
  187. package/dist/core/serialization/validation.js.map +1 -1
  188. package/dist/core/serialization/yaml.js +1 -1
  189. package/dist/core/serialization/yaml.js.map +1 -1
  190. package/dist/core/types/common.d.ts.map +1 -1
  191. package/dist/core/types/deployment.d.ts +116 -3
  192. package/dist/core/types/deployment.d.ts.map +1 -1
  193. package/dist/core/types/deployment.js.map +1 -1
  194. package/dist/core/types/index.d.ts +1 -1
  195. package/dist/core/types/index.d.ts.map +1 -1
  196. package/dist/core/types/index.js.map +1 -1
  197. package/dist/core/types/kubernetes.d.ts.map +1 -1
  198. package/dist/core/types/serialization.d.ts +14 -3
  199. package/dist/core/types/serialization.d.ts.map +1 -1
  200. package/dist/core/validation/cel-validator.d.ts.map +1 -1
  201. package/dist/core/validation/cel-validator.js +28 -10
  202. package/dist/core/validation/cel-validator.js.map +1 -1
  203. package/dist/core/yaml/index.d.ts +1 -1
  204. package/dist/core/yaml/index.d.ts.map +1 -1
  205. package/dist/core/yaml/index.js +1 -1
  206. package/dist/core/yaml/index.js.map +1 -1
  207. package/dist/core/yaml/path-resolver.d.ts.map +1 -1
  208. package/dist/core/yaml/path-resolver.js +6 -6
  209. package/dist/core/yaml/path-resolver.js.map +1 -1
  210. package/dist/core.d.ts +10 -10
  211. package/dist/core.d.ts.map +1 -1
  212. package/dist/core.js +14 -14
  213. package/dist/core.js.map +1 -1
  214. package/dist/factories/flux/git-repository.d.ts.map +1 -1
  215. package/dist/factories/flux/git-repository.js.map +1 -1
  216. package/dist/factories/flux/index.d.ts +1 -1
  217. package/dist/factories/flux/index.d.ts.map +1 -1
  218. package/dist/factories/flux/index.js.map +1 -1
  219. package/dist/factories/flux/kustomize/index.d.ts +1 -1
  220. package/dist/factories/flux/kustomize/index.d.ts.map +1 -1
  221. package/dist/factories/flux/kustomize/index.js.map +1 -1
  222. package/dist/factories/flux/kustomize/readiness-evaluators.d.ts.map +1 -1
  223. package/dist/factories/flux/kustomize/readiness-evaluators.js +9 -9
  224. package/dist/factories/flux/kustomize/readiness-evaluators.js.map +1 -1
  225. package/dist/factories/flux/kustomize/types.d.ts +1 -1
  226. package/dist/factories/flux/kustomize/types.d.ts.map +1 -1
  227. package/dist/factories/helm/helm-release.d.ts +7 -4
  228. package/dist/factories/helm/helm-release.d.ts.map +1 -1
  229. package/dist/factories/helm/helm-release.js +7 -4
  230. package/dist/factories/helm/helm-release.js.map +1 -1
  231. package/dist/factories/helm/helm-repository.d.ts.map +1 -1
  232. package/dist/factories/helm/helm-repository.js.map +1 -1
  233. package/dist/factories/helm/index.d.ts +1 -1
  234. package/dist/factories/helm/index.d.ts.map +1 -1
  235. package/dist/factories/helm/index.js +1 -1
  236. package/dist/factories/helm/index.js.map +1 -1
  237. package/dist/factories/helm/readiness-evaluators.d.ts.map +1 -1
  238. package/dist/factories/helm/readiness-evaluators.js +4 -2
  239. package/dist/factories/helm/readiness-evaluators.js.map +1 -1
  240. package/dist/factories/index.d.ts +6 -3
  241. package/dist/factories/index.d.ts.map +1 -1
  242. package/dist/factories/index.js +10 -6
  243. package/dist/factories/index.js.map +1 -1
  244. package/dist/factories/kro/index.d.ts +3 -3
  245. package/dist/factories/kro/index.d.ts.map +1 -1
  246. package/dist/factories/kro/index.js +2 -2
  247. package/dist/factories/kro/index.js.map +1 -1
  248. package/dist/factories/kro/kro-crd.d.ts.map +1 -1
  249. package/dist/factories/kro/kro-crd.js +5 -5
  250. package/dist/factories/kro/kro-crd.js.map +1 -1
  251. package/dist/factories/kro/kro-custom-resource.d.ts.map +1 -1
  252. package/dist/factories/kro/kro-custom-resource.js +21 -21
  253. package/dist/factories/kro/kro-custom-resource.js.map +1 -1
  254. package/dist/factories/kro/resource-graph-definition.d.ts.map +1 -1
  255. package/dist/factories/kro/resource-graph-definition.js +7 -7
  256. package/dist/factories/kro/resource-graph-definition.js.map +1 -1
  257. package/dist/factories/kubernetes/autoscaling/horizontal-pod-autoscaler-v1.d.ts.map +1 -1
  258. package/dist/factories/kubernetes/autoscaling/horizontal-pod-autoscaler-v1.js.map +1 -1
  259. package/dist/factories/kubernetes/autoscaling/horizontal-pod-autoscaler.js +2 -2
  260. package/dist/factories/kubernetes/certificates/certificate-signing-request.js +2 -2
  261. package/dist/factories/kubernetes/certificates/certificate-signing-request.js.map +1 -1
  262. package/dist/factories/kubernetes/config/config-map.js +1 -1
  263. package/dist/factories/kubernetes/config/config-map.js.map +1 -1
  264. package/dist/factories/kubernetes/config/secret.js +1 -1
  265. package/dist/factories/kubernetes/config/secret.js.map +1 -1
  266. package/dist/factories/kubernetes/core/component-status.js +1 -1
  267. package/dist/factories/kubernetes/core/component-status.js.map +1 -1
  268. package/dist/factories/kubernetes/core/node.js +1 -1
  269. package/dist/factories/kubernetes/core/node.js.map +1 -1
  270. package/dist/factories/kubernetes/core/pod.js +4 -4
  271. package/dist/factories/kubernetes/core/pod.js.map +1 -1
  272. package/dist/factories/kubernetes/extensions/custom-resource-definition.js +2 -2
  273. package/dist/factories/kubernetes/extensions/custom-resource-definition.js.map +1 -1
  274. package/dist/factories/kubernetes/index.d.ts +2 -2
  275. package/dist/factories/kubernetes/index.d.ts.map +1 -1
  276. package/dist/factories/kubernetes/index.js +8 -8
  277. package/dist/factories/kubernetes/index.js.map +1 -1
  278. package/dist/factories/kubernetes/networking/endpoints.d.ts.map +1 -1
  279. package/dist/factories/kubernetes/networking/endpoints.js +4 -4
  280. package/dist/factories/kubernetes/networking/endpoints.js.map +1 -1
  281. package/dist/factories/kubernetes/networking/ingress.js +2 -2
  282. package/dist/factories/kubernetes/networking/network-policy.js +2 -2
  283. package/dist/factories/kubernetes/networking/network-policy.js.map +1 -1
  284. package/dist/factories/kubernetes/networking/service.d.ts.map +1 -1
  285. package/dist/factories/kubernetes/networking/service.js +8 -7
  286. package/dist/factories/kubernetes/networking/service.js.map +1 -1
  287. package/dist/factories/kubernetes/policy/limit-range.js +2 -2
  288. package/dist/factories/kubernetes/policy/limit-range.js.map +1 -1
  289. package/dist/factories/kubernetes/policy/pod-disruption-budget.js +5 -5
  290. package/dist/factories/kubernetes/policy/resource-quota.js +4 -4
  291. package/dist/factories/kubernetes/rbac/cluster-role-binding.js +2 -2
  292. package/dist/factories/kubernetes/rbac/cluster-role-binding.js.map +1 -1
  293. package/dist/factories/kubernetes/rbac/cluster-role.js +2 -2
  294. package/dist/factories/kubernetes/rbac/cluster-role.js.map +1 -1
  295. package/dist/factories/kubernetes/rbac/role-binding.js +2 -2
  296. package/dist/factories/kubernetes/rbac/role-binding.js.map +1 -1
  297. package/dist/factories/kubernetes/rbac/role.js +2 -2
  298. package/dist/factories/kubernetes/rbac/role.js.map +1 -1
  299. package/dist/factories/kubernetes/rbac/service-account.js +2 -2
  300. package/dist/factories/kubernetes/rbac/service-account.js.map +1 -1
  301. package/dist/factories/kubernetes/storage/persistent-volume-claim.js +2 -2
  302. package/dist/factories/kubernetes/storage/persistent-volume.js +4 -4
  303. package/dist/factories/kubernetes/storage/storage-class.js +2 -2
  304. package/dist/factories/kubernetes/storage/storage-class.js.map +1 -1
  305. package/dist/factories/kubernetes/workloads/cron-job.js +5 -5
  306. package/dist/factories/kubernetes/workloads/daemon-set.js +2 -2
  307. package/dist/factories/kubernetes/workloads/deployment.d.ts.map +1 -1
  308. package/dist/factories/kubernetes/workloads/deployment.js +5 -6
  309. package/dist/factories/kubernetes/workloads/deployment.js.map +1 -1
  310. package/dist/factories/kubernetes/workloads/job.js +10 -10
  311. package/dist/factories/kubernetes/workloads/replica-set.js +2 -2
  312. package/dist/factories/kubernetes/workloads/replication-controller.js +5 -5
  313. package/dist/factories/kubernetes/workloads/stateful-set.d.ts.map +1 -1
  314. package/dist/factories/kubernetes/workloads/stateful-set.js +7 -7
  315. package/dist/factories/kubernetes/workloads/stateful-set.js.map +1 -1
  316. package/dist/factories/kubernetes/yaml/index.d.ts +1 -1
  317. package/dist/factories/kubernetes/yaml/index.d.ts.map +1 -1
  318. package/dist/factories/kubernetes/yaml/index.js +1 -1
  319. package/dist/factories/kubernetes/yaml/index.js.map +1 -1
  320. package/dist/factories/kubernetes/yaml/yaml-directory.d.ts +2 -2
  321. package/dist/factories/kubernetes/yaml/yaml-directory.d.ts.map +1 -1
  322. package/dist/factories/kubernetes/yaml/yaml-directory.js +106 -101
  323. package/dist/factories/kubernetes/yaml/yaml-directory.js.map +1 -1
  324. package/dist/factories/kubernetes/yaml/yaml-file.d.ts +7 -4
  325. package/dist/factories/kubernetes/yaml/yaml-file.d.ts.map +1 -1
  326. package/dist/factories/kubernetes/yaml/yaml-file.js +110 -99
  327. package/dist/factories/kubernetes/yaml/yaml-file.js.map +1 -1
  328. package/dist/factories/shared.d.ts +49 -0
  329. package/dist/factories/shared.d.ts.map +1 -1
  330. package/dist/factories/shared.js +75 -3
  331. package/dist/factories/shared.js.map +1 -1
  332. package/dist/factories/simple/autoscaling/horizontal-pod-autoscaler.d.ts +17 -0
  333. package/dist/factories/simple/autoscaling/horizontal-pod-autoscaler.d.ts.map +1 -0
  334. package/dist/factories/simple/autoscaling/horizontal-pod-autoscaler.js +46 -0
  335. package/dist/factories/simple/autoscaling/horizontal-pod-autoscaler.js.map +1 -0
  336. package/dist/factories/simple/autoscaling/index.d.ts +8 -0
  337. package/dist/factories/simple/autoscaling/index.d.ts.map +1 -0
  338. package/dist/factories/simple/autoscaling/index.js +8 -0
  339. package/dist/factories/simple/autoscaling/index.js.map +1 -0
  340. package/dist/factories/simple/config/config-map.d.ts +17 -0
  341. package/dist/factories/simple/config/config-map.d.ts.map +1 -0
  342. package/dist/factories/simple/config/config-map.js +25 -0
  343. package/dist/factories/simple/config/config-map.js.map +1 -0
  344. package/dist/factories/simple/config/index.d.ts +9 -0
  345. package/dist/factories/simple/config/index.d.ts.map +1 -0
  346. package/dist/factories/simple/config/index.js +9 -0
  347. package/dist/factories/simple/config/index.js.map +1 -0
  348. package/dist/factories/simple/config/secret.d.ts +17 -0
  349. package/dist/factories/simple/config/secret.d.ts.map +1 -0
  350. package/dist/factories/simple/config/secret.js +24 -0
  351. package/dist/factories/simple/config/secret.js.map +1 -0
  352. package/dist/factories/simple/helm/index.d.ts +16 -0
  353. package/dist/factories/simple/helm/index.d.ts.map +1 -0
  354. package/dist/factories/simple/helm/index.js +21 -0
  355. package/dist/factories/simple/helm/index.js.map +1 -0
  356. package/dist/factories/simple/index.d.ts +50 -0
  357. package/dist/factories/simple/index.d.ts.map +1 -0
  358. package/dist/factories/simple/index.js +58 -0
  359. package/dist/factories/simple/index.js.map +1 -0
  360. package/dist/factories/simple/networking/index.d.ts +10 -0
  361. package/dist/factories/simple/networking/index.d.ts.map +1 -0
  362. package/dist/factories/simple/networking/index.js +10 -0
  363. package/dist/factories/simple/networking/index.js.map +1 -0
  364. package/dist/factories/simple/networking/ingress.d.ts +17 -0
  365. package/dist/factories/simple/networking/ingress.d.ts.map +1 -0
  366. package/dist/factories/simple/networking/ingress.js +30 -0
  367. package/dist/factories/simple/networking/ingress.js.map +1 -0
  368. package/dist/factories/simple/networking/network-policy.d.ts +17 -0
  369. package/dist/factories/simple/networking/network-policy.d.ts.map +1 -0
  370. package/dist/factories/simple/networking/network-policy.js +30 -0
  371. package/dist/factories/simple/networking/network-policy.js.map +1 -0
  372. package/dist/factories/simple/networking/service.d.ts +17 -0
  373. package/dist/factories/simple/networking/service.d.ts.map +1 -0
  374. package/dist/factories/simple/networking/service.js +27 -0
  375. package/dist/factories/simple/networking/service.js.map +1 -0
  376. package/dist/factories/simple/storage/index.d.ts +9 -0
  377. package/dist/factories/simple/storage/index.d.ts.map +1 -0
  378. package/dist/factories/simple/storage/index.js +9 -0
  379. package/dist/factories/simple/storage/index.js.map +1 -0
  380. package/dist/factories/simple/storage/persistent-volume-claim.d.ts +17 -0
  381. package/dist/factories/simple/storage/persistent-volume-claim.d.ts.map +1 -0
  382. package/dist/factories/simple/storage/persistent-volume-claim.js +32 -0
  383. package/dist/factories/simple/storage/persistent-volume-claim.js.map +1 -0
  384. package/dist/factories/simple/storage/persistent-volume.d.ts +17 -0
  385. package/dist/factories/simple/storage/persistent-volume.d.ts.map +1 -0
  386. package/dist/factories/simple/storage/persistent-volume.js +44 -0
  387. package/dist/factories/simple/storage/persistent-volume.js.map +1 -0
  388. package/dist/factories/simple/types.d.ts +165 -0
  389. package/dist/factories/simple/types.d.ts.map +1 -0
  390. package/dist/factories/simple/types.js +9 -0
  391. package/dist/factories/simple/types.js.map +1 -0
  392. package/dist/factories/simple/workloads/cron-job.d.ts +17 -0
  393. package/dist/factories/simple/workloads/cron-job.d.ts.map +1 -0
  394. package/dist/factories/simple/workloads/cron-job.js +43 -0
  395. package/dist/factories/simple/workloads/cron-job.js.map +1 -0
  396. package/dist/factories/simple/workloads/daemon-set.d.ts +17 -0
  397. package/dist/factories/simple/workloads/daemon-set.d.ts.map +1 -0
  398. package/dist/factories/simple/workloads/daemon-set.js +46 -0
  399. package/dist/factories/simple/workloads/daemon-set.js.map +1 -0
  400. package/dist/factories/simple/workloads/deployment.d.ts +17 -0
  401. package/dist/factories/simple/workloads/deployment.d.ts.map +1 -0
  402. package/dist/factories/simple/workloads/deployment.js +47 -0
  403. package/dist/factories/simple/workloads/deployment.js.map +1 -0
  404. package/dist/factories/simple/workloads/index.d.ts +12 -0
  405. package/dist/factories/simple/workloads/index.d.ts.map +1 -0
  406. package/dist/factories/simple/workloads/index.js +12 -0
  407. package/dist/factories/simple/workloads/index.js.map +1 -0
  408. package/dist/factories/simple/workloads/job.d.ts +17 -0
  409. package/dist/factories/simple/workloads/job.d.ts.map +1 -0
  410. package/dist/factories/simple/workloads/job.js +40 -0
  411. package/dist/factories/simple/workloads/job.js.map +1 -0
  412. package/dist/factories/simple/workloads/stateful-set.d.ts +17 -0
  413. package/dist/factories/simple/workloads/stateful-set.d.ts.map +1 -0
  414. package/dist/factories/simple/workloads/stateful-set.js +47 -0
  415. package/dist/factories/simple/workloads/stateful-set.js.map +1 -0
  416. package/dist/factories/simple/yaml/index.d.ts +13 -0
  417. package/dist/factories/simple/yaml/index.d.ts.map +1 -0
  418. package/dist/factories/simple/yaml/index.js +23 -0
  419. package/dist/factories/simple/yaml/index.js.map +1 -0
  420. package/dist/index.d.ts +5 -3
  421. package/dist/index.d.ts.map +1 -1
  422. package/dist/index.js +25 -22
  423. package/dist/index.js.map +1 -1
  424. package/dist/utils/helpers.d.ts +1 -1
  425. package/dist/utils/helpers.d.ts.map +1 -1
  426. package/dist/utils/helpers.js +53 -7
  427. package/dist/utils/helpers.js.map +1 -1
  428. package/dist/utils/index.d.ts +2 -2
  429. package/dist/utils/index.d.ts.map +1 -1
  430. package/dist/utils/index.js +2 -2
  431. package/dist/utils/index.js.map +1 -1
  432. package/dist/utils/type-guards.d.ts +1 -1
  433. package/dist/utils/type-guards.d.ts.map +1 -1
  434. package/dist/utils/type-guards.js +3 -9
  435. package/dist/utils/type-guards.js.map +1 -1
  436. package/package.json +12 -6
@@ -0,0 +1,738 @@
1
+ /**
2
+ * EventMonitor - Kubernetes Events Monitoring with Server-Side Filtering
3
+ *
4
+ * Monitors Kubernetes events related to deployed resources using efficient
5
+ * server-side filtering to minimize network traffic and improve performance.
6
+ */
7
+ import * as k8s from '@kubernetes/client-node';
8
+ import { getComponentLogger } from '../logging/index.js';
9
+ /**
10
+ * EventMonitor manages Kubernetes event watching with server-side filtering
11
+ */
12
+ export class EventMonitor {
13
+ k8sApi;
14
+ kubeConfig;
15
+ watchConnections = new Map();
16
+ monitoredResources = new Map();
17
+ resourceRelationships = new Map();
18
+ childDiscoveryInProgress = new Set();
19
+ options;
20
+ logger = getComponentLogger('event-monitor');
21
+ isMonitoring = false;
22
+ startResourceVersion;
23
+ eventsProcessed = 0;
24
+ appsApi;
25
+ watchFactory;
26
+ constructor(k8sApi, kubeConfig, options = {}, watchFactory) {
27
+ this.k8sApi = k8sApi;
28
+ this.kubeConfig = kubeConfig;
29
+ this.appsApi = kubeConfig.makeApiClient(k8s.AppsV1Api);
30
+ this.watchFactory = watchFactory || ((config) => new k8s.Watch(config));
31
+ this.options = {
32
+ namespace: options.namespace || 'default',
33
+ eventTypes: options.eventTypes || ['Warning', 'Error'],
34
+ includeChildResources: options.includeChildResources ?? true,
35
+ startTime: options.startTime || new Date(),
36
+ progressCallback: options.progressCallback ||
37
+ (() => {
38
+ /* no-op */
39
+ }),
40
+ maxWatchConnections: options.maxWatchConnections || 10,
41
+ watchTimeoutSeconds: options.watchTimeoutSeconds || 300, // 5 minutes
42
+ };
43
+ }
44
+ /**
45
+ * Start monitoring events for deployed resources
46
+ */
47
+ async startMonitoring(deployedResources) {
48
+ if (this.isMonitoring) {
49
+ this.logger.warn('Event monitoring already started');
50
+ return;
51
+ }
52
+ this.logger.info('Starting event monitoring', {
53
+ resourceCount: deployedResources.length,
54
+ namespace: this.options.namespace,
55
+ eventTypes: this.options.eventTypes,
56
+ });
57
+ try {
58
+ // Get resource version for time-based filtering
59
+ this.startResourceVersion = await this.getResourceVersionForTime(this.options.startTime);
60
+ // Add resources to monitoring
61
+ for (const resource of deployedResources) {
62
+ await this.addResource(resource);
63
+ }
64
+ // If no resources were provided, create a namespace-wide watch connection
65
+ // to capture all events that will be generated during deployment
66
+ if (deployedResources.length === 0) {
67
+ await this.createNamespaceWideWatchConnection();
68
+ }
69
+ this.isMonitoring = true;
70
+ this.logger.info('Event monitoring started successfully', {
71
+ watchConnections: this.watchConnections.size,
72
+ monitoredResources: this.monitoredResources.size,
73
+ });
74
+ }
75
+ catch (error) {
76
+ this.logger.error('Failed to start event monitoring', error);
77
+ await this.stopMonitoring();
78
+ throw error;
79
+ }
80
+ }
81
+ /**
82
+ * Stop monitoring and clean up all watch connections
83
+ */
84
+ async stopMonitoring() {
85
+ if (!this.isMonitoring) {
86
+ return;
87
+ }
88
+ this.logger.info('Stopping event monitoring', {
89
+ watchConnections: this.watchConnections.size,
90
+ });
91
+ // Close all watch connections
92
+ for (const [key, connection] of this.watchConnections) {
93
+ try {
94
+ if (connection.request && typeof connection.request.abort === 'function') {
95
+ connection.request.abort();
96
+ }
97
+ this.logger.debug('Closed watch connection', { key, kind: connection.kind });
98
+ }
99
+ catch (error) {
100
+ this.logger.warn('Error closing watch connection', error);
101
+ }
102
+ }
103
+ this.watchConnections.clear();
104
+ this.monitoredResources.clear();
105
+ this.resourceRelationships.clear();
106
+ this.childDiscoveryInProgress.clear();
107
+ this.isMonitoring = false;
108
+ this.logger.info('Event monitoring stopped', {
109
+ eventsProcessed: this.eventsProcessed,
110
+ });
111
+ // Reset counter for next monitoring session
112
+ this.eventsProcessed = 0;
113
+ }
114
+ /**
115
+ * Add a resource to monitoring
116
+ */
117
+ async addResource(resource) {
118
+ const resourceId = this.getResourceId(resource);
119
+ const resourceIdentifier = {
120
+ kind: resource.kind,
121
+ name: resource.name,
122
+ namespace: resource.namespace || this.options.namespace,
123
+ ...(resource.manifest.metadata?.uid && { uid: resource.manifest.metadata.uid }),
124
+ };
125
+ this.monitoredResources.set(resourceId, resourceIdentifier);
126
+ // Create or update watch connection for this resource
127
+ await this.ensureWatchConnection(resourceIdentifier);
128
+ this.logger.debug('Added resource to monitoring', {
129
+ resourceId,
130
+ kind: resource.kind,
131
+ name: resource.name,
132
+ namespace: resourceIdentifier.namespace,
133
+ });
134
+ // Trigger child resource discovery if enabled and resource has UID
135
+ if (this.options.includeChildResources && resourceIdentifier.uid) {
136
+ // Use setTimeout to avoid blocking the main flow
137
+ setTimeout(() => {
138
+ this.discoverChildResources(resource).catch((error) => {
139
+ this.logger.warn('Child resource discovery failed', {
140
+ error: error,
141
+ resourceId,
142
+ kind: resource.kind,
143
+ name: resource.name,
144
+ });
145
+ });
146
+ }, 1000); // Wait 1 second to allow resource to be fully created
147
+ }
148
+ }
149
+ /**
150
+ * Remove a resource from monitoring
151
+ */
152
+ async removeResource(resource) {
153
+ const resourceId = this.getResourceId(resource);
154
+ const resourceIdentifier = this.monitoredResources.get(resourceId);
155
+ if (!resourceIdentifier) {
156
+ return;
157
+ }
158
+ this.monitoredResources.delete(resourceId);
159
+ // Remove from relationships
160
+ this.resourceRelationships.delete(resourceId);
161
+ // Update or remove watch connection
162
+ await this.updateWatchConnection(resourceIdentifier, 'remove');
163
+ this.logger.debug('Removed resource from monitoring', {
164
+ resourceId,
165
+ kind: resource.kind,
166
+ name: resource.name,
167
+ });
168
+ }
169
+ /**
170
+ * Add additional resources to monitor (for child resource discovery)
171
+ */
172
+ async addResources(resources) {
173
+ for (const resource of resources) {
174
+ await this.addResource(resource);
175
+ }
176
+ }
177
+ /**
178
+ * Discover and monitor child resources created by parent resources
179
+ */
180
+ async discoverChildResources(parentResource) {
181
+ if (!this.options.includeChildResources) {
182
+ return;
183
+ }
184
+ const parentId = this.getResourceId(parentResource);
185
+ // Prevent concurrent discovery for the same resource
186
+ if (this.childDiscoveryInProgress.has(parentId)) {
187
+ return;
188
+ }
189
+ this.childDiscoveryInProgress.add(parentId);
190
+ try {
191
+ const parentIdentifier = this.monitoredResources.get(parentId);
192
+ if (!parentIdentifier || !parentIdentifier.uid) {
193
+ this.logger.debug('Cannot discover children for resource without UID', {
194
+ parentId,
195
+ kind: parentResource.kind,
196
+ name: parentResource.name,
197
+ });
198
+ return;
199
+ }
200
+ this.logger.debug('Starting child resource discovery', {
201
+ parentId,
202
+ parentKind: parentResource.kind,
203
+ parentName: parentResource.name,
204
+ parentUid: parentIdentifier.uid,
205
+ });
206
+ const childResources = await this.findChildResources(parentIdentifier);
207
+ if (childResources.length > 0) {
208
+ // Create relationship record
209
+ const relationship = {
210
+ parent: parentIdentifier,
211
+ children: childResources,
212
+ discoveredAt: new Date(),
213
+ relationshipType: this.determineRelationshipType(parentResource.kind),
214
+ };
215
+ this.resourceRelationships.set(parentId, relationship);
216
+ // Add child resources to monitoring (only those with UIDs)
217
+ for (const childResource of childResources.filter((r) => r.uid)) {
218
+ const childDeployedResource = {
219
+ id: `${childResource.kind}-${childResource.name}`,
220
+ kind: childResource.kind,
221
+ name: childResource.name,
222
+ namespace: childResource.namespace || parentResource.namespace,
223
+ status: 'deployed',
224
+ deployedAt: new Date(),
225
+ manifest: {
226
+ apiVersion: this.getApiVersionForKind(childResource.kind),
227
+ kind: childResource.kind,
228
+ metadata: {
229
+ name: childResource.name,
230
+ namespace: childResource.namespace || parentResource.namespace,
231
+ uid: childResource.uid || '',
232
+ },
233
+ },
234
+ };
235
+ await this.addResource(childDeployedResource);
236
+ // Emit child resource discovered event
237
+ const discoveredEvent = {
238
+ type: 'child-resource-discovered',
239
+ message: `Discovered child resource ${childResource.kind}/${childResource.name}`,
240
+ timestamp: new Date(),
241
+ parentResource: parentIdentifier,
242
+ childResource: childResource,
243
+ relationshipType: relationship.relationshipType,
244
+ };
245
+ this.options.progressCallback(discoveredEvent);
246
+ this.logger.info('Discovered and added child resource to monitoring', {
247
+ parentId,
248
+ childKind: childResource.kind,
249
+ childName: childResource.name,
250
+ relationshipType: relationship.relationshipType,
251
+ });
252
+ }
253
+ }
254
+ }
255
+ catch (error) {
256
+ this.logger.error('Failed to discover child resources', error, {
257
+ parentId,
258
+ parentKind: parentResource.kind,
259
+ parentName: parentResource.name,
260
+ });
261
+ }
262
+ finally {
263
+ this.childDiscoveryInProgress.delete(parentId);
264
+ }
265
+ }
266
+ /**
267
+ * Find child resources using owner references
268
+ */
269
+ async findChildResources(parentResource) {
270
+ const childResources = [];
271
+ const namespace = parentResource.namespace || this.options.namespace;
272
+ try {
273
+ // Define resource types that commonly have children
274
+ const childResourceTypes = this.getChildResourceTypes(parentResource.kind);
275
+ for (const resourceType of childResourceTypes) {
276
+ try {
277
+ const resources = await this.listResourcesWithOwnerReference(resourceType, namespace, parentResource.uid || '');
278
+ childResources.push(...resources);
279
+ }
280
+ catch (error) {
281
+ this.logger.debug('Failed to list child resources of type', {
282
+ error: error,
283
+ resourceType,
284
+ parentKind: parentResource.kind,
285
+ parentName: parentResource.name,
286
+ });
287
+ // Continue with other resource types
288
+ }
289
+ }
290
+ }
291
+ catch (error) {
292
+ this.logger.error('Error during child resource discovery', error, {
293
+ parentKind: parentResource.kind,
294
+ parentName: parentResource.name,
295
+ });
296
+ }
297
+ return childResources;
298
+ }
299
+ /**
300
+ * List resources with specific owner reference
301
+ */
302
+ async listResourcesWithOwnerReference(resourceType, namespace, ownerUid) {
303
+ const resources = [];
304
+ try {
305
+ let resourceList;
306
+ // Handle different resource types
307
+ switch (resourceType) {
308
+ case 'ReplicaSet':
309
+ resourceList = await this.appsApi.listNamespacedReplicaSet(namespace);
310
+ break;
311
+ case 'Pod':
312
+ resourceList = await this.k8sApi.listNamespacedPod(namespace);
313
+ break;
314
+ case 'Service':
315
+ resourceList = await this.k8sApi.listNamespacedService(namespace);
316
+ break;
317
+ case 'ConfigMap':
318
+ resourceList = await this.k8sApi.listNamespacedConfigMap(namespace);
319
+ break;
320
+ case 'Secret':
321
+ resourceList = await this.k8sApi.listNamespacedSecret(namespace);
322
+ break;
323
+ default:
324
+ this.logger.debug('Unsupported child resource type for discovery', { resourceType });
325
+ return resources;
326
+ }
327
+ // Filter by owner reference
328
+ for (const item of resourceList.body.items) {
329
+ const resource = item;
330
+ if (resource.metadata?.ownerReferences) {
331
+ const hasOwnerReference = resource.metadata.ownerReferences.some((ref) => ref.uid === ownerUid);
332
+ if (hasOwnerReference && resource.metadata.name && resource.metadata.uid) {
333
+ resources.push({
334
+ kind: resourceType,
335
+ name: resource.metadata.name,
336
+ namespace: resource.metadata.namespace || namespace,
337
+ uid: resource.metadata.uid,
338
+ });
339
+ }
340
+ }
341
+ }
342
+ }
343
+ catch (error) {
344
+ this.logger.debug('Failed to list resources for owner reference check', {
345
+ error: error,
346
+ resourceType,
347
+ namespace,
348
+ ownerUid,
349
+ });
350
+ }
351
+ return resources;
352
+ }
353
+ /**
354
+ * Get potential child resource types for a parent resource kind
355
+ */
356
+ getChildResourceTypes(parentKind) {
357
+ const childTypeMap = {
358
+ Deployment: ['ReplicaSet', 'Pod'],
359
+ ReplicaSet: ['Pod'],
360
+ StatefulSet: ['Pod'],
361
+ DaemonSet: ['Pod'],
362
+ Job: ['Pod'],
363
+ CronJob: ['Job', 'Pod'],
364
+ Service: [], // Services don't typically create child resources
365
+ ConfigMap: [], // ConfigMaps don't create child resources
366
+ Secret: [], // Secrets don't create child resources
367
+ };
368
+ return childTypeMap[parentKind] || [];
369
+ }
370
+ /**
371
+ * Determine relationship type based on parent resource kind
372
+ */
373
+ determineRelationshipType(parentKind) {
374
+ const relationshipMap = {
375
+ Deployment: 'manages',
376
+ ReplicaSet: 'owns',
377
+ StatefulSet: 'manages',
378
+ DaemonSet: 'manages',
379
+ Job: 'owns',
380
+ CronJob: 'creates',
381
+ };
382
+ return relationshipMap[parentKind] || 'owns';
383
+ }
384
+ /**
385
+ * Get API version for a resource kind
386
+ */
387
+ getApiVersionForKind(kind) {
388
+ const apiVersionMap = {
389
+ Pod: 'v1',
390
+ Service: 'v1',
391
+ ConfigMap: 'v1',
392
+ Secret: 'v1',
393
+ Deployment: 'apps/v1',
394
+ ReplicaSet: 'apps/v1',
395
+ StatefulSet: 'apps/v1',
396
+ DaemonSet: 'apps/v1',
397
+ Job: 'batch/v1',
398
+ CronJob: 'batch/v1',
399
+ };
400
+ return apiVersionMap[kind] || 'v1';
401
+ }
402
+ /**
403
+ * Ensure a watch connection exists for the given resource
404
+ */
405
+ async ensureWatchConnection(resource) {
406
+ const connectionKey = this.getConnectionKey(resource);
407
+ let connection = this.watchConnections.get(connectionKey);
408
+ if (!connection) {
409
+ // Create new watch connection
410
+ connection = await this.createWatchConnection(resource);
411
+ this.watchConnections.set(connectionKey, connection);
412
+ }
413
+ else {
414
+ // Add resource to existing connection
415
+ connection.resources.add(resource.name);
416
+ // Update field selector if needed
417
+ await this.updateConnectionFieldSelector(connection);
418
+ }
419
+ }
420
+ /**
421
+ * Create a new watch connection for a resource kind/namespace combination
422
+ */
423
+ async createWatchConnection(resource) {
424
+ const namespace = resource.namespace || this.options.namespace;
425
+ const fieldSelector = this.buildFieldSelector([resource]);
426
+ this.logger.debug('Creating watch connection', {
427
+ kind: resource.kind,
428
+ namespace,
429
+ fieldSelector,
430
+ });
431
+ const watcher = this.watchFactory(this.kubeConfig);
432
+ const connection = {
433
+ kind: resource.kind,
434
+ namespace,
435
+ fieldSelector,
436
+ watcher,
437
+ resources: new Set([resource.name]),
438
+ ...(this.startResourceVersion && { lastResourceVersion: this.startResourceVersion }),
439
+ };
440
+ // Start watching
441
+ await this.startWatchConnection(connection);
442
+ return connection;
443
+ }
444
+ /**
445
+ * Start a watch connection
446
+ */
447
+ async startWatchConnection(connection) {
448
+ try {
449
+ const watchOptions = {
450
+ timeoutSeconds: this.options.watchTimeoutSeconds,
451
+ };
452
+ // Only add fieldSelector if it's not empty
453
+ if (connection.fieldSelector) {
454
+ watchOptions.fieldSelector = connection.fieldSelector;
455
+ }
456
+ if (connection.lastResourceVersion) {
457
+ watchOptions.resourceVersion = connection.lastResourceVersion;
458
+ }
459
+ this.logger.debug('Starting watch connection with options', {
460
+ kind: connection.kind,
461
+ namespace: connection.namespace,
462
+ fieldSelector: connection.fieldSelector || '(none - watch all)',
463
+ watchOptions,
464
+ });
465
+ const request = await connection.watcher.watch(`/api/v1/namespaces/${connection.namespace}/events`, watchOptions, (type, apiObj, watchObj) => {
466
+ this.handleWatchEvent(type, apiObj, watchObj, connection);
467
+ }, (error) => {
468
+ this.handleWatchError(error, connection);
469
+ });
470
+ // Ensure the request object has an abort method
471
+ connection.request =
472
+ request && typeof request === 'object' && 'abort' in request
473
+ ? request
474
+ : {
475
+ abort: () => {
476
+ /* no-op for testing */
477
+ },
478
+ };
479
+ this.logger.debug('Watch connection started', {
480
+ kind: connection.kind,
481
+ namespace: connection.namespace,
482
+ resourceCount: connection.resources.size,
483
+ });
484
+ }
485
+ catch (error) {
486
+ this.logger.error('Failed to start watch connection', error, {
487
+ kind: connection.kind,
488
+ namespace: connection.namespace,
489
+ });
490
+ throw error;
491
+ }
492
+ }
493
+ /**
494
+ * Handle watch events
495
+ */
496
+ handleWatchEvent(type, event, watchObj, connection) {
497
+ try {
498
+ // Debug: Log that we received an event
499
+ this.logger.debug('Received watch event', {
500
+ type,
501
+ eventType: event.type,
502
+ reason: event.reason,
503
+ involvedObject: `${event.involvedObject?.kind}/${event.involvedObject?.name}`,
504
+ namespace: event.involvedObject?.namespace,
505
+ connectionKind: connection.kind,
506
+ });
507
+ // Update resource version for reconnection
508
+ if (watchObj && typeof watchObj === 'object' && 'metadata' in watchObj) {
509
+ const metadata = watchObj.metadata;
510
+ if (metadata?.resourceVersion) {
511
+ connection.lastResourceVersion = metadata.resourceVersion;
512
+ }
513
+ }
514
+ // Skip if event type is not in our filter
515
+ if (event.type &&
516
+ !this.options.eventTypes.includes(event.type)) {
517
+ return;
518
+ }
519
+ // Convert to our event format
520
+ const kubernetesEvent = this.convertToKubernetesEvent(event);
521
+ // Increment event counter
522
+ this.eventsProcessed++;
523
+ // Emit event via progress callback if available, otherwise log to console
524
+ if (this.options.progressCallback) {
525
+ this.options.progressCallback(kubernetesEvent);
526
+ }
527
+ else {
528
+ // Fallback to console logging when no progress callback is provided
529
+ this.logger.info('Kubernetes Event', {
530
+ type: event.type,
531
+ reason: event.reason,
532
+ involvedObject: `${event.involvedObject?.kind}/${event.involvedObject?.name}`,
533
+ namespace: event.involvedObject?.namespace,
534
+ message: event.message,
535
+ timestamp: event.lastTimestamp || event.firstTimestamp,
536
+ });
537
+ }
538
+ this.logger.debug('Processed Kubernetes event', {
539
+ eventType: event.type,
540
+ reason: event.reason,
541
+ involvedObject: `${event.involvedObject?.kind}/${event.involvedObject?.name}`,
542
+ message: event.message?.substring(0, 100),
543
+ hasCallback: !!this.options.progressCallback,
544
+ });
545
+ }
546
+ catch (error) {
547
+ this.logger.error('Error handling watch event', error, {
548
+ eventType: type,
549
+ eventReason: event.reason,
550
+ });
551
+ }
552
+ }
553
+ /**
554
+ * Handle watch errors
555
+ */
556
+ handleWatchError(error, _connection) {
557
+ this.logger.warn('Watch connection error', error);
558
+ // Implement reconnection logic here
559
+ // For now, just log the error
560
+ // TODO: Add exponential backoff retry logic
561
+ }
562
+ /**
563
+ * Update watch connection when resources are added/removed
564
+ */
565
+ async updateWatchConnection(resource, action) {
566
+ const connectionKey = this.getConnectionKey(resource);
567
+ const connection = this.watchConnections.get(connectionKey);
568
+ if (!connection) {
569
+ return;
570
+ }
571
+ if (action === 'add') {
572
+ connection.resources.add(resource.name);
573
+ }
574
+ else {
575
+ connection.resources.delete(resource.name);
576
+ }
577
+ // If no resources left, remove the connection
578
+ if (connection.resources.size === 0) {
579
+ if (connection.request && typeof connection.request.abort === 'function') {
580
+ connection.request.abort();
581
+ }
582
+ this.watchConnections.delete(connectionKey);
583
+ this.logger.debug('Removed empty watch connection', { connectionKey });
584
+ return;
585
+ }
586
+ // Update field selector
587
+ await this.updateConnectionFieldSelector(connection);
588
+ }
589
+ /**
590
+ * Update the field selector for a connection
591
+ */
592
+ async updateConnectionFieldSelector(connection) {
593
+ const resources = Array.from(connection.resources).map((name) => ({
594
+ kind: connection.kind,
595
+ name,
596
+ namespace: connection.namespace,
597
+ }));
598
+ const newFieldSelector = this.buildFieldSelector(resources);
599
+ if (newFieldSelector !== connection.fieldSelector) {
600
+ connection.fieldSelector = newFieldSelector;
601
+ // Restart the watch connection with new field selector
602
+ if (connection.request && typeof connection.request.abort === 'function') {
603
+ connection.request.abort();
604
+ }
605
+ await this.startWatchConnection(connection);
606
+ this.logger.debug('Updated watch connection field selector', {
607
+ kind: connection.kind,
608
+ namespace: connection.namespace,
609
+ fieldSelector: newFieldSelector,
610
+ });
611
+ }
612
+ }
613
+ /**
614
+ * Create a namespace-wide watch connection to capture all events
615
+ * This is used when starting monitoring without specific resources
616
+ */
617
+ async createNamespaceWideWatchConnection() {
618
+ const namespace = this.options.namespace || 'default';
619
+ const connectionKey = `namespace-wide-${namespace}`;
620
+ if (this.watchConnections.has(connectionKey)) {
621
+ return; // Already exists
622
+ }
623
+ this.logger.debug('Creating namespace-wide watch connection', {
624
+ namespace,
625
+ });
626
+ const watcher = this.watchFactory(this.kubeConfig);
627
+ const connection = {
628
+ kind: '*', // Special marker for namespace-wide connection
629
+ namespace,
630
+ fieldSelector: '', // Empty selector watches all events in namespace
631
+ watcher,
632
+ resources: new Set(),
633
+ ...(this.startResourceVersion && { lastResourceVersion: this.startResourceVersion }),
634
+ };
635
+ this.watchConnections.set(connectionKey, connection);
636
+ await this.startWatchConnection(connection);
637
+ this.logger.debug('Created namespace-wide watch connection', {
638
+ namespace,
639
+ });
640
+ }
641
+ /**
642
+ * Build field selector for resources
643
+ */
644
+ buildFieldSelector(resources) {
645
+ if (resources.length === 0) {
646
+ return '';
647
+ }
648
+ // Group by kind for efficient filtering
649
+ const resourcesByKind = new Map();
650
+ for (const resource of resources) {
651
+ const names = resourcesByKind.get(resource.kind) || [];
652
+ names.push(resource.name);
653
+ resourcesByKind.set(resource.kind, names);
654
+ }
655
+ // Build field selector
656
+ const selectors = [];
657
+ for (const [kind, names] of resourcesByKind) {
658
+ if (names.length === 1) {
659
+ // Single resource
660
+ selectors.push(`involvedObject.kind=${kind},involvedObject.name=${names[0]}`);
661
+ }
662
+ else {
663
+ // Multiple resources of same kind - need separate selectors
664
+ // Note: Kubernetes doesn't support OR in field selectors, so we'll use the kind filter
665
+ // and do name filtering client-side for now
666
+ selectors.push(`involvedObject.kind=${kind}`);
667
+ }
668
+ }
669
+ return selectors.join(',');
670
+ }
671
+ /**
672
+ * Convert Kubernetes event to our event format
673
+ */
674
+ convertToKubernetesEvent(event) {
675
+ return {
676
+ type: 'kubernetes-event',
677
+ eventType: event.type || 'Normal',
678
+ reason: event.reason || 'Unknown',
679
+ message: `[${event.involvedObject?.kind}/${event.involvedObject?.name}] ${event.reason}: ${event.message}`,
680
+ timestamp: new Date(),
681
+ source: {
682
+ component: event.source?.component || 'unknown',
683
+ ...(event.source?.host && { host: event.source.host }),
684
+ },
685
+ involvedObject: {
686
+ kind: event.involvedObject?.kind || 'Unknown',
687
+ name: event.involvedObject?.name || 'unknown',
688
+ ...(event.involvedObject?.namespace && { namespace: event.involvedObject.namespace }),
689
+ ...(event.involvedObject?.uid && { uid: event.involvedObject.uid }),
690
+ },
691
+ ...(event.count && { count: event.count }),
692
+ ...(event.firstTimestamp && { firstTimestamp: new Date(event.firstTimestamp) }),
693
+ ...(event.lastTimestamp && { lastTimestamp: new Date(event.lastTimestamp) }),
694
+ eventMessage: event.message || '',
695
+ };
696
+ }
697
+ /**
698
+ * Get resource version for time-based filtering
699
+ */
700
+ async getResourceVersionForTime(_time) {
701
+ try {
702
+ // Get a recent event to establish current resource version
703
+ const eventList = await this.k8sApi.listNamespacedEvent(this.options.namespace, undefined, // pretty
704
+ undefined, // allowWatchBookmarks
705
+ undefined, // continue
706
+ undefined, // fieldSelector
707
+ undefined, // labelSelector
708
+ 1 // limit to 1 event
709
+ );
710
+ return eventList.body.metadata?.resourceVersion || '0';
711
+ }
712
+ catch (error) {
713
+ this.logger.warn('Failed to get resource version for time filtering', error);
714
+ // Don't throw - continue with default resource version
715
+ return '0';
716
+ }
717
+ }
718
+ /**
719
+ * Get unique resource identifier
720
+ */
721
+ getResourceId(resource) {
722
+ return `${resource.kind}/${resource.name}/${resource.namespace || this.options.namespace}`;
723
+ }
724
+ /**
725
+ * Get connection key for watch connection pooling
726
+ */
727
+ getConnectionKey(resource) {
728
+ return `${resource.kind}/${resource.namespace || this.options.namespace}`;
729
+ }
730
+ }
731
+ /**
732
+ * Create an EventMonitor instance
733
+ */
734
+ export function createEventMonitor(kubeConfig, options = {}, watchFactory) {
735
+ const k8sApi = kubeConfig.makeApiClient(k8s.CoreV1Api);
736
+ return new EventMonitor(k8sApi, kubeConfig, options, watchFactory);
737
+ }
738
+ //# sourceMappingURL=event-monitor.js.map