@highstate/k8s 0.9.8 → 0.9.10

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 (34) hide show
  1. package/dist/{chunk-YEH2UAPS.js → chunk-3B5DTLGG.js} +2 -2
  2. package/dist/{chunk-JBGQQVTZ.js → chunk-7R2VAXVL.js} +24 -4
  3. package/dist/chunk-7R2VAXVL.js.map +1 -0
  4. package/dist/{chunk-YTCZBMAL.js → chunk-FF3GFWG3.js} +2 -2
  5. package/dist/chunk-OP75IMU7.js +766 -0
  6. package/dist/chunk-OP75IMU7.js.map +1 -0
  7. package/dist/{chunk-UNVUOHHB.js → chunk-R43VRICF.js} +163 -448
  8. package/dist/chunk-R43VRICF.js.map +1 -0
  9. package/dist/deployment-E3ZTF2IS.js +10 -0
  10. package/dist/highstate.manifest.json +8 -8
  11. package/dist/index.js +27 -11
  12. package/dist/index.js.map +1 -1
  13. package/dist/stateful-set-NTU7QKC7.js +10 -0
  14. package/dist/units/cert-manager/index.js +2 -2
  15. package/package.json +9 -9
  16. package/src/config-map.ts +180 -0
  17. package/src/container.ts +12 -1
  18. package/src/cron-job.ts +8 -1
  19. package/src/helm.ts +35 -2
  20. package/src/index.ts +1 -0
  21. package/src/job.ts +8 -1
  22. package/src/scripting/bundle.ts +7 -5
  23. package/src/secret.ts +4 -0
  24. package/src/service.ts +1 -0
  25. package/dist/chunk-J6O3TE56.js +0 -347
  26. package/dist/chunk-J6O3TE56.js.map +0 -1
  27. package/dist/chunk-JBGQQVTZ.js.map +0 -1
  28. package/dist/chunk-UNVUOHHB.js.map +0 -1
  29. package/dist/deployment-TFCMSEGW.js +0 -10
  30. package/dist/stateful-set-2OEPSK44.js +0 -10
  31. /package/dist/{chunk-YEH2UAPS.js.map → chunk-3B5DTLGG.js.map} +0 -0
  32. /package/dist/{chunk-YTCZBMAL.js.map → chunk-FF3GFWG3.js.map} +0 -0
  33. /package/dist/{deployment-TFCMSEGW.js.map → deployment-E3ZTF2IS.js.map} +0 -0
  34. /package/dist/{stateful-set-2OEPSK44.js.map → stateful-set-NTU7QKC7.js.map} +0 -0
