@highstate/k8s 0.9.18 → 0.9.20

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 (93) hide show
  1. package/dist/chunk-2EEHJZPD.js +13 -0
  2. package/dist/chunk-2EEHJZPD.js.map +1 -0
  3. package/dist/{chunk-OFFSHGC6.js → chunk-4JGXGN2L.js} +66 -48
  4. package/dist/chunk-4JGXGN2L.js.map +1 -0
  5. package/dist/chunk-A3XGSDIW.js +306 -0
  6. package/dist/chunk-A3XGSDIW.js.map +1 -0
  7. package/dist/chunk-IMTXUK2U.js +244 -0
  8. package/dist/chunk-IMTXUK2U.js.map +1 -0
  9. package/dist/chunk-JYNXQ3I3.js +287 -0
  10. package/dist/chunk-JYNXQ3I3.js.map +1 -0
  11. package/dist/{chunk-5C2BJGES.js → chunk-KDD6XUWM.js} +30 -23
  12. package/dist/chunk-KDD6XUWM.js.map +1 -0
  13. package/dist/chunk-NOFJC3EM.js +236 -0
  14. package/dist/chunk-NOFJC3EM.js.map +1 -0
  15. package/dist/chunk-NXSYCA3V.js +337 -0
  16. package/dist/chunk-NXSYCA3V.js.map +1 -0
  17. package/dist/chunk-SBC3TUIN.js +1513 -0
  18. package/dist/chunk-SBC3TUIN.js.map +1 -0
  19. package/dist/chunk-SI7X6N46.js +338 -0
  20. package/dist/chunk-SI7X6N46.js.map +1 -0
  21. package/dist/chunk-WGMJCZSK.js +360 -0
  22. package/dist/chunk-WGMJCZSK.js.map +1 -0
  23. package/dist/deployment-752P6JIT.js +8 -0
  24. package/dist/{deployment-XK3CDJOE.js.map → deployment-752P6JIT.js.map} +1 -1
  25. package/dist/highstate.manifest.json +8 -7
  26. package/dist/impl/gateway-route.js +123 -0
  27. package/dist/impl/gateway-route.js.map +1 -0
  28. package/dist/impl/tls-certificate.js +32 -0
  29. package/dist/impl/tls-certificate.js.map +1 -0
  30. package/dist/index.js +736 -208
  31. package/dist/index.js.map +1 -1
  32. package/dist/stateful-set-N64YVKR7.js +8 -0
  33. package/dist/{stateful-set-7CAQWTV2.js.map → stateful-set-N64YVKR7.js.map} +1 -1
  34. package/dist/units/cert-manager/index.js +11 -10
  35. package/dist/units/cert-manager/index.js.map +1 -1
  36. package/dist/units/dns01-issuer/index.js +27 -23
  37. package/dist/units/dns01-issuer/index.js.map +1 -1
  38. package/dist/units/existing-cluster/index.js +11 -8
  39. package/dist/units/existing-cluster/index.js.map +1 -1
  40. package/dist/units/gateway-api/index.js +2 -2
  41. package/dist/units/gateway-api/index.js.map +1 -1
  42. package/package.json +39 -13
  43. package/src/cluster.ts +30 -22
  44. package/src/config-map.ts +195 -57
  45. package/src/container.ts +5 -5
  46. package/src/cron-job.ts +403 -31
  47. package/src/deployment.ts +260 -120
  48. package/src/dns01-solver.ts +10 -0
  49. package/src/gateway/backend.ts +2 -2
  50. package/src/gateway/gateway.ts +383 -0
  51. package/src/gateway/http-route.ts +17 -24
  52. package/src/gateway/index.ts +1 -0
  53. package/src/helm.ts +83 -53
  54. package/src/impl/gateway-route.ts +155 -0
  55. package/src/impl/tls-certificate.ts +33 -0
  56. package/src/index.ts +22 -67
  57. package/src/job.ts +393 -28
  58. package/src/namespace.ts +236 -99
  59. package/src/network-policy.ts +216 -165
  60. package/src/network.ts +2 -2
  61. package/src/pvc.ts +266 -65
  62. package/src/rbac.ts +218 -0
  63. package/src/scripting/bundle.ts +9 -20
  64. package/src/scripting/container.ts +1 -1
  65. package/src/scripting/environment.ts +5 -5
  66. package/src/secret.ts +200 -62
  67. package/src/service.ts +288 -158
  68. package/src/shared.ts +94 -67
  69. package/src/stateful-set.ts +270 -117
  70. package/src/tls.ts +344 -0
  71. package/src/units/cert-manager/index.ts +2 -3
  72. package/src/units/dns01-issuer/index.ts +30 -14
  73. package/src/units/existing-cluster/index.ts +10 -7
  74. package/src/units/gateway-api/index.ts +2 -2
  75. package/src/worker.ts +26 -0
  76. package/src/workload.ts +275 -171
  77. package/dist/chunk-5C2BJGES.js.map +0 -1
  78. package/dist/chunk-5TLC5BXR.js +0 -256
  79. package/dist/chunk-5TLC5BXR.js.map +0 -1
  80. package/dist/chunk-BBIY3KUN.js +0 -1557
  81. package/dist/chunk-BBIY3KUN.js.map +0 -1
  82. package/dist/chunk-OFFSHGC6.js.map +0 -1
  83. package/dist/chunk-TZHOUJRC.js +0 -202
  84. package/dist/chunk-TZHOUJRC.js.map +0 -1
  85. package/dist/chunk-YWRJ4EZM.js +0 -192
  86. package/dist/chunk-YWRJ4EZM.js.map +0 -1
  87. package/dist/deployment-XK3CDJOE.js +0 -6
  88. package/dist/stateful-set-7CAQWTV2.js +0 -6
  89. package/dist/units/access-point/index.js +0 -21
  90. package/dist/units/access-point/index.js.map +0 -1
  91. package/src/access-point.ts +0 -191
  92. package/src/units/access-point/index.ts +0 -19
  93. package/src/units/dns01-issuer/solver.ts +0 -23
