@highstate/library 0.15.0 → 0.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/highstate.library.msgpack +0 -0
- package/dist/index.js +1721 -953
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/abbreviations.ts +1 -0
- package/src/common/access-point.ts +2 -2
- package/src/common/files.ts +10 -0
- package/src/common/server.ts +15 -57
- package/src/databases/etcd.ts +97 -0
- package/src/databases/index.ts +1 -0
- package/src/databases/mariadb.ts +48 -2
- package/src/databases/mongodb.ts +48 -2
- package/src/databases/postgresql.ts +51 -2
- package/src/databases/redis.ts +48 -2
- package/src/databases/s3.ts +65 -6
- package/src/databases/shared.ts +12 -6
- package/src/dns.ts +59 -49
- package/src/k8s/apps/etcd.ts +46 -0
- package/src/k8s/apps/index.ts +2 -0
- package/src/k8s/apps/mariadb.ts +0 -5
- package/src/k8s/apps/minio.ts +0 -5
- package/src/k8s/apps/mongodb.ts +0 -5
- package/src/k8s/apps/postgresql.ts +0 -5
- package/src/k8s/apps/shared.ts +10 -1
- package/src/k8s/apps/traefik.ts +16 -1
- package/src/k8s/apps/valkey.ts +0 -5
- package/src/k8s/apps/wg-feed-server.ts +34 -0
- package/src/k8s/reduced-access.ts +23 -53
- package/src/k8s/resources.ts +78 -35
- package/src/k8s/service.ts +21 -10
- package/src/k8s/shared.ts +60 -90
- package/src/k8s/workload.ts +87 -26
- package/src/network/address-space.ts +94 -0
- package/src/network/address.ts +33 -0
- package/src/network/dynamic-endpoint.ts +39 -0
- package/src/network/endpoint-schema.ts +116 -0
- package/src/network/endpoint.ts +347 -0
- package/src/network/index.ts +6 -0
- package/src/network/subnet.ts +31 -0
- package/src/ssh.ts +66 -10
- package/src/third-party/cloudflare.ts +1 -0
- package/src/utils.ts +41 -11
- package/src/wireguard.ts +340 -150
- package/src/network.ts +0 -391
package/src/k8s/resources.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Simplify, SimplifyDeep } from "type-fest"
|
|
1
2
|
import { defineEntity, z } from "@highstate/contract"
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -8,6 +9,7 @@ export const metadataSchema = z.object({
|
|
|
8
9
|
labels: z.record(z.string(), z.string()).optional(),
|
|
9
10
|
annotations: z.record(z.string(), z.string()).optional(),
|
|
10
11
|
uid: z.string(),
|
|
12
|
+
namespace: z.string().optional(),
|
|
11
13
|
})
|
|
12
14
|
|
|
13
15
|
/**
|
|
@@ -15,31 +17,48 @@ export const metadataSchema = z.object({
|
|
|
15
17
|
*
|
|
16
18
|
* It includes the namespace field.
|
|
17
19
|
*/
|
|
18
|
-
export const
|
|
20
|
+
export const namespacedMetadataSchema = z.object({
|
|
19
21
|
...metadataSchema.shape,
|
|
20
22
|
namespace: z.string(),
|
|
21
23
|
})
|
|
22
24
|
|
|
23
25
|
/**
|
|
24
|
-
* The
|
|
25
|
-
*
|
|
26
|
-
* It includes the cluster ID and name, which are required for all Kubernetes resources.
|
|
26
|
+
* The entity which represents a Kubernetes resource.
|
|
27
27
|
*/
|
|
28
|
-
export const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
28
|
+
export const resourceEntity = defineEntity({
|
|
29
|
+
type: "k8s.resource.v1",
|
|
30
|
+
|
|
31
|
+
schema: z.intersection(
|
|
32
|
+
z.object({
|
|
33
|
+
clusterId: z.string(),
|
|
34
|
+
clusterName: z.string(),
|
|
35
|
+
apiVersion: z.string(),
|
|
36
|
+
kind: z.string(),
|
|
37
|
+
}),
|
|
38
|
+
z.union([
|
|
39
|
+
z.object({
|
|
40
|
+
isNamespaced: z.literal(false),
|
|
41
|
+
metadata: metadataSchema,
|
|
42
|
+
}),
|
|
43
|
+
z.object({
|
|
44
|
+
isNamespaced: z.literal(true),
|
|
45
|
+
metadata: namespacedMetadataSchema,
|
|
46
|
+
}),
|
|
47
|
+
]),
|
|
48
|
+
),
|
|
33
49
|
})
|
|
34
50
|
|
|
35
51
|
/**
|
|
36
|
-
* The
|
|
37
|
-
*
|
|
38
|
-
* Extends the base resource schema with the scoped metadata.
|
|
52
|
+
* The entity which represents a Kubernetes resource scoped to a namespace.
|
|
39
53
|
*/
|
|
40
|
-
export const
|
|
41
|
-
|
|
42
|
-
|
|
54
|
+
export const namespacedResourceEntity = defineEntity({
|
|
55
|
+
type: "k8s.namespaced-resource.v1",
|
|
56
|
+
|
|
57
|
+
extends: { resourceEntity },
|
|
58
|
+
|
|
59
|
+
schema: z.object({
|
|
60
|
+
isNamespaced: z.literal(true),
|
|
61
|
+
}),
|
|
43
62
|
})
|
|
44
63
|
|
|
45
64
|
/**
|
|
@@ -48,10 +67,8 @@ export const scopedResourceSchema = z.object({
|
|
|
48
67
|
export const namespaceEntity = defineEntity({
|
|
49
68
|
type: "k8s.namespace.v1",
|
|
50
69
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
type: z.literal("namespace"),
|
|
54
|
-
}),
|
|
70
|
+
extends: { resourceEntity },
|
|
71
|
+
schema: z.unknown(),
|
|
55
72
|
|
|
56
73
|
meta: {
|
|
57
74
|
color: "#9E9E9E",
|
|
@@ -64,10 +81,8 @@ export const namespaceEntity = defineEntity({
|
|
|
64
81
|
export const persistentVolumeClaimEntity = defineEntity({
|
|
65
82
|
type: "k8s.persistent-volume-claim.v1",
|
|
66
83
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
type: z.literal("persistent-volume-claim"),
|
|
70
|
-
}),
|
|
84
|
+
extends: { namespacedResourceEntity },
|
|
85
|
+
schema: z.unknown(),
|
|
71
86
|
|
|
72
87
|
meta: {
|
|
73
88
|
color: "#FFC107",
|
|
@@ -80,10 +95,8 @@ export const persistentVolumeClaimEntity = defineEntity({
|
|
|
80
95
|
export const gatewayEntity = defineEntity({
|
|
81
96
|
type: "k8s.gateway.v1",
|
|
82
97
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
type: z.literal("gateway"),
|
|
86
|
-
}),
|
|
98
|
+
extends: { namespacedResourceEntity },
|
|
99
|
+
schema: z.unknown(),
|
|
87
100
|
|
|
88
101
|
meta: {
|
|
89
102
|
color: "#4CAF50",
|
|
@@ -93,19 +106,49 @@ export const gatewayEntity = defineEntity({
|
|
|
93
106
|
export const certificateEntity = defineEntity({
|
|
94
107
|
type: "k8s.certificate.v1",
|
|
95
108
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
109
|
+
extends: { namespacedResourceEntity },
|
|
110
|
+
schema: z.unknown(),
|
|
111
|
+
|
|
112
|
+
meta: {
|
|
113
|
+
color: "#3F51B5",
|
|
114
|
+
},
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
export const configMapEntity = defineEntity({
|
|
118
|
+
type: "k8s.config-map.v1",
|
|
119
|
+
|
|
120
|
+
extends: { namespacedResourceEntity },
|
|
121
|
+
schema: z.unknown(),
|
|
122
|
+
|
|
123
|
+
meta: {
|
|
124
|
+
color: "#FF9800",
|
|
125
|
+
},
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
export const secretEntity = defineEntity({
|
|
129
|
+
type: "k8s.secret.v1",
|
|
130
|
+
|
|
131
|
+
extends: { namespacedResourceEntity },
|
|
132
|
+
schema: z.unknown(),
|
|
133
|
+
|
|
134
|
+
meta: {
|
|
135
|
+
color: "#9C27B0",
|
|
136
|
+
},
|
|
100
137
|
})
|
|
101
138
|
|
|
102
139
|
export type Metadata = z.infer<typeof metadataSchema>
|
|
103
|
-
export type Resource = z.infer<typeof
|
|
140
|
+
export type Resource = z.infer<typeof resourceEntity.schema>
|
|
141
|
+
|
|
142
|
+
export type NamespacedMetadata = z.infer<typeof namespacedMetadataSchema>
|
|
104
143
|
|
|
105
|
-
export type
|
|
106
|
-
|
|
144
|
+
export type NamespacedResource = SimplifyDeep<
|
|
145
|
+
z.infer<typeof namespacedResourceEntity.schema>,
|
|
146
|
+
Record<string, string>
|
|
147
|
+
>
|
|
107
148
|
|
|
108
|
-
export type Namespace = z.infer<typeof namespaceEntity.schema
|
|
149
|
+
export type Namespace = Simplify<z.infer<typeof namespaceEntity.schema>>
|
|
109
150
|
export type PersistentVolumeClaim = z.infer<typeof persistentVolumeClaimEntity.schema>
|
|
110
151
|
export type Gateway = z.infer<typeof gatewayEntity.schema>
|
|
111
152
|
export type Certificate = z.infer<typeof certificateEntity.schema>
|
|
153
|
+
export type ConfigMap = z.infer<typeof configMapEntity.schema>
|
|
154
|
+
export type Secret = z.infer<typeof secretEntity.schema>
|
package/src/k8s/service.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import type { Simplify } from "type-fest"
|
|
1
2
|
import { defineEntity, z } from "@highstate/contract"
|
|
2
3
|
import { l4EndpointEntity } from "../network"
|
|
3
|
-
import {
|
|
4
|
+
import { namespacedResourceEntity } from "./resources"
|
|
4
5
|
|
|
5
|
-
export const
|
|
6
|
+
export const serviceEndpointMetadataSchema = z.object({
|
|
6
7
|
"k8s.service": z.object({
|
|
7
8
|
/**
|
|
8
9
|
* The ID of the cluster where the service is located.
|
|
@@ -24,6 +25,11 @@ export const endpointServiceMetadataSchema = z.object({
|
|
|
24
25
|
*/
|
|
25
26
|
namespace: z.string(),
|
|
26
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Whether this endpoint is only accessible within the cluster.
|
|
30
|
+
*/
|
|
31
|
+
isInternal: z.boolean(),
|
|
32
|
+
|
|
27
33
|
/**
|
|
28
34
|
* The selector of the service.
|
|
29
35
|
*/
|
|
@@ -39,18 +45,23 @@ export const endpointServiceMetadataSchema = z.object({
|
|
|
39
45
|
export const serviceEndpointSchema = z.intersection(
|
|
40
46
|
l4EndpointEntity.schema,
|
|
41
47
|
z.object({
|
|
42
|
-
metadata:
|
|
48
|
+
metadata: serviceEndpointMetadataSchema,
|
|
43
49
|
}),
|
|
44
50
|
)
|
|
45
51
|
|
|
46
52
|
export const serviceEntity = defineEntity({
|
|
47
53
|
type: "k8s.service.v1",
|
|
48
54
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
endpoints:
|
|
53
|
-
|
|
55
|
+
extends: { namespacedResourceEntity },
|
|
56
|
+
|
|
57
|
+
includes: {
|
|
58
|
+
endpoints: {
|
|
59
|
+
entity: l4EndpointEntity,
|
|
60
|
+
multiple: true,
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
schema: z.unknown(),
|
|
54
65
|
|
|
55
66
|
meta: {
|
|
56
67
|
color: "#2196F3",
|
|
@@ -59,7 +70,7 @@ export const serviceEntity = defineEntity({
|
|
|
59
70
|
|
|
60
71
|
export const serviceTypeSchema = z.enum(["NodePort", "LoadBalancer", "ClusterIP"])
|
|
61
72
|
|
|
62
|
-
export type EndpointServiceMetadata = z.infer<typeof
|
|
63
|
-
export type ServiceEndpoint = z.infer<typeof serviceEndpointSchema
|
|
73
|
+
export type EndpointServiceMetadata = z.infer<typeof serviceEndpointMetadataSchema>
|
|
74
|
+
export type ServiceEndpoint = Simplify<z.infer<typeof serviceEndpointSchema>>
|
|
64
75
|
export type ServiceType = z.infer<typeof serviceTypeSchema>
|
|
65
76
|
export type Service = z.infer<typeof serviceEntity.schema>
|
package/src/k8s/shared.ts
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
1
|
import { $args, defineEntity, defineUnit, z } from "@highstate/contract"
|
|
2
2
|
import { serverEntity } from "../common"
|
|
3
|
-
import * as dns from "../dns"
|
|
4
3
|
import { implementationReferenceSchema } from "../impl-ref"
|
|
5
|
-
import { l3EndpointEntity, l4EndpointEntity } from "../network"
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
4
|
+
import { addressEntity, l3EndpointEntity, l4EndpointEntity } from "../network"
|
|
5
|
+
import { metadataSchema } from "../utils"
|
|
6
|
+
import { namespacedResourceEntity } from "./resources"
|
|
8
7
|
|
|
9
8
|
export const fallbackKubeApiAccessSchema = z.object({
|
|
10
9
|
serverIp: z.string(),
|
|
11
10
|
serverPort: z.number(),
|
|
12
11
|
})
|
|
13
12
|
|
|
14
|
-
export const tunDevicePolicySchema = z.
|
|
13
|
+
export const tunDevicePolicySchema = z.discriminatedUnion("type", [
|
|
15
14
|
z.object({
|
|
16
15
|
type: z.literal("host"),
|
|
17
16
|
}),
|
|
@@ -40,14 +39,14 @@ export const clusterQuirksSchema = z.object({
|
|
|
40
39
|
*
|
|
41
40
|
* For some runtimes, like Talos's one, the /dev/net/tun device is not available in the host, so the plugin policy should be used.
|
|
42
41
|
*/
|
|
43
|
-
tunDevicePolicy: tunDevicePolicySchema.
|
|
42
|
+
tunDevicePolicy: tunDevicePolicySchema.prefault({ type: "host" }),
|
|
44
43
|
|
|
45
44
|
/**
|
|
46
45
|
* The service type to use for external services.
|
|
47
46
|
*
|
|
48
47
|
* If not provided, the default service type is `NodePort` since `LoadBalancer` may not be available.
|
|
49
48
|
*/
|
|
50
|
-
externalServiceType: externalServiceTypeSchema.
|
|
49
|
+
externalServiceType: externalServiceTypeSchema.default("NodePort"),
|
|
51
50
|
})
|
|
52
51
|
|
|
53
52
|
export const clusterInfoProperties = {
|
|
@@ -79,15 +78,6 @@ export const clusterInfoProperties = {
|
|
|
79
78
|
*/
|
|
80
79
|
networkPolicyImplRef: implementationReferenceSchema.optional(),
|
|
81
80
|
|
|
82
|
-
/**
|
|
83
|
-
* The endpoints of the cluster nodes.
|
|
84
|
-
*
|
|
85
|
-
* The entry may represent real node endpoint or virtual endpoint (like a load balancer).
|
|
86
|
-
*
|
|
87
|
-
* The same node may also be represented by multiple entries (e.g. a node with private and public IP).
|
|
88
|
-
*/
|
|
89
|
-
endpoints: l3EndpointEntity.schema.array(),
|
|
90
|
-
|
|
91
81
|
/**
|
|
92
82
|
* The endpoints of the API server.
|
|
93
83
|
*
|
|
@@ -100,7 +90,7 @@ export const clusterInfoProperties = {
|
|
|
100
90
|
/**
|
|
101
91
|
* The external IPs of the cluster nodes allowed to be used for external access.
|
|
102
92
|
*/
|
|
103
|
-
externalIps:
|
|
93
|
+
externalIps: addressEntity.schema.array(),
|
|
104
94
|
|
|
105
95
|
/**
|
|
106
96
|
* The extra quirks of the cluster to improve compatibility.
|
|
@@ -110,12 +100,26 @@ export const clusterInfoProperties = {
|
|
|
110
100
|
/**
|
|
111
101
|
* The extra metadata to attach to the cluster.
|
|
112
102
|
*/
|
|
113
|
-
metadata:
|
|
103
|
+
metadata: metadataSchema.optional(),
|
|
114
104
|
} as const
|
|
115
105
|
|
|
116
106
|
export const clusterEntity = defineEntity({
|
|
117
107
|
type: "k8s.cluster.v1",
|
|
118
108
|
|
|
109
|
+
includes: {
|
|
110
|
+
/**
|
|
111
|
+
* The endpoints of the cluster nodes.
|
|
112
|
+
*
|
|
113
|
+
* The entry may represent real node endpoint or virtual endpoint (like a load balancer).
|
|
114
|
+
*
|
|
115
|
+
* The same node may also be represented by multiple entries (e.g. a node with private and public IP).
|
|
116
|
+
*/
|
|
117
|
+
endpoints: {
|
|
118
|
+
entity: l3EndpointEntity,
|
|
119
|
+
multiple: true,
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
|
|
119
123
|
schema: z.object({
|
|
120
124
|
...clusterInfoProperties,
|
|
121
125
|
kubeconfig: z.string(),
|
|
@@ -153,14 +157,6 @@ export const clusterInputs = {
|
|
|
153
157
|
|
|
154
158
|
export const clusterOutputs = {
|
|
155
159
|
k8sCluster: clusterEntity,
|
|
156
|
-
apiEndpoints: {
|
|
157
|
-
entity: l4EndpointEntity,
|
|
158
|
-
multiple: true,
|
|
159
|
-
},
|
|
160
|
-
endpoints: {
|
|
161
|
-
entity: l3EndpointEntity,
|
|
162
|
-
multiple: true,
|
|
163
|
-
},
|
|
164
160
|
} as const
|
|
165
161
|
|
|
166
162
|
/**
|
|
@@ -171,11 +167,9 @@ export const existingCluster = defineUnit({
|
|
|
171
167
|
|
|
172
168
|
args: {
|
|
173
169
|
/**
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
* If not provided, will be automatically detected by querying the cluster nodes.
|
|
170
|
+
* Whether to auto-detect external IPs of the cluster nodes and merge them with the provided external IPs.
|
|
177
171
|
*/
|
|
178
|
-
|
|
172
|
+
autoDetectExternalIps: z.boolean().default(true),
|
|
179
173
|
|
|
180
174
|
/**
|
|
181
175
|
* The policy for using internal IPs of the nodes as external IPs.
|
|
@@ -183,13 +177,44 @@ export const existingCluster = defineUnit({
|
|
|
183
177
|
* - `always`: always use internal IPs as external IPs;
|
|
184
178
|
* - `public`: use internal IPs as external IPs only if they are (theoretically) routable from the public internet **(default)**;
|
|
185
179
|
* - `never`: never use internal IPs as external IPs.
|
|
180
|
+
*
|
|
181
|
+
* Have no effect if `autoDetectExternalIps` is `false`.
|
|
186
182
|
*/
|
|
187
183
|
internalIpsPolicy: internalIpsPolicySchema.default("public"),
|
|
188
184
|
|
|
185
|
+
/**
|
|
186
|
+
* The list of external IPs of the cluster nodes allowed to be used for external access.
|
|
187
|
+
*/
|
|
188
|
+
externalIps: z.string().array().default([]),
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Whether to use all external IPs (auto-detected and provided) as endpoints of the cluster.
|
|
192
|
+
*
|
|
193
|
+
* Set to `false` if you want to manage endpoints manually.
|
|
194
|
+
*/
|
|
195
|
+
useExternalIpsAsEndpoints: z.boolean().default(true),
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* The list of endpoints of the cluster nodes.
|
|
199
|
+
*/
|
|
200
|
+
endpoints: z.string().array().default([]),
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Whether to add endpoints from `kubeconfig` to the list of API endpoints.
|
|
204
|
+
*
|
|
205
|
+
* Set to `false` if you want to manage API endpoints manually.
|
|
206
|
+
*/
|
|
207
|
+
useKubeconfigApiEndpoint: z.boolean().default(true),
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* The list of endpoints of the API server.
|
|
211
|
+
*/
|
|
212
|
+
apiEndpoints: z.string().array().default([]),
|
|
213
|
+
|
|
189
214
|
/**
|
|
190
215
|
* The extra quirks of the cluster to improve compatibility.
|
|
191
216
|
*/
|
|
192
|
-
quirks: clusterQuirksSchema.optional(),
|
|
217
|
+
quirks: clusterQuirksSchema.optional().meta({ complex: true }),
|
|
193
218
|
},
|
|
194
219
|
|
|
195
220
|
secrets: {
|
|
@@ -223,38 +248,14 @@ export const clusterPatch = defineUnit({
|
|
|
223
248
|
|
|
224
249
|
args: {
|
|
225
250
|
/**
|
|
226
|
-
* The endpoints
|
|
227
|
-
*
|
|
228
|
-
* The entry may represent real node endpoint or virtual endpoint (like a load balancer).
|
|
229
|
-
*
|
|
230
|
-
* The same node may also be represented by multiple entries (e.g. a node with private and public IP).
|
|
231
|
-
*/
|
|
232
|
-
apiEndpoints: z.string().array().default([]),
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* The mode to use for patching the API endpoints.
|
|
236
|
-
*
|
|
237
|
-
* - `prepend`: prepend the new endpoints to the existing ones (default);
|
|
238
|
-
* - `replace`: replace the existing endpoints with the new ones.
|
|
239
|
-
*/
|
|
240
|
-
apiEndpointsPatchMode: arrayPatchModeSchema.default("prepend"),
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* The endpoints of the cluster nodes.
|
|
244
|
-
*
|
|
245
|
-
* The entry may represent real node endpoint or virtual endpoint (like a load balancer).
|
|
246
|
-
*
|
|
247
|
-
* The same node may also be represented by multiple entries (e.g. a node with private and public IP).
|
|
251
|
+
* The endpoints to set on the cluster.
|
|
248
252
|
*/
|
|
249
253
|
endpoints: z.string().array().default([]),
|
|
250
254
|
|
|
251
255
|
/**
|
|
252
|
-
* The
|
|
253
|
-
*
|
|
254
|
-
* - `prepend`: prepend the new endpoints to the existing ones (default);
|
|
255
|
-
* - `replace`: replace the existing endpoints with the new ones.
|
|
256
|
+
* The API endpoints to set on the cluster.
|
|
256
257
|
*/
|
|
257
|
-
|
|
258
|
+
apiEndpoints: z.string().array().default([]),
|
|
258
259
|
},
|
|
259
260
|
|
|
260
261
|
inputs: {
|
|
@@ -286,37 +287,6 @@ export const clusterPatch = defineUnit({
|
|
|
286
287
|
},
|
|
287
288
|
})
|
|
288
289
|
|
|
289
|
-
/**
|
|
290
|
-
* Creates a set of DNS records for the cluster and updates the endpoints.
|
|
291
|
-
*/
|
|
292
|
-
export const clusterDns = defineUnit({
|
|
293
|
-
type: "k8s.cluster-dns.v1",
|
|
294
|
-
|
|
295
|
-
args: {
|
|
296
|
-
...dns.createArgs(),
|
|
297
|
-
...dns.createArgs("api"),
|
|
298
|
-
},
|
|
299
|
-
|
|
300
|
-
inputs: {
|
|
301
|
-
k8sCluster: clusterEntity,
|
|
302
|
-
...dns.inputs,
|
|
303
|
-
},
|
|
304
|
-
|
|
305
|
-
outputs: clusterOutputs,
|
|
306
|
-
|
|
307
|
-
meta: {
|
|
308
|
-
title: "Cluster DNS",
|
|
309
|
-
icon: "devicon:kubernetes",
|
|
310
|
-
secondaryIcon: "mdi:dns",
|
|
311
|
-
category: "Kubernetes",
|
|
312
|
-
},
|
|
313
|
-
|
|
314
|
-
source: {
|
|
315
|
-
package: "@highstate/k8s",
|
|
316
|
-
path: "units/cluster-dns",
|
|
317
|
-
},
|
|
318
|
-
})
|
|
319
|
-
|
|
320
290
|
export const monitorWorkerResourceGroupSchema = z.object({
|
|
321
291
|
type: z.enum(["deployment", "statefulset", "pod", "service"]),
|
|
322
292
|
namespace: z.string(),
|
|
@@ -332,7 +302,7 @@ export const monitorWorkerParamsSchema = z.object({
|
|
|
332
302
|
/**
|
|
333
303
|
* The resources to monitor in the cluster.
|
|
334
304
|
*/
|
|
335
|
-
resources:
|
|
305
|
+
resources: namespacedResourceEntity.schema.array(),
|
|
336
306
|
})
|
|
337
307
|
|
|
338
308
|
export type Cluster = z.infer<typeof clusterEntity.schema>
|
package/src/k8s/workload.ts
CHANGED
|
@@ -1,7 +1,81 @@
|
|
|
1
1
|
import { defineEntity, z } from "@highstate/contract"
|
|
2
|
-
import {
|
|
2
|
+
import { l4EndpointEntity } from "../network"
|
|
3
|
+
import { namespacedResourceEntity } from "./resources"
|
|
3
4
|
import { serviceEntity } from "./service"
|
|
4
5
|
|
|
6
|
+
/**
|
|
7
|
+
* The entity which represents a Kubernetes workload.
|
|
8
|
+
*/
|
|
9
|
+
export const workloadEntity = defineEntity({
|
|
10
|
+
type: "k8s.workload.v1",
|
|
11
|
+
|
|
12
|
+
extends: { namespacedResourceEntity },
|
|
13
|
+
schema: z.unknown(),
|
|
14
|
+
|
|
15
|
+
meta: {
|
|
16
|
+
color: "#9C27B0",
|
|
17
|
+
},
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The entity which represents a Kubernetes job managed by Highstate.
|
|
22
|
+
*/
|
|
23
|
+
export const jobEntity = defineEntity({
|
|
24
|
+
type: "k8s.job.v1",
|
|
25
|
+
|
|
26
|
+
extends: { workloadEntity },
|
|
27
|
+
|
|
28
|
+
schema: z.unknown(),
|
|
29
|
+
|
|
30
|
+
meta: {
|
|
31
|
+
color: "#FF5722",
|
|
32
|
+
},
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The entity which represents a Kubernetes cron job managed by Highstate.
|
|
37
|
+
*/
|
|
38
|
+
export const cronJobEntity = defineEntity({
|
|
39
|
+
type: "k8s.cron-job.v1",
|
|
40
|
+
|
|
41
|
+
extends: { workloadEntity },
|
|
42
|
+
|
|
43
|
+
schema: z.unknown(),
|
|
44
|
+
|
|
45
|
+
meta: {
|
|
46
|
+
color: "#FF9800",
|
|
47
|
+
},
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The entity which represents a Kubernetes workload (optionally) exposed via a service.
|
|
52
|
+
*
|
|
53
|
+
* Includes both the workload and its associated service.
|
|
54
|
+
*/
|
|
55
|
+
export const exposableWorkloadEntity = defineEntity({
|
|
56
|
+
type: "k8s.exposable-workload.v1",
|
|
57
|
+
|
|
58
|
+
extends: { workloadEntity },
|
|
59
|
+
|
|
60
|
+
includes: {
|
|
61
|
+
service: {
|
|
62
|
+
entity: serviceEntity,
|
|
63
|
+
required: false,
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
endpoints: {
|
|
67
|
+
entity: l4EndpointEntity,
|
|
68
|
+
multiple: true,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
schema: z.unknown(),
|
|
73
|
+
|
|
74
|
+
meta: {
|
|
75
|
+
color: "#4CAF50",
|
|
76
|
+
},
|
|
77
|
+
})
|
|
78
|
+
|
|
5
79
|
/**
|
|
6
80
|
* The entity which represents a Kubernetes deployment managed by Highstate.
|
|
7
81
|
*
|
|
@@ -10,11 +84,8 @@ import { serviceEntity } from "./service"
|
|
|
10
84
|
export const deploymentEntity = defineEntity({
|
|
11
85
|
type: "k8s.deployment.v1",
|
|
12
86
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
type: z.literal("deployment"),
|
|
16
|
-
service: serviceEntity.schema.optional(),
|
|
17
|
-
}),
|
|
87
|
+
extends: { exposableWorkloadEntity },
|
|
88
|
+
schema: z.unknown(),
|
|
18
89
|
|
|
19
90
|
meta: {
|
|
20
91
|
color: "#4CAF50",
|
|
@@ -29,29 +100,16 @@ export const deploymentEntity = defineEntity({
|
|
|
29
100
|
export const statefulSetEntity = defineEntity({
|
|
30
101
|
type: "k8s.stateful-set.v1",
|
|
31
102
|
|
|
32
|
-
|
|
33
|
-
...scopedResourceSchema.shape,
|
|
34
|
-
type: z.literal("stateful-set"),
|
|
35
|
-
service: serviceEntity.schema,
|
|
36
|
-
}),
|
|
103
|
+
extends: { exposableWorkloadEntity },
|
|
37
104
|
|
|
38
|
-
|
|
39
|
-
|
|
105
|
+
includes: {
|
|
106
|
+
service: serviceEntity,
|
|
40
107
|
},
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* The entity which represents a Kubernetes workload exposed via a service.
|
|
45
|
-
*
|
|
46
|
-
* It can be either a deployment or a stateful set.
|
|
47
|
-
*/
|
|
48
|
-
export const exposableWorkloadEntity = defineEntity({
|
|
49
|
-
type: "k8s.exposable-workload.v1",
|
|
50
108
|
|
|
51
|
-
schema: z.
|
|
109
|
+
schema: z.unknown(),
|
|
52
110
|
|
|
53
111
|
meta: {
|
|
54
|
-
color: "#
|
|
112
|
+
color: "#FFC107",
|
|
55
113
|
},
|
|
56
114
|
})
|
|
57
115
|
|
|
@@ -63,7 +121,7 @@ export const networkInterfaceEntity = defineEntity({
|
|
|
63
121
|
|
|
64
122
|
schema: z.object({
|
|
65
123
|
name: z.string(),
|
|
66
|
-
workload:
|
|
124
|
+
workload: workloadEntity.schema,
|
|
67
125
|
}),
|
|
68
126
|
|
|
69
127
|
meta: {
|
|
@@ -71,7 +129,10 @@ export const networkInterfaceEntity = defineEntity({
|
|
|
71
129
|
},
|
|
72
130
|
})
|
|
73
131
|
|
|
132
|
+
export type Workload = z.infer<typeof workloadEntity.schema>
|
|
133
|
+
export type Job = z.infer<typeof jobEntity.schema>
|
|
134
|
+
export type CronJob = z.infer<typeof cronJobEntity.schema>
|
|
135
|
+
export type ExposableWorkload = z.infer<typeof exposableWorkloadEntity.schema>
|
|
74
136
|
export type Deployment = z.infer<typeof deploymentEntity.schema>
|
|
75
137
|
export type StatefulSet = z.infer<typeof statefulSetEntity.schema>
|
|
76
|
-
export type ExposableWorkload = z.infer<typeof exposableWorkloadEntity.schema>
|
|
77
138
|
export type NetworkInterface = z.infer<typeof networkInterfaceEntity.schema>
|