@@ -0,0 +1,180 @@
1
+ import type { k8s } from "@highstate/library"
2
+ import { core, type types } from "@pulumi/kubernetes"
3
+ import {
4
+ ComponentResource,
5
+ output,
6
+ Output,
7
+ type ComponentResourceOptions,
8
+ type Input,
9
+ type Inputs,
10
+ } from "@pulumi/pulumi"
11
+ import { getProvider, mapMetadata, withPatchName, type CommonArgs } from "./shared"
12
+
13
+ export type ConfigMapArgs = CommonArgs &
14
+ Omit<types.input.core.v1.ConfigMap, "kind" | "metadata" | "apiVersion">
15
+
16
+ export type CreateOrPatchConfigMapArgs = ConfigMapArgs & {
17
+ /**
18
+ * The resource to use to determine the name of the config map.
19
+ *
20
+ * If not provided, the config map will be created, otherwise it will be retrieved/patched.
21
+ */
22
+ existing: Input<k8s.Resource> | undefined
23
+ }
24
+
25
+ export abstract class ConfigMap extends ComponentResource {
26
+ protected constructor(
27
+ type: string,
28
+ name: string,
29
+ args: Inputs,
30
+ opts: ComponentResourceOptions | undefined,
31
+
32
+ /**
33
+ * The cluster where the config map is created.
34
+ */
35
+ readonly cluster: Output<k8s.Cluster>,
36
+
37
+ /**
38
+ * The metadata of the underlying Kubernetes config map.
39
+ */
40
+ readonly metadata: Output<types.output.meta.v1.ObjectMeta>,
41
+
42
+ /**
43
+ * The data of the underlying Kubernetes config map.
44
+ */
45
+ readonly data: Output<Record<string, string>>,
46
+ ) {
47
+ super(type, name, args, opts)
48
+ }
49
+
50
+ /**
51
+ * Creates a new config map.
52
+ */
53
+ static create(name: string, args: ConfigMapArgs, opts?: ComponentResourceOptions): ConfigMap {
54
+ return new CreatedConfigMap(name, args, opts)
55
+ }
56
+
57
+ /**
58
+ * Creates a new config map or patches an existing one.
59
+ *
60
+ * Will throw an error if the config map does not exist when `args.resource` is provided.
61
+ */
62
+ static createOrPatch(
63
+ name: string,
64
+ args: CreateOrPatchConfigMapArgs,
65
+ opts?: ComponentResourceOptions,
66
+ ): ConfigMap {
67
+ if (!args.existing) {
68
+ return new CreatedConfigMap(name, args, opts)
69
+ }
70
+
71
+ return new ConfigMapPatch(
72
+ name,
73
+ {
74
+ ...args,
75
+ name: withPatchName("configmap", args.existing, args.cluster),
76
+ namespace: output(args.existing).metadata.namespace,
77
+ },
78
+ opts,
79
+ )
80
+ }
81
+
82
+ /**
83
+ * Gets an existing config map.
84
+ *
85
+ * Will throw an error if the config map does not exist.
86
+ */
87
+ static get(
88
+ name: string,
89
+ id: Input<string>,
90
+ cluster: Input<k8s.Cluster>,
91
+ opts?: ComponentResourceOptions,
92
+ ): ConfigMap {
93
+ return new ExternalConfigMap(name, id, cluster, opts)
94
+ }
95
+ }
96
+
97
+ class CreatedConfigMap extends ConfigMap {
98
+ constructor(name: string, args: ConfigMapArgs, opts?: ComponentResourceOptions) {
99
+ const configMap = output(args).apply(async args => {
100
+ return new core.v1.ConfigMap(
101
+ name,
102
+ {
103
+ metadata: mapMetadata(args, name),
104
+ data: args.data,
105
+ },
106
+ {
107
+ ...opts,
108
+ parent: this,
109
+ provider: await getProvider(args.cluster),
110
+ },
111
+ )
112
+ })
113
+
114
+ super(
115
+ "highstate:k8s:ConfigMap",
116
+ name,
117
+ args,
118
+ opts,
119
+ output(args.cluster),
120
+ configMap.metadata,
121
+ configMap.data,
122
+ )
123
+ }
124
+ }
125
+
126
+ class ConfigMapPatch extends ConfigMap {
127
+ constructor(name: string, args: ConfigMapArgs, opts?: ComponentResourceOptions) {
128
+ const configMap = output(args).apply(async args => {
129
+ return new core.v1.ConfigMapPatch(
130
+ name,
131
+ {
132
+ metadata: mapMetadata(args, name),
133
+ data: args.data,
134
+ },
135
+ {
136
+ ...opts,
137
+ parent: this,
138
+ provider: await getProvider(args.cluster),
139
+ },
140
+ )
141
+ })
142
+
143
+ super(
144
+ "highstate:k8s:ConfigMapPatch",
145
+ name,
146
+ args,
147
+ opts,
148
+ output(args.cluster),
149
+ configMap.metadata,
150
+ configMap.data,
151
+ )
152
+ }
153
+ }
154
+
155
+ class ExternalConfigMap extends ConfigMap {
156
+ constructor(
157
+ name: string,
158
+ id: Input<string>,
159
+ cluster: Input<k8s.Cluster>,
160
+ opts?: ComponentResourceOptions,
161
+ ) {
162
+ const configMap = output(id).apply(async realName => {
163
+ return core.v1.ConfigMap.get(name, realName, {
164
+ ...opts,
165
+ parent: this,
166
+ provider: await getProvider(cluster),
167
+ })
168
+ })
169
+
170
+ super(
171
+ "highstate:k8s:ExternalConfigMap",
172
+ name,
173
+ { id, cluster },
174
+ opts,
175
+ output(cluster),
176
+ configMap.metadata,
177
+ configMap.data,
178
+ )
179
+ }
180
+ }
package/src/container.ts CHANGED
@@ -5,6 +5,7 @@ import { normalize, output, type Input, type InputArray, type Unwrap } from "@hi
5
5
  import { concat, map, omit } from "remeda"
6
6
  import { PersistentVolumeClaim } from "./pvc"
7
7
  import { Secret } from "./secret"
8
+ import { ConfigMap } from "./config-map"
8
9
 
