pepr 0.31.1 → 0.32.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.
Files changed (54) hide show
  1. package/dist/cli.js +76 -13
  2. package/dist/controller.js +3 -3
  3. package/dist/lib/assets/helm.d.ts.map +1 -1
  4. package/dist/lib/assets/index.d.ts.map +1 -1
  5. package/dist/lib/assets/yaml.d.ts.map +1 -1
  6. package/dist/lib/controller/store.d.ts.map +1 -1
  7. package/dist/lib/mutate-processor.d.ts.map +1 -1
  8. package/dist/lib.js +23 -9
  9. package/dist/lib.js.map +3 -3
  10. package/package.json +6 -6
  11. package/src/lib/assets/helm.ts +18 -0
  12. package/src/lib/assets/index.ts +3 -1
  13. package/src/lib/assets/yaml.ts +35 -0
  14. package/src/lib/controller/index.ts +3 -3
  15. package/src/lib/controller/store.ts +7 -3
  16. package/src/lib/mutate-processor.ts +17 -6
  17. package/src/runtime/controller.ts +2 -2
  18. package/dist/cli.d.ts +0 -3
  19. package/dist/lib/assets/deploy.d.ts +0 -3
  20. package/dist/lib/assets/destroy.d.ts +0 -2
  21. package/dist/lib/assets/helm.d.ts +0 -5
  22. package/dist/lib/assets/index.d.ts +0 -24
  23. package/dist/lib/assets/loader.d.ts +0 -8
  24. package/dist/lib/assets/networking.d.ts +0 -7
  25. package/dist/lib/assets/pods.d.ts +0 -126
  26. package/dist/lib/assets/rbac.d.ts +0 -14
  27. package/dist/lib/assets/store.d.ts +0 -7
  28. package/dist/lib/assets/webhooks.d.ts +0 -6
  29. package/dist/lib/assets/yaml.d.ts +0 -5
  30. package/dist/lib/capability.d.ts +0 -66
  31. package/dist/lib/controller/index.d.ts +0 -10
  32. package/dist/lib/controller/store.d.ts +0 -7
  33. package/dist/lib/errors.d.ts +0 -12
  34. package/dist/lib/filter.d.ts +0 -11
  35. package/dist/lib/helpers.d.ts +0 -34
  36. package/dist/lib/included-files.d.ts +0 -2
  37. package/dist/lib/k8s.d.ts +0 -132
  38. package/dist/lib/logger.d.ts +0 -3
  39. package/dist/lib/metrics.d.ts +0 -39
  40. package/dist/lib/module.d.ts +0 -62
  41. package/dist/lib/mutate-processor.d.ts +0 -5
  42. package/dist/lib/mutate-request.d.ts +0 -79
  43. package/dist/lib/queue.d.ts +0 -19
  44. package/dist/lib/schedule.d.ts +0 -76
  45. package/dist/lib/storage.d.ts +0 -83
  46. package/dist/lib/tls.d.ts +0 -18
  47. package/dist/lib/types.d.ts +0 -192
  48. package/dist/lib/utils.d.ts +0 -23
  49. package/dist/lib/validate-processor.d.ts +0 -4
  50. package/dist/lib/validate-request.d.ts +0 -55
  51. package/dist/lib/watch-processor.d.ts +0 -10
  52. package/dist/lib.d.ts +0 -11
  53. package/dist/runtime/controller.d.ts +0 -3
  54. package/dist/sdk/sdk.d.ts +0 -38
