@intentius/chant-k8s-client 0.31.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/client.d.ts +122 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/concurrency.d.ts +20 -0
- package/dist/concurrency.d.ts.map +1 -0
- package/dist/credentials.d.ts +85 -0
- package/dist/credentials.d.ts.map +1 -0
- package/dist/errors.d.ts +96 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/testing.d.ts +84 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/types.d.ts +146 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +51 -0
- package/src/client.test.ts +407 -0
- package/src/client.ts +570 -0
- package/src/concurrency.ts +40 -0
- package/src/credentials.test.ts +139 -0
- package/src/credentials.ts +117 -0
- package/src/errors.ts +168 -0
- package/src/index.ts +59 -0
- package/src/testing.ts +188 -0
- package/src/types.ts +156 -0
package/src/types.ts
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public data shapes for the chant Kubernetes API client (chant #1074).
|
|
3
|
+
*
|
|
4
|
+
* Everything here is plain data: no class, nothing imported from
|
|
5
|
+
* `@kubernetes/client-node`, nothing imported from chant core. The lexicon
|
|
6
|
+
* that consumes this package must be able to name these types without pulling
|
|
7
|
+
* either dependency onto the build path.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
/** A live Kubernetes object, as the API server returned it. */
|
|
11
|
+
export interface K8sObject {
|
|
12
|
+
apiVersion?: string;
|
|
13
|
+
kind?: string;
|
|
14
|
+
metadata?: {
|
|
15
|
+
name?: string;
|
|
16
|
+
namespace?: string;
|
|
17
|
+
uid?: string;
|
|
18
|
+
resourceVersion?: string;
|
|
19
|
+
generation?: number;
|
|
20
|
+
creationTimestamp?: string;
|
|
21
|
+
labels?: Record<string, string>;
|
|
22
|
+
annotations?: Record<string, string>;
|
|
23
|
+
ownerReferences?: Array<Record<string, unknown>>;
|
|
24
|
+
managedFields?: Array<Record<string, unknown>>;
|
|
25
|
+
[k: string]: unknown;
|
|
26
|
+
};
|
|
27
|
+
status?: Record<string, unknown>;
|
|
28
|
+
[k: string]: unknown;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Addresses one object. `namespace` is ignored for cluster-scoped kinds. */
|
|
32
|
+
export interface ObjectRef {
|
|
33
|
+
apiVersion: string;
|
|
34
|
+
kind: string;
|
|
35
|
+
name: string;
|
|
36
|
+
namespace?: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* How to find a resource in the cluster's discovery.
|
|
41
|
+
*
|
|
42
|
+
* - By GVK — what `describeResources` uses, because the generated operation
|
|
43
|
+
* surface gives it an exact `apiVersion` + `kind`.
|
|
44
|
+
* - By kubectl-style resource string — what `waitForReady` uses, because its
|
|
45
|
+
* activity contract has always taken `kind` in the form `kubectl get`
|
|
46
|
+
* accepts (`certificates`, `raycluster.ray.io`, `Deployment`).
|
|
47
|
+
*/
|
|
48
|
+
export type ResourceSelector =
|
|
49
|
+
| { apiVersion: string; kind: string }
|
|
50
|
+
| { resource: string; group?: string };
|
|
51
|
+
|
|
52
|
+
/** One entry of an `APIResourceList`, as the cluster reports it. */
|
|
53
|
+
export interface ApiResourceInfo {
|
|
54
|
+
/** Plural path segment, e.g. `deployments`. */
|
|
55
|
+
name: string;
|
|
56
|
+
singularName?: string;
|
|
57
|
+
kind: string;
|
|
58
|
+
namespaced: boolean;
|
|
59
|
+
verbs: readonly string[];
|
|
60
|
+
shortNames?: readonly string[];
|
|
61
|
+
/** `""` for the core group. */
|
|
62
|
+
group: string;
|
|
63
|
+
version: string;
|
|
64
|
+
/** `v1` or `apps/v1` — what goes in a manifest. */
|
|
65
|
+
apiVersion: string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Which credential path the client is authenticating with. */
|
|
69
|
+
export type CredentialPath =
|
|
70
|
+
| "exec-plugin"
|
|
71
|
+
| "auth-provider"
|
|
72
|
+
| "token"
|
|
73
|
+
| "client-certificate"
|
|
74
|
+
| "basic-auth"
|
|
75
|
+
| "in-cluster"
|
|
76
|
+
| "none";
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Where an observation's credentials came from, recorded so the provenance of
|
|
80
|
+
* a read is legible (chant #1074's managed-cluster note). A read authorized by
|
|
81
|
+
* `aws eks get-token` and a read authorized by a static service-account token
|
|
82
|
+
* are not equally trustworthy inputs to a drift report.
|
|
83
|
+
*/
|
|
84
|
+
export interface ClientProvenance {
|
|
85
|
+
/** API server URL. */
|
|
86
|
+
server: string;
|
|
87
|
+
/** kubectl context the client resolved to. */
|
|
88
|
+
context?: string;
|
|
89
|
+
/** Where the context came from — a declared binding or the ambient default. */
|
|
90
|
+
contextSource: "bound" | "ambient";
|
|
91
|
+
credential: CredentialPath;
|
|
92
|
+
/** The exec plugin's command, when `credential` is `exec-plugin`. */
|
|
93
|
+
execCommand?: string;
|
|
94
|
+
/** Where the kubeconfig itself came from. */
|
|
95
|
+
kubeconfigSource: "explicit-string" | "explicit-path" | "default" | "in-cluster";
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Options for {@link import("./client").createK8sClient}. */
|
|
99
|
+
export interface K8sClientOptions {
|
|
100
|
+
/**
|
|
101
|
+
* Literal kubeconfig YAML. Wins over every other source — which is how
|
|
102
|
+
* tests avoid reading the developer's real `~/.kube/config`.
|
|
103
|
+
*/
|
|
104
|
+
kubeconfig?: string;
|
|
105
|
+
/** Path to a kubeconfig file. Wins over the ambient default. */
|
|
106
|
+
kubeconfigPath?: string;
|
|
107
|
+
/**
|
|
108
|
+
* Context to use, from `k8s.profiles.<env>.context` (chant #1100/#1155).
|
|
109
|
+
* Omitted means the kubeconfig's own current-context.
|
|
110
|
+
*/
|
|
111
|
+
context?: string;
|
|
112
|
+
/**
|
|
113
|
+
* Exec credential-plugin commands this client may execute. Defaults to
|
|
114
|
+
* {@link import("./credentials").DEFAULT_EXEC_ALLOWLIST}.
|
|
115
|
+
*/
|
|
116
|
+
execAllowlist?: readonly string[];
|
|
117
|
+
/**
|
|
118
|
+
* Replaces `@kubernetes/client-node`'s HTTP send. This is the package's only
|
|
119
|
+
* seam onto the network: URL construction, kubeconfig parsing, auth header
|
|
120
|
+
* application and response handling all still run for real above it. Tests
|
|
121
|
+
* pass one; production does not.
|
|
122
|
+
*/
|
|
123
|
+
requestLayer?: RequestLayer;
|
|
124
|
+
/** Max concurrent in-flight requests. Default 8. */
|
|
125
|
+
concurrency?: number;
|
|
126
|
+
/** Where the context came from, for provenance. Default `ambient`. */
|
|
127
|
+
contextSource?: "bound" | "ambient";
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* `@kubernetes/client-node`'s promise-shaped HTTP library: it receives the
|
|
132
|
+
* library's own `RequestContext` (fully built URL, method, headers including
|
|
133
|
+
* whatever the auth path put there) and returns its own `ResponseContext`.
|
|
134
|
+
*
|
|
135
|
+
* Typed structurally rather than against the library's classes so this module
|
|
136
|
+
* stays free of `@kubernetes/client-node` imports; `client.ts` checks the real
|
|
137
|
+
* shapes where it matters.
|
|
138
|
+
*/
|
|
139
|
+
export interface RequestLayer {
|
|
140
|
+
send(request: RequestContextLike): Promise<ResponseContextLike> | ResponseContextLike;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
/** The subset of client-node's `RequestContext` this package and its tests read. */
|
|
144
|
+
export interface RequestContextLike {
|
|
145
|
+
getUrl(): string;
|
|
146
|
+
getHttpMethod(): string;
|
|
147
|
+
getHeaders(): Record<string, string>;
|
|
148
|
+
getBody(): unknown;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** The subset of client-node's `ResponseContext` this package produces and consumes. */
|
|
152
|
+
export interface ResponseContextLike {
|
|
153
|
+
httpStatusCode: number;
|
|
154
|
+
headers: Record<string, string>;
|
|
155
|
+
body: { text(): Promise<string> };
|
|
156
|
+
}
|