9
10
  export type Container = Omit<PartialKeys<types.input.core.v1.Container, "name">, "volumeMounts"> & {
10
11
  /**
@@ -126,9 +127,10 @@ export type WorkloadVolume =
126
127
  | types.input.core.v1.Volume
127
128
  | core.v1.PersistentVolumeClaim
128
129
  | PersistentVolumeClaim
129
- | Secret
130
130
  | core.v1.ConfigMap
131
+ | ConfigMap
131
132
  | core.v1.Secret
133
+ | Secret
132
134
 
133
135
  export function mapContainerToRaw(
134
136
  container: Unwrap<Container>,
@@ -289,6 +291,15 @@ export function mapWorkloadVolume(volume: WorkloadVolume) {
289
291
  }
290
292
  }
291
293
 
294
+ if (volume instanceof ConfigMap) {
295
+ return {
296
+ name: volume.metadata.name,
297
+ configMap: {
298
+ name: volume.metadata.name,
299
+ },
300
+ }
301
+ }
302
+
292
303
  if (core.v1.PersistentVolumeClaim.isInstance(volume)) {
293
304
  return {
294
305
  name: volume.metadata.name,
package/src/cron-job.ts CHANGED
@@ -41,7 +41,14 @@ export class CronJob extends ComponentResource {
41
41
  {
42
42
  jobTemplate: {
43
43
  spec: {
44
- template: podTemplate,
44
+ template: mergeDeep(
45
+ {
46
+ spec: {
47
+ restartPolicy: "Never",
48
+ },
49
+ },
50
+ podTemplate,
51
+ ),
45
52
  },
46
53
  },
47
54
 
package/src/helm.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { k8s } from "@highstate/library"
2
2
  import { resolve } from "node:path"
3
3
  import { mkdir, readFile, unlink } from "node:fs/promises"
4
- import { toPromise, type InputMap } from "@highstate/pulumi"
4
+ import { normalize, toPromise, type InputMap } from "@highstate/pulumi"
5
5
  import { core, helm, types } from "@pulumi/kubernetes"
6
6
  import {
7
7
  ComponentResource,
@@ -15,6 +15,7 @@ import { sha256 } from "crypto-hash"
15
15
  import { omit } from "remeda"
16
16
  import { local } from "@pulumi/command"
17
17
  import { glob } from "glob"
18
+ import { NetworkPolicy, type NetworkPolicyArgs } from "./network-policy"
18
19
  import { HttpRoute, type HttpRouteArgs } from "./gateway"
19
20
  import { getProvider, mapNamespaceLikeToNamespaceName, type NamespaceLike } from "./shared"
20
21
  import { getServiceType, Service, type ServiceArgs } from "./service"
@@ -56,6 +57,16 @@ export type ChartArgs = Omit<
56
57
  * The http route args to bind the service to.
57
58
  */
58
59
  httpRoute?: Input<HttpRouteArgs>
60
+
61
+ /**
62
+ * The network policy to apply to the chart.
63
+ */
64
+ networkPolicy?: Input<Omit<NetworkPolicyArgs, "selector" | "cluster" | "namespace">>
65
+
66
+ /**
67
+ * The network policies to apply to the chart.
68
+ */
69
+ networkPolicies?: Input<NetworkPolicyArgs[]>
59
70
  }
60
71
 
61
72
  export class Chart extends ComponentResource {
@@ -69,6 +80,11 @@ export class Chart extends ComponentResource {
69
80
  */
70
81
  public readonly httpRoute: Output<HttpRoute | undefined>
71
82
 
83
+ /**
84
+ * The network policies applied to the chart.
85
+ */
86
+ public readonly networkPolicies: Output<NetworkPolicy[]>
87
+
72
88
  constructor(
73
89
  private readonly name: string,
74
90
  private readonly args: ChartArgs,
@@ -150,7 +166,24 @@ export class Chart extends ComponentResource {
150
166
  )
151
167
  })
152
168
 
153
- this.registerOutputs({ chart: this.chart })
169
+ this.networkPolicies = output(args).apply(args => {
170
+ const policies = normalize(args.networkPolicy, args.networkPolicies)
171
+
172
+ return output(
173
+ policies.map(policy => {
174
+ return NetworkPolicy.create(
175
+ name,
176
+ {
177
+ ...policy,
178
+
179
+ cluster: args.cluster,
180
+ namespace: args.namespace,
181
+ },
182
+ { ...opts, parent: this },
183
+ )
184
+ }),
185
+ )
186
+ })
154
187
  }