package/dist/lib/k8s.d.ts DELETED
@@ -1,132 +0,0 @@
1
- import { GenericKind, GroupVersionKind, KubernetesObject } from "kubernetes-fluent-client";
2
- export declare enum Operation {
3
- CREATE = "CREATE",
4
- UPDATE = "UPDATE",
5
- DELETE = "DELETE",
6
- CONNECT = "CONNECT"
7
- }
8
- /**
9
- * PeprStore for internal use by Pepr. This is used to store arbitrary data in the cluster.
10
- */
11
- export declare class PeprStore extends GenericKind {
12
- data: {
13
- [key: string]: string;
14
- };
15
- }
16
- export declare const peprStoreGVK: {
17
- kind: string;
18
- version: string;
19
- group: string;
20
- };
21
- /**
22
- * GroupVersionResource unambiguously identifies a resource. It doesn't anonymously include GroupVersion
23
- * to avoid automatic coercion. It doesn't use a GroupVersion to avoid custom marshalling
24
- */
25
- export interface GroupVersionResource {
26
- readonly group: string;
27
- readonly version: string;
28
- readonly resource: string;
29
- }
30
- /**
31
- * A Kubernetes admission request to be processed by a capability.
32
- */
33
- export interface AdmissionRequest<T = KubernetesObject> {
34
- /** UID is an identifier for the individual request/response. */
35
- readonly uid: string;
36
- /** Kind is the fully-qualified type of object being submitted (for example, v1.Pod or autoscaling.v1.Scale) */
37
- readonly kind: GroupVersionKind;
38
- /** Resource is the fully-qualified resource being requested (for example, v1.pods) */
39
- readonly resource: GroupVersionResource;
40
- /** SubResource is the sub-resource being requested, if any (for example, "status" or "scale") */
41
- readonly subResource?: string;
42
- /** RequestKind is the fully-qualified type of the original API request (for example, v1.Pod or autoscaling.v1.Scale). */
43
- readonly requestKind?: GroupVersionKind;
44
- /** RequestResource is the fully-qualified resource of the original API request (for example, v1.pods). */
45
- readonly requestResource?: GroupVersionResource;
46
- /** RequestSubResource is the sub-resource of the original API request, if any (for example, "status" or "scale"). */
47
- readonly requestSubResource?: string;
48
- /**
49
- * Name is the name of the object as presented in the request. On a CREATE operation, the client may omit name and
50
- * rely on the server to generate the name. If that is the case, this method will return the empty string.
51
- */
52
- readonly name: string;
53
- /** Namespace is the namespace associated with the request (if any). */
54
- readonly namespace?: string;
55
- /**
56
- * Operation is the operation being performed. This may be different than the operation
57
- * requested. e.g. a patch can result in either a CREATE or UPDATE Operation.
58
- */
59
- readonly operation: Operation;
60
- /** UserInfo is information about the requesting user */
61
- readonly userInfo: {
62
- /** The name that uniquely identifies this user among all active users. */
63
- username?: string;
64
- /**
65
- * A unique value that identifies this user across time. If this user is deleted
66
- * and another user by the same name is added, they will have different UIDs.
67
- */
68
- uid?: string;
69
- /** The names of groups this user is a part of. */
70
- groups?: string[];
71
- /** Any additional information provided by the authenticator. */
72
- extra?: {
73
- [key: string]: string[];
74
- };
75
- };
76
- /** Object is the object from the incoming request prior to default values being applied */
77
- readonly object: T;
78
- /** OldObject is the existing object. Only populated for UPDATE or DELETE requests. */
79
- readonly oldObject?: T;
80
- /** DryRun indicates that modifications will definitely not be persisted for this request. Defaults to false. */
81
- readonly dryRun?: boolean;
82
- /**
83
- * Options contains the options for the operation being performed.
84
- * e.g. `meta.k8s.io/v1.DeleteOptions` or `meta.k8s.io/v1.CreateOptions`. This may be
85
- * different than the options the caller provided. e.g. for a patch request the performed
86
- * Operation might be a CREATE, in which case the Options will a
87
- * `meta.k8s.io/v1.CreateOptions` even though the caller provided `meta.k8s.io/v1.PatchOptions`.
88
- */
89
- readonly options?: any;
90
- }
91
- export interface MutateResponse {
92
- /** UID is an identifier for the individual request/response. This must be copied over from the corresponding AdmissionRequest. */
93
- uid: string;
94
- /** Allowed indicates whether or not the admission request was permitted. */
95
- allowed: boolean;
96
- /** Result contains extra details into why an admission request was denied. This field IS NOT consulted in any way if "Allowed" is "true". */
97
- result?: string;
98
- /** The patch body. Currently we only support "JSONPatch" which implements RFC 6902. */
99
- patch?: string;
100
- /** The type of Patch. Currently we only allow "JSONPatch". */
101
- patchType?: "JSONPatch";
102
- /**
103
- * AuditAnnotations is an unstructured key value map set by remote admission controller (e.g. error=image-blacklisted).
104
- *
105
- * See https://kubernetes.io/docs/reference/labels-annotations-taints/audit-annotations/ for more information
106
- */
107
- auditAnnotations?: {
108
- [key: string]: string;
109
- };
110
- /** warnings is a list of warning messages to return to the requesting API client. */
111
- warnings?: string[];
112
- }
113
- export interface ValidateResponse extends MutateResponse {
114
- /** Status contains extra details into why an admission request was denied. This field IS NOT consulted in any way if "Allowed" is "true". */
115
- status?: {
116
- /** A machine-readable description of why this operation is in the
117
- "Failure" status. If this value is empty there is no information available. */
118
- code: number;
119
- /** A human-readable description of the status of this operation. */
120
- message: string;
121
- };
122
- }
123
- export type WebhookIgnore = {
124
- /**
125
- * List of Kubernetes namespaces to always ignore.
126
- * Any resources in these namespaces will be ignored by Pepr.
127
- *
128
- * Note: `kube-system` and `pepr-system` are always ignored.
129
- */
130
- namespaces?: string[];
131
- };
132
- //# sourceMappingURL=k8s.d.ts.map
@@ -1,3 +0,0 @@
1
- declare const Log: import("pino").Logger<never>;
2
- export default Log;
3
- //# sourceMappingURL=logger.d.ts.map
@@ -1,39 +0,0 @@
1
- /**
2
- * MetricsCollector class handles metrics collection using prom-client and performance hooks.
3
- */
4
- export declare class MetricsCollector {
5
- #private;
6
- /**
7
- * Creates a MetricsCollector instance with prefixed metrics.
8
- * @param [prefix='pepr'] - The prefix for the metric names.
9
- */
10
- constructor(prefix?: string);
11
- addCounter: (name: string, help: string) => void;
12
- addSummary: (name: string, help: string) => void;
13
- incCounter: (name: string) => void;
14
- /**
15
- * Increments the error counter.
16
- */
17
- error: () => void;
18
- /**
19
- * Increments the alerts counter.
20
- */
21
- alert: () => void;
22
- /**
23
- * Observes the duration since the provided start time and updates the summary.
24
- * @param startTime - The start time.
25
- * @param name - The metrics summary to increment.
26
- */
27
- observeEnd: (startTime: number, name?: string) => void;
28
- /**
29
- * Fetches the current metrics from the registry.
30
- * @returns The metrics.
31
- */
32
- getMetrics: () => Promise<string>;
33
- /**
34
- * Returns the current timestamp from performance.now() method. Useful for start timing an operation.
35
- * @returns The timestamp.
36
- */
37
- static observeStart(): number;
38
- }
39
- //# sourceMappingURL=metrics.d.ts.map
@@ -1,62 +0,0 @@
1
- import { Capability } from "./capability";
2
- import { AdmissionRequest, MutateResponse, ValidateResponse, WebhookIgnore } from "./k8s";
3
- /** Custom Labels Type for package.json */
4
- export interface CustomLabels {
5
- namespace?: Record<string, string>;
6
- }
7
- /** Global configuration for the Pepr runtime. */
8
- export type ModuleConfig = {
9
- /** The Pepr version this module uses */
10
- peprVersion?: string;
11
- /** The user-defined version of the module */
12
- appVersion?: string;
13
- /** A unique identifier for this Pepr module. This is automatically generated by Pepr. */
14
- uuid: string;
15
- /** A description of the Pepr module and what it does. */
16
- description?: string;
17
- /** The webhookTimeout */
18
- webhookTimeout?: number;
19
- /** Reject K8s resource AdmissionRequests on error. */
20
- onError?: string;
21
- /** Configure global exclusions that will never be processed by Pepr. */
22
- alwaysIgnore: WebhookIgnore;
23
- /** Define the log level for the in-cluster controllers */
24
- logLevel?: string;
25
- /** Propagate env variables to in-cluster controllers */
26
- env?: Record<string, string>;
27
- /** Custom Labels for Kubernetes Objects */
28
- customLabels?: CustomLabels;
29
- };
30
- export type PackageJSON = {
31
- description: string;
32
- pepr: ModuleConfig;
33
- };
34
- export type PeprModuleOptions = {
35
- deferStart?: boolean;
36
- /** A user-defined callback to pre-process or intercept a Pepr request from K8s immediately before it is processed */
37
- beforeHook?: (req: AdmissionRequest) => void;
38
- /** A user-defined callback to post-process or intercept a Pepr response just before it is returned to K8s */
39
- afterHook?: (res: MutateResponse | ValidateResponse) => void;
40
- };
41
- export declare const isWatchMode: () => boolean;
42
- export declare const isBuildMode: () => boolean;
43
- export declare const isDevMode: () => boolean;
44
- export declare class PeprModule {
45
- #private;
46
- /**
47
- * Create a new Pepr runtime
48
- *
49
- * @param config The configuration for the Pepr runtime
50
- * @param capabilities The capabilities to be loaded into the Pepr runtime
51
- * @param opts Options for the Pepr runtime
52
- */
53
- constructor({ description, pepr }: PackageJSON, capabilities?: Capability[], opts?: PeprModuleOptions);
54
- /**
55
- * Start the Pepr runtime manually.
56
- * Normally this is called automatically when the Pepr module is instantiated, but can be called manually if `deferStart` is set to `true` in the constructor.
57
- *
58
- * @param port
59
- */
60
- start: (port?: number) => void;
61
- }
62
- //# sourceMappingURL=module.d.ts.map
@@ -1,5 +0,0 @@
1
- import { Capability } from "./capability";
2
- import { MutateResponse, AdmissionRequest } from "./k8s";
3
- import { ModuleConfig } from "./module";
4
- export declare function mutateProcessor(config: ModuleConfig, capabilities: Capability[], req: AdmissionRequest, reqMetadata: Record<string, string>): Promise<MutateResponse>;
5
- //# sourceMappingURL=mutate-processor.d.ts.map
@@ -1,79 +0,0 @@
1
- import { KubernetesObject } from "kubernetes-fluent-client";
2
- import { AdmissionRequest } from "./k8s";
3
- import { DeepPartial } from "./types";
4
- /**
5
- * The RequestWrapper class provides methods to modify Kubernetes objects in the context
6
- * of a mutating webhook request.
7
- */
8
- export declare class PeprMutateRequest<T extends KubernetesObject> {
9
- #private;
10
- Raw: T;
11
- get PermitSideEffects(): boolean;
12
- /**
13
- * Indicates whether the request is a dry run.
14
- * @returns true if the request is a dry run, false otherwise.
15
- */
16
- get IsDryRun(): boolean | undefined;
17
- /**
18
- * Provides access to the old resource in the request if available.
19
- * @returns The old Kubernetes resource object or null if not available.
20
- */
21
- get OldResource(): T | undefined;
22
- /**
23
- * Provides access to the request object.
24
- * @returns The request object containing the Kubernetes resource.
25
- */
26
- get Request(): AdmissionRequest<T>;
27
- /**
28
- * Creates a new instance of the action class.
29
- * @param input - The request object containing the Kubernetes resource to modify.
30
- */
31
- constructor(input: AdmissionRequest<T>);
32
- /**
33
- * Deep merges the provided object with the current resource.
34
- *
35
- * @param obj - The object to merge with the current resource.
36
- */
37
- Merge: (obj: DeepPartial<T>) => void;
38
- /**
39
- * Updates a label on the Kubernetes resource.
40
- * @param key - The key of the label to update.
41
- * @param value - The value of the label.
42
- * @returns The current action instance for method chaining.
43
- */
44
- SetLabel: (key: string, value: string) => this;
45
- /**
46
- * Updates an annotation on the Kubernetes resource.
47
- * @param key - The key of the annotation to update.
48
- * @param value - The value of the annotation.
49
- * @returns The current action instance for method chaining.
50
- */
51
- SetAnnotation: (key: string, value: string) => this;
52
- /**
53
- * Removes a label from the Kubernetes resource.
54
- * @param key - The key of the label to remove.
55
- * @returns The current Action instance for method chaining.
56
- */
57
- RemoveLabel: (key: string) => this;
58
- /**
59
- * Removes an annotation from the Kubernetes resource.
60
- * @param key - The key of the annotation to remove.
61
- * @returns The current Action instance for method chaining.
62
- */
63
- RemoveAnnotation: (key: string) => this;
64
- /**
65
- * Check if a label exists on the Kubernetes resource.
66
- *
67
- * @param key the label key to check
68
- * @returns
69
- */
70
- HasLabel: (key: string) => boolean;
71
- /**
72
- * Check if an annotation exists on the Kubernetes resource.
73
- *
74
- * @param key the annotation key to check
75
- * @returns
76
- */
77
- HasAnnotation: (key: string) => boolean;
78
- }
79
- //# sourceMappingURL=mutate-request.d.ts.map
@@ -1,19 +0,0 @@
1
- import { KubernetesObject } from "@kubernetes/client-node";
2
- import { WatchPhase } from "kubernetes-fluent-client/dist/fluent/types";
3
- /**
4
- * Queue is a FIFO queue for reconciling
5
- */
6
- export declare class Queue<K extends KubernetesObject> {
7
- #private;
8
- constructor();
9
- setReconcile(reconcile: (obj: KubernetesObject, type: WatchPhase) => Promise<void>): void;
10
- /**
11
- * Enqueue adds an item to the queue and returns a promise that resolves when the item is
12
- * reconciled.
13
- *
14
- * @param item The object to reconcile
15
- * @returns A promise that resolves when the object is reconciled
16
- */
17
- enqueue(item: K, type: WatchPhase): Promise<void>;
18
- }
19
- //# sourceMappingURL=queue.d.ts.map
@@ -1,76 +0,0 @@
1
- /// <reference types="node" />
2
- import { PeprStore } from "./storage";
3
- type Unit = "seconds" | "second" | "minute" | "minutes" | "hours" | "hour";
4
- export interface Schedule {
5
- /**
6
- * * The name of the store
7
- */
8
- name: string;
9
- /**
10
- * The value associated with a unit of time
11
- */
12
- every: number;
13
- /**
14
- * The unit of time
15
- */
16
- unit: Unit;
17
- /**
18
- * The code to run
19
- */
20
- run: () => void;
21
- /**
22
- * The start time of the schedule
23
- */
24
- startTime?: Date | undefined;
25
- /**
26
- * The number of times the schedule has run
27
- */
28
- completions?: number | undefined;
29
- /**
30
- * Tje intervalID to clear the interval
31
- */
32
- intervalID?: NodeJS.Timeout;
33
- }
34
- export declare class OnSchedule implements Schedule {
35
- intervalId: NodeJS.Timeout | null;
36
- store: PeprStore | undefined;
37
- name: string;
38
- completions?: number | undefined;
39
- every: number;
40
- unit: Unit;
41
- run: () => void;
42
- startTime?: Date | undefined;
43
- duration: number | undefined;
44
- lastTimestamp: Date | undefined;
45
- constructor(schedule: Schedule);
46
- setStore(store: PeprStore): void;
47
- startInterval(): void;
48
- /**
49
- * Checks the store for this schedule and sets the values if it exists
50
- * @returns
51
- */
52
- checkStore(): void;
53
- /**
54
- * Saves the schedule to the store
55
- * @returns
56
- */
57
- saveToStore(): void;
58
- /**
59
- * Gets the durations in milliseconds
60
- */
61
- getDuration(): void;
62
- /**
63
- * Sets up the interval
64
- */
65
- setupInterval(): void;
66
- /**
67
- * Starts the interval
68
- */
69
- start(): void;
70
- /**
71
- * Stops the interval
72
- */
73
- stop(): void;
74
- }
75
- export {};
76
- //# sourceMappingURL=schedule.d.ts.map
@@ -1,83 +0,0 @@
1
- export type DataOp = "add" | "remove";
2
- export type DataStore = Record<string, string>;
3
- export type DataSender = (op: DataOp, keys: string[], value?: string) => void;
4
- export type DataReceiver = (data: DataStore) => void;
5
- export type Unsubscribe = () => void;
6
- export interface PeprStore {
7
- /**
8
- * Returns the current value associated with the given key, or null if the given key does not exist.
9
- */
10
- getItem(key: string): string | null;
11
- /**
12
- * Removes all key/value pairs, if there are any.
13
- */
14
- clear(): void;
15
- /**
16
- * Removes the key/value pair with the given key, if a key/value pair with the given key exists.
17
- */
18
- removeItem(key: string): void;
19
- /**
20
- * Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously.
21
- */
22
- setItem(key: string, value: string): void;
23
- /**
24
- * Subscribe to changes in the store. This API behaves similarly to the [Svelte Store API](https://vercel.com/docs/beginner-sveltekit/svelte-stores#using-the-store).
25
- *
26
- * @param listener - The callback to be invoked when the store changes.
27
- * @returns A function to unsubscribe from the listener.
28
- */
29
- subscribe(listener: DataReceiver): Unsubscribe;
30
- /**
31
- * Register a function to be called when the store is ready.
32
- */
33
- onReady(callback: DataReceiver): void;
34
- /**
35
- * Sets the value of the pair identified by key to value, creating a new key/value pair if none existed for key previously.
36
- * Resolves when the key/value show up in the store.
37
- */
38
- setItemAndWait(key: string, value: string): Promise<void>;
39
- /**
40
- * Remove the value of the key.
41
- * Resolves when the key does not show up in the store.
42
- */
43
- removeItemAndWait(key: string): Promise<void>;
44
- }
45
- /**
46
- * A key-value data store that can be used to persist data that should be shared across Pepr controllers and capabilities.
47
- *
48
- * The API is similar to the [Storage API](https://developer.mozilla.org/docs/Web/API/Storage)
49
- */
50
- export declare class Storage implements PeprStore {
51
- #private;
52
- registerSender: (send: DataSender) => void;
53
- receive: (data: DataStore) => void;
54
- getItem: (key: string) => string | null;
55
- clear: () => void;
56
- removeItem: (key: string) => void;
57
- setItem: (key: string, value: string) => void;
58
- /**
59
- * Creates a promise and subscribes to the store, the promise resolves when
60
- * the key and value are seen in the store.
61
- *
62
- * @param key - The key to add into the store
63
- * @param value - The value of the key
64
- * @returns
65
- */
66
- setItemAndWait: (key: string, value: string) => Promise<void>;
67
- /**
68
- * Creates a promise and subscribes to the store, the promise resolves when
69
- * the key is removed from the store.
70
- *
71
- * @param key - The key to add into the store
72
- * @returns
73
- */
74
- removeItemAndWait: (key: string) => Promise<void>;
75
- subscribe: (subscriber: DataReceiver) => () => void;
76
- onReady: (callback: DataReceiver) => void;
77
- /**
78
- * Remove a subscriber from the list of subscribers.
79
- * @param idx - The index of the subscriber to remove.
80
- */
81
- unsubscribe: (idx: number) => void;
82
- }
83
- //# sourceMappingURL=storage.d.ts.map
package/dist/lib/tls.d.ts DELETED
@@ -1,18 +0,0 @@
1
- export interface TLSOut {
2
- ca: string;
3
- crt: string;
4
- key: string;
5
- pem: {
6
- ca: string;
7
- crt: string;
8
- key: string;
9
- };
10
- }
11
- /**
12
- * Generates a self-signed CA and server certificate with Subject Alternative Names (SANs) for the K8s webhook.
13
- *
14
- * @param {string} name - The name to use for the server certificate's Common Name and SAN DNS entry.
15
- * @returns {TLSOut} - An object containing the Base64-encoded CA, server certificate, and server private key.
16
- */
17
- export declare function genTLS(name: string): TLSOut;
18
- //# sourceMappingURL=tls.d.ts.map