package/src/shared.ts CHANGED
@@ -1,47 +1,44 @@
1
1
  import type { PartialKeys } from "@highstate/contract"
2
2
  import type { k8s } from "@highstate/library"
3
- import { interpolate, Output, output, toPromise, type Input, type Unwrap } from "@highstate/pulumi"
4
- import { core, Provider, types } from "@pulumi/kubernetes"
3
+ import {
4
+ ComponentResource,
5
+ type ComponentResourceOptions,
6
+ type Input,
7
+ type Inputs,
8
+ type Output,
9
+ output,
10
+ secret,
11
+ toPromise,
12
+ type Unwrap,
13
+ } from "@highstate/pulumi"
14
+ import { core, Provider, type types } from "@pulumi/kubernetes"
5
15
  import * as images from "../assets/images.json"
6
16
  import { Namespace } from "./namespace"
7
17
 
8
- const providers = new Map<string, Provider>()
18
+ const providers = new Map<`${string}.${string}`, Provider>()
9
19
 
10
- export function getProvider(cluster: Input<k8s.Cluster>): Promise<Provider> {
11
- const provider = output(cluster).apply(cluster => {
12
- const existingProvider = providers.get(cluster.id)
13
- if (existingProvider) {
14
- return existingProvider
15
- }
16
-
17
- const provider = new Provider(`${cluster.name}-${cluster.id}`, {
18
- kubeconfig: cluster.kubeconfig,
19
- })
20
- providers.set(cluster.id, provider)
20
+ export function getProvider(cluster: k8s.Cluster): Provider {
21
+ const name = `${cluster.name}.${cluster.connectionId}` as const
22
+ const existing = providers.get(name)
23
+ if (existing) {
24
+ return existing
25
+ }
21
26
 
22
- return provider
23
- })
27
+ const provider = new Provider(name, { kubeconfig: secret(cluster.kubeconfig) })
28
+ providers.set(name, provider)
24
29
 
25
- return toPromise(provider)
30
+ return provider
26
31
  }
27
32
 
28
- export function getProviderSync(cluster: k8s.Cluster): Provider {
29
- const existingProvider = providers.get(cluster.id)
30
- if (existingProvider) {
31
- return existingProvider
32
- }
33
-
34
- const provider = new Provider(`${cluster.name}-${cluster.id}`, {
35
- kubeconfig: cluster.kubeconfig,
36
- })
37
- providers.set(cluster.id, provider)
33
+ export async function getProviderAsync(cluster: Input<k8s.Cluster>): Promise<Provider> {
34
+ const resolvedCluster = await toPromise(cluster)
38
35
 
39
- return provider
36
+ return getProvider(resolvedCluster)
40
37
  }
41
38
 
42
39
  export type NamespaceLike = core.v1.Namespace | Namespace | string
43
40
 
44
- export type CommonArgs = {
41
+ export type ScopedResourceArgs = {
45
42
  /**
46
43
  * The name of the resource.
47
44
  */
@@ -50,12 +47,7 @@ export type CommonArgs = {
50
47
  /**
51
48
  * The namespace to create the resource in.
52
49
  */
53
- namespace: Input<NamespaceLike | undefined>
54
-
55
- /**
56
- * The cluster to create the resource in.
57
- */
58
- cluster: Input<k8s.Cluster>
50
+ namespace: Input<Namespace>
59
51
 
60
52
  /**
61
53
  * The metadata to apply to the resource.
@@ -63,17 +55,20 @@ export type CommonArgs = {
63
55
  metadata?: Input<types.input.meta.v1.ObjectMeta>
64
56
  }
65
57
 
66
- export const commonExtraArgs = ["name", "namespace", "cluster", "metadata"] as const
58
+ export const commonExtraArgs = ["name", "namespace", "metadata"] as const
67
59
 
68
60
  export function mapMetadata(
69
- args: PartialKeys<Unwrap<CommonArgs>, "namespace" | "cluster">,
61
+ args: PartialKeys<ScopedResourceArgs, "namespace">,
70
62
  fallbackName?: string,
71
- ): types.input.meta.v1.ObjectMeta {
72
- return {
73
- ...args.metadata,
74
- name: args.name ?? args.metadata?.name ?? fallbackName,
75
- namespace: args.namespace ? mapNamespaceLikeToNamespaceName(args.namespace) : undefined,
76
- }
63
+ ): Output<Unwrap<types.input.meta.v1.ObjectMeta>> {
64
+ return output(args.metadata).apply(metadata =>
65
+ output({
66
+ ...metadata,
67
+ name: args.name ?? metadata?.name ?? fallbackName,
68
+ namespace:
69
+ metadata?.namespace ?? (args.namespace ? output(args.namespace).metadata.name : undefined),
70
+ }),
71
+ )
77
72
  }
78
73
 
79
74
  export type SelectorLike = types.input.meta.v1.LabelSelector | Record<string, Input<string>>
@@ -90,7 +85,7 @@ export function mapSelectorLikeToSelector(
90
85
  }
91
86
  }
92
87
 
93
- export function mapNamespaceLikeToNamespaceName(namespace: NamespaceLike): Output<string> {
88
+ export function getNamespaceName(namespace: NamespaceLike): Output<string> {
94
89
  if (Namespace.isInstance(namespace)) {
95
90
  return namespace.metadata.name
96
91
  }
@@ -112,35 +107,67 @@ export function mapNamespaceNameToSelector(
112
107
  }
113
108
  }
114
109
 
115
- export type ResourceId = {
116
- name: Input<string>
117
- namespace?: Input<NamespaceLike | undefined>
118
- }
119
-
120
- export function resourceIdToString(id: Input<ResourceId>): Output<string> {
121
- return output(id).apply(metadata => {
122
- const namespaceName = metadata.namespace
123
- ? mapNamespaceLikeToNamespaceName(metadata.namespace)
124
- : undefined
125
-
126
- return output(namespaceName ? interpolate`${namespaceName}/${metadata.name}` : metadata.name)
127
- })
128
- }
129
-
130
- export function withPatchName(
131
- resourceType: string,
132
- resource: Input<k8s.Resource>,
110
+ export function validateCluster(
111
+ entity: Input<k8s.Resource>,
133
112
  cluster: Input<k8s.Cluster>,
134
- ): Output<string> {
135
- return output({ resource, cluster }).apply(({ resource, cluster }) => {
136
- if (resource.clusterId !== cluster.id) {
113
+ ): Input<k8s.Cluster> {
114
+ return output({ entity, cluster }).apply(({ entity, cluster }) => {
115
+ if (entity.clusterId !== cluster.id) {
137
116
  throw new Error(
138
- `Cluster mismatch when patching ${resourceType} "${resource.metadata.name}": "${resource.clusterId}" != "${cluster.id}"`,
117
+ `Cluster mismatch for ${entity.type} "${entity.metadata.name}": "${entity.clusterId}" != "${cluster.id}"`,
139
118
  )
140
119
  }
141
120
 
142
- return resource.metadata.name
121
+ return cluster
143
122
  })
144
123
  }
145
124
 
146
125
  export { images }
126
+
127
+ /**
128
+ * Base class for all Kubernetes scoped resources.
129
+ *
130
+ * Provides common functionality for resources that have a cluster, namespace, metadata, and entity.
131
+ */
132
+ export abstract class ScopedResource extends ComponentResource {
133
+ protected constructor(
134
+ type: string,
135
+ name: string,
136
+ args: Inputs,
137
+ opts: ComponentResourceOptions | undefined,
138
+
139
+ /**
140
+ * The Kubernetes API version (e.g., "v1", "apps/v1", "batch/v1").
141
+ */
142
+ readonly apiVersion: Output<string>,
143
+
144
+ /**
145
+ * The Kubernetes kind (e.g., "ConfigMap", "Deployment", "CronJob").
146
+ */
147
+ readonly kind: Output<string>,
148
+
149
+ /**
150
+ * The namespace where the resource is located.
151
+ */
152
+ readonly namespace: Output<Namespace>,
153
+
154
+ /**
155
+ * The metadata of the underlying Kubernetes resource.
156
+ */
157
+ readonly metadata: Output<types.output.meta.v1.ObjectMeta>,
158
+ ) {
159
+ super(type, name, args, opts)
160
+ }
161
+
162
+ /**
163
+ * The cluster where the resource is located.
164
+ */
165
+ get cluster(): Output<k8s.Cluster> {
166
+ return this.namespace.cluster
167
+ }
168
+
169
+ /**
170
+ * The Highstate resource entity.
171
+ */
172
+ abstract get entity(): Output<k8s.ScopedResource>
173
+ }