155
188
 
156
189
  get service(): Output<Service> {
package/src/index.ts CHANGED
@@ -23,6 +23,7 @@ export {
23
23
  isFromCluster,
24
24
  } from "./service"
25
25
  export { type SecretArgs, type CreateOrPatchSecretArgs, Secret } from "./secret"
26
+ export { type ConfigMapArgs, type CreateOrPatchConfigMapArgs, ConfigMap } from "./config-map"
26
27
  export { type StatefulSetArgs, StatefulSet } from "./stateful-set"
27
28
  export {
28
29
  type NetworkPolicyArgs,
package/src/job.ts CHANGED
@@ -32,7 +32,14 @@ export class Job extends ComponentResource {
32
32
  metadata: mapMetadata(args, name),
33
33
  spec: mergeDeep(
34
34
  {
35
- template: podTemplate,
35
+ template: mergeDeep(
36
+ {
37
+ spec: {
38
+ restartPolicy: "Never",
39
+ },
40
+ },
41
+ podTemplate,
42
+ ),
36
43
  } satisfies types.input.batch.v1.JobSpec,
37
44
  omit(args, jobExtraArgs) as types.input.batch.v1.JobSpec,
38
45
  ),
@@ -1,6 +1,5 @@
1
1
  import type { ContainerEnvironment, ContainerVolumeMount, WorkloadVolume } from "../container"
2
2
  import type { network } from "@highstate/library"
3
- import { core } from "@pulumi/kubernetes"
4
3
  import { apply, normalize, type InputArray } from "@highstate/pulumi"
5
4
  import {
6
5
  ComponentResource,
@@ -16,7 +15,8 @@ import { readPackageJSON } from "pkg-types"
16
15
  import { text, trimIndentation } from "@highstate/contract"
17
16
  import { parseL34Endpoint } from "@highstate/common"
18
17
  import { serializeFunction } from "@pulumi/pulumi/runtime/index.js"
19
- import { mapMetadata, type CommonArgs } from "../shared"
18
+ import { type CommonArgs } from "../shared"
19
+ import { ConfigMap } from "../config-map"
20
20
  import {
21
21
  emptyScriptEnvironment,
22
22
  functionScriptImages,
@@ -46,7 +46,7 @@ export class ScriptBundle extends ComponentResource {
46
46
  /**
47
47
  * The config map containing the scripts.
48
48
  */
49
- readonly configMap: Output<core.v1.ConfigMap>
49
+ readonly configMap: Output<ConfigMap>
50
50
 
51
51
  /**
52
52
  * The volumes that should be included in the workload.
@@ -118,10 +118,12 @@ export class ScriptBundle extends ComponentResource {
118
118
  )
119
119
 
120
120
  this.configMap = output({ scriptEnvironment, args }).apply(({ scriptEnvironment, args }) => {
121
- return new core.v1.ConfigMap(
121
+ return ConfigMap.create(
122
122
  name,
123
123
  {
124
- metadata: mapMetadata(args, name),
124
+ cluster: args.cluster,
125
+ namespace: args.namespace,
126
+
125
127
  data: createScriptData(this.distribution, scriptEnvironment),
126
128
  },
127
129
  { ...opts, parent: this },
package/src/secret.ts CHANGED
@@ -108,6 +108,8 @@ class CreatedSecret extends Secret {
108
108
  metadata: mapMetadata(args, name),
109
109
  data: args.data,
110
110
  stringData: args.stringData,
111
+ type: args.type,
112
+ immutable: args.immutable,
111
113
  },
112
114
  {
113
115
  ...opts,
@@ -139,6 +141,8 @@ class SecretPatch extends Secret {
139
141
  metadata: mapMetadata(args, name),
140
142
  data: args.data,
141
143
  stringData: args.stringData,
144
+ type: args.type,
145
+ immutable: args.immutable,
142
146
  },
143
147
  {
144
148
  ...opts,
package/src/service.ts CHANGED
@@ -227,6 +227,7 @@ export abstract class Service extends ComponentResource {
227
227
 
228
228
  const clusterIpEndpoints = spec.clusterIPs?.map(ip => ({
229
229
  ...parseL3Endpoint(ip),
230
+ visibility: "internal" as network.EndpointVisibility,
230
231
  port: spec.ports[0].port,
231
232
  protocol: spec.ports[0].protocol?.toLowerCase() as network.L4Protocol,
232
233
  metadata: endpointMetadata,