pepr 0.3.0-rc0 → 0.3.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.
@@ -1,208 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const ava_1 = __importDefault(require("ava"));
7
- const loader_1 = require("../../fixtures/loader");
8
- const filter_1 = require("./filter");
9
- const k8s_1 = require("./k8s");
10
- const callback = () => undefined;
11
- (0, ava_1.default)("should reject when name does not match", t => {
12
- const binding = {
13
- kind: k8s_1.gvkMap.V1Pod,
14
- filters: {
15
- name: "bleh",
16
- namespaces: [],
17
- labels: {},
18
- annotations: {},
19
- },
20
- callback,
21
- };
22
- const pod = (0, loader_1.POD1)();
23
- t.true((0, filter_1.shouldSkipRequest)(binding, pod));
24
- });
25
- (0, ava_1.default)("should reject when kind does not match", t => {
26
- const binding = {
27
- kind: k8s_1.gvkMap.V1ConfigMap,
28
- filters: {
29
- name: "",
30
- namespaces: [],
31
- labels: {},
32
- annotations: {},
33
- },
34
- callback,
35
- };
36
- const pod = (0, loader_1.POD1)();
37
- t.true((0, filter_1.shouldSkipRequest)(binding, pod));
38
- });
39
- (0, ava_1.default)("should reject when group does not match", t => {
40
- const binding = {
41
- kind: k8s_1.gvkMap.V1CronJob,
42
- filters: {
43
- name: "",
44
- namespaces: [],
45
- labels: {},
46
- annotations: {},
47
- },
48
- callback,
49
- };
50
- const pod = (0, loader_1.POD1)();
51
- t.true((0, filter_1.shouldSkipRequest)(binding, pod));
52
- });
53
- (0, ava_1.default)("should reject when version does not match", t => {
54
- const binding = {
55
- kind: {
56
- group: "",
57
- version: "v2",
58
- kind: "Pod",
59
- },
60
- filters: {
61
- name: "",
62
- namespaces: [],
63
- labels: {},
64
- annotations: {},
65
- },
66
- callback,
67
- };
68
- const pod = (0, loader_1.POD1)();
69
- t.true((0, filter_1.shouldSkipRequest)(binding, pod));
70
- });
71
- (0, ava_1.default)("should allow when group, version, and kind match", t => {
72
- const binding = {
73
- kind: k8s_1.gvkMap.V1Pod,
74
- filters: {
75
- name: "",
76
- namespaces: [],
77
- labels: {},
78
- annotations: {},
79
- },
80
- callback,
81
- };
82
- const pod = (0, loader_1.POD1)();
83
- t.false((0, filter_1.shouldSkipRequest)(binding, pod));
84
- });
85
- (0, ava_1.default)("should allow when kind match and others are empty", t => {
86
- const binding = {
87
- kind: {
88
- group: "",
89
- version: "",
90
- kind: "Pod",
91
- },
92
- filters: {
93
- name: "",
94
- namespaces: [],
95
- labels: {},
96
- annotations: {},
97
- },
98
- callback,
99
- };
100
- const pod = (0, loader_1.POD1)();
101
- t.false((0, filter_1.shouldSkipRequest)(binding, pod));
102
- });
103
- (0, ava_1.default)("should reject when namespace does not match", t => {
104
- const binding = {
105
- kind: k8s_1.gvkMap.V1Pod,
106
- filters: {
107
- name: "",
108
- namespaces: ["bleh"],
109
- labels: {},
110
- annotations: {},
111
- },
112
- callback,
113
- };
114
- const pod = (0, loader_1.POD1)();
115
- t.true((0, filter_1.shouldSkipRequest)(binding, pod));
116
- });
117
- (0, ava_1.default)("should allow when namespace is match", t => {
118
- const binding = {
119
- kind: k8s_1.gvkMap.V1Pod,
120
- filters: {
121
- name: "",
122
- namespaces: ["default", "unicorn", "things"],
123
- labels: {},
124
- annotations: {},
125
- },
126
- callback,
127
- };
128
- const pod = (0, loader_1.POD1)();
129
- t.false((0, filter_1.shouldSkipRequest)(binding, pod));
130
- });
131
- (0, ava_1.default)("should reject when label does not match", t => {
132
- const binding = {
133
- kind: k8s_1.gvkMap.V1Pod,
134
- filters: {
135
- name: "",
136
- namespaces: [],
137
- labels: {
138
- foo: "bar",
139
- },
140
- annotations: {},
141
- },
142
- callback,
143
- };
144
- const pod = (0, loader_1.POD1)();
145
- t.true((0, filter_1.shouldSkipRequest)(binding, pod));
146
- });
147
- (0, ava_1.default)("should allow when label is match", t => {
148
- const binding = {
149
- kind: k8s_1.gvkMap.V1Pod,
150
- filters: {
151
- name: "",
152
- namespaces: [],
153
- labels: {
154
- foo: "bar",
155
- test: "test1",
156
- },
157
- annotations: {},
158
- },
159
- callback,
160
- };
161
- const pod = (0, loader_1.POD1)();
162
- pod.object.metadata = pod.object.metadata || {};
163
- pod.object.metadata.labels = {
164
- foo: "bar",
165
- test: "test1",
166
- test2: "test2",
167
- };
168
- t.false((0, filter_1.shouldSkipRequest)(binding, pod));
169
- });
170
- (0, ava_1.default)("should reject when annotation does not match", t => {
171
- const binding = {
172
- kind: k8s_1.gvkMap.V1Pod,
173
- filters: {
174
- name: "",
175
- namespaces: [],
176
- labels: {},
177
- annotations: {
178
- foo: "bar",
179
- },
180
- },
181
- callback,
182
- };
183
- const pod = (0, loader_1.POD1)();
184
- t.true((0, filter_1.shouldSkipRequest)(binding, pod));
185
- });
186
- (0, ava_1.default)("should allow when annotation is match", t => {
187
- const binding = {
188
- kind: k8s_1.gvkMap.V1Pod,
189
- filters: {
190
- name: "",
191
- namespaces: [],
192
- labels: {},
193
- annotations: {
194
- foo: "bar",
195
- test: "test1",
196
- },
197
- },
198
- callback,
199
- };
200
- const pod = (0, loader_1.POD1)();
201
- pod.object.metadata = pod.object.metadata || {};
202
- pod.object.metadata.annotations = {
203
- foo: "bar",
204
- test: "test1",
205
- test2: "test2",
206
- };
207
- t.false((0, filter_1.shouldSkipRequest)(binding, pod));
208
- });
@@ -1,296 +0,0 @@
1
- "use strict";
2
- // SPDX-License-Identifier: Apache-2.0
3
- // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
4
- var __importDefault = (this && this.__importDefault) || function (mod) {
5
- return (mod && mod.__esModule) ? mod : { "default": mod };
6
- };
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- const ava_1 = __importDefault(require("ava"));
9
- const _1 = require(".");
10
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1APIService'", t => {
11
- const { name } = _1.a.APIService;
12
- const gvk = (0, _1.modelToGroupVersionKind)(name);
13
- t.is(gvk.group, "apiregistration.k8s.io");
14
- t.is(gvk.version, "v1");
15
- t.is(gvk.kind, "APIService");
16
- });
17
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1CertificateSigningRequest'", t => {
18
- const { name } = _1.a.CertificateSigningRequest;
19
- const gvk = (0, _1.modelToGroupVersionKind)(name);
20
- t.is(gvk.group, "certificates.k8s.io");
21
- t.is(gvk.version, "v1");
22
- t.is(gvk.kind, "CertificateSigningRequest");
23
- });
24
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1ConfigMap'", t => {
25
- const { name } = _1.a.ConfigMap;
26
- const gvk = (0, _1.modelToGroupVersionKind)(name);
27
- t.is(gvk.group, "");
28
- t.is(gvk.version, "v1");
29
- t.is(gvk.kind, "ConfigMap");
30
- });
31
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1ControllerRevision'", t => {
32
- const { name } = _1.a.ControllerRevision;
33
- const gvk = (0, _1.modelToGroupVersionKind)(name);
34
- t.is(gvk.group, "apps");
35
- t.is(gvk.version, "v1");
36
- t.is(gvk.kind, "ControllerRevision");
37
- });
38
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1CronJob'", t => {
39
- const { name } = _1.a.CronJob;
40
- const gvk = (0, _1.modelToGroupVersionKind)(name);
41
- t.is(gvk.group, "batch");
42
- t.is(gvk.version, "v1");
43
- t.is(gvk.kind, "CronJob");
44
- });
45
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1CSIDriver'", t => {
46
- const { name } = _1.a.CSIDriver;
47
- const gvk = (0, _1.modelToGroupVersionKind)(name);
48
- t.is(gvk.group, "storage.k8s.io");
49
- t.is(gvk.version, "v1");
50
- t.is(gvk.kind, "CSIDriver");
51
- });
52
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1CSIStorageCapacity'", t => {
53
- const { name } = _1.a.CSIStorageCapacity;
54
- const gvk = (0, _1.modelToGroupVersionKind)(name);
55
- t.is(gvk.group, "storage.k8s.io");
56
- t.is(gvk.version, "v1");
57
- t.is(gvk.kind, "CSIStorageCapacity");
58
- });
59
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1CustomResourceDefinition'", t => {
60
- const { name } = _1.a.CustomResourceDefinition;
61
- const gvk = (0, _1.modelToGroupVersionKind)(name);
62
- t.is(gvk.group, "apiextensions.k8s.io");
63
- t.is(gvk.version, "v1");
64
- t.is(gvk.kind, "CustomResourceDefinition");
65
- });
66
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1DaemonSet'", t => {
67
- const { name } = _1.a.DaemonSet;
68
- const gvk = (0, _1.modelToGroupVersionKind)(name);
69
- t.is(gvk.group, "apps");
70
- t.is(gvk.version, "v1");
71
- t.is(gvk.kind, "DaemonSet");
72
- });
73
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1Deployment'", t => {
74
- const { name } = _1.a.Deployment;
75
- const gvk = (0, _1.modelToGroupVersionKind)(name);
76
- t.is(gvk.group, "apps");
77
- t.is(gvk.version, "v1");
78
- t.is(gvk.kind, "Deployment");
79
- });
80
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1EndpointSlice'", t => {
81
- const { name } = _1.a.EndpointSlice;
82
- const gvk = (0, _1.modelToGroupVersionKind)(name);
83
- t.is(gvk.group, "discovery.k8s.io");
84
- t.is(gvk.version, "v1");
85
- t.is(gvk.kind, "EndpointSlice");
86
- });
87
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1HorizontalPodAutoscaler'", t => {
88
- const { name } = _1.a.HorizontalPodAutoscaler;
89
- const gvk = (0, _1.modelToGroupVersionKind)(name);
90
- t.is(gvk.group, "autoscaling");
91
- t.is(gvk.version, "v2");
92
- t.is(gvk.kind, "HorizontalPodAutoscaler");
93
- });
94
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1Ingress'", t => {
95
- const { name } = _1.a.Ingress;
96
- const gvk = (0, _1.modelToGroupVersionKind)(name);
97
- t.is(gvk.group, "networking.k8s.io");
98
- t.is(gvk.version, "v1");
99
- t.is(gvk.kind, "Ingress");
100
- });
101
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1IngressClass'", t => {
102
- const { name } = _1.a.IngressClass;
103
- const gvk = (0, _1.modelToGroupVersionKind)(name);
104
- t.is(gvk.group, "networking.k8s.io");
105
- t.is(gvk.version, "v1");
106
- t.is(gvk.kind, "IngressClass");
107
- });
108
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1Job'", t => {
109
- const { name } = _1.a.Job;
110
- const gvk = (0, _1.modelToGroupVersionKind)(name);
111
- t.is(gvk.group, "batch");
112
- t.is(gvk.version, "v1");
113
- t.is(gvk.kind, "Job");
114
- });
115
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1LimitRange'", t => {
116
- const { name } = _1.a.LimitRange;
117
- const gvk = (0, _1.modelToGroupVersionKind)(name);
118
- t.is(gvk.group, "");
119
- t.is(gvk.version, "v1");
120
- t.is(gvk.kind, "LimitRange");
121
- });
122
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1LocalSubjectAccessReview'", t => {
123
- const { name } = _1.a.LocalSubjectAccessReview;
124
- const gvk = (0, _1.modelToGroupVersionKind)(name);
125
- t.is(gvk.group, "authorization.k8s.io");
126
- t.is(gvk.version, "v1");
127
- t.is(gvk.kind, "LocalSubjectAccessReview");
128
- });
129
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1MutatingWebhookConfiguration'", t => {
130
- const { name } = _1.a.MutatingWebhookConfiguration;
131
- const gvk = (0, _1.modelToGroupVersionKind)(name);
132
- t.is(gvk.group, "admissionregistration.k8s.io");
133
- t.is(gvk.version, "v1");
134
- t.is(gvk.kind, "MutatingWebhookConfiguration");
135
- });
136
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1Namespace'", t => {
137
- const { name } = _1.a.Namespace;
138
- const gvk = (0, _1.modelToGroupVersionKind)(name);
139
- t.is(gvk.group, "");
140
- t.is(gvk.version, "v1");
141
- t.is(gvk.kind, "Namespace");
142
- });
143
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1NetworkPolicy'", t => {
144
- const { name } = _1.a.NetworkPolicy;
145
- const gvk = (0, _1.modelToGroupVersionKind)(name);
146
- t.is(gvk.group, "networking.k8s.io");
147
- t.is(gvk.version, "v1");
148
- t.is(gvk.kind, "NetworkPolicy");
149
- });
150
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1Node'", t => {
151
- const { name } = _1.a.Node;
152
- const gvk = (0, _1.modelToGroupVersionKind)(name);
153
- t.is(gvk.group, "");
154
- t.is(gvk.version, "v1");
155
- t.is(gvk.kind, "Node");
156
- });
157
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1PersistentVolume'", t => {
158
- const { name } = _1.a.PersistentVolume;
159
- const gvk = (0, _1.modelToGroupVersionKind)(name);
160
- t.is(gvk.group, "");
161
- t.is(gvk.version, "v1");
162
- t.is(gvk.kind, "PersistentVolume");
163
- });
164
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1PersistentVolumeClaim'", t => {
165
- const { name } = _1.a.PersistentVolumeClaim;
166
- const gvk = (0, _1.modelToGroupVersionKind)(name);
167
- t.is(gvk.group, "");
168
- t.is(gvk.version, "v1");
169
- t.is(gvk.kind, "PersistentVolumeClaim");
170
- });
171
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1Pod'", t => {
172
- const { name } = _1.a.Pod;
173
- const gvk = (0, _1.modelToGroupVersionKind)(name);
174
- t.is(gvk.group, "");
175
- t.is(gvk.version, "v1");
176
- t.is(gvk.kind, "Pod");
177
- });
178
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1PodDisruptionBudget'", t => {
179
- const { name } = _1.a.PodDisruptionBudget;
180
- const gvk = (0, _1.modelToGroupVersionKind)(name);
181
- t.is(gvk.group, "policy");
182
- t.is(gvk.version, "v1");
183
- t.is(gvk.kind, "PodDisruptionBudget");
184
- });
185
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1PodTemplate'", t => {
186
- const { name } = _1.a.PodTemplate;
187
- const gvk = (0, _1.modelToGroupVersionKind)(name);
188
- t.is(gvk.group, "");
189
- t.is(gvk.version, "v1");
190
- t.is(gvk.kind, "PodTemplate");
191
- });
192
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1ReplicaSet'", t => {
193
- const { name } = _1.a.ReplicaSet;
194
- const gvk = (0, _1.modelToGroupVersionKind)(name);
195
- t.is(gvk.group, "apps");
196
- t.is(gvk.version, "v1");
197
- t.is(gvk.kind, "ReplicaSet");
198
- });
199
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1ReplicationController'", t => {
200
- const { name } = _1.a.ReplicationController;
201
- const gvk = (0, _1.modelToGroupVersionKind)(name);
202
- t.is(gvk.group, "");
203
- t.is(gvk.version, "v1");
204
- t.is(gvk.kind, "ReplicationController");
205
- });
206
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1ResourceQuota'", t => {
207
- const { name } = _1.a.ResourceQuota;
208
- const gvk = (0, _1.modelToGroupVersionKind)(name);
209
- t.is(gvk.group, "");
210
- t.is(gvk.version, "v1");
211
- t.is(gvk.kind, "ResourceQuota");
212
- });
213
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1RuntimeClass'", t => {
214
- const { name } = _1.a.RuntimeClass;
215
- const gvk = (0, _1.modelToGroupVersionKind)(name);
216
- t.is(gvk.group, "node.k8s.io");
217
- t.is(gvk.version, "v1");
218
- t.is(gvk.kind, "RuntimeClass");
219
- });
220
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1Secret'", t => {
221
- const { name } = _1.a.Secret;
222
- const gvk = (0, _1.modelToGroupVersionKind)(name);
223
- t.is(gvk.group, "");
224
- t.is(gvk.version, "v1");
225
- t.is(gvk.kind, "Secret");
226
- });
227
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1SelfSubjectAccessReview'", t => {
228
- const { name } = _1.a.SelfSubjectAccessReview;
229
- const gvk = (0, _1.modelToGroupVersionKind)(name);
230
- t.is(gvk.group, "authorization.k8s.io");
231
- t.is(gvk.version, "v1");
232
- t.is(gvk.kind, "SelfSubjectAccessReview");
233
- });
234
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1SelfSubjectRulesReview'", t => {
235
- const { name } = _1.a.SelfSubjectRulesReview;
236
- const gvk = (0, _1.modelToGroupVersionKind)(name);
237
- t.is(gvk.group, "authorization.k8s.io");
238
- t.is(gvk.version, "v1");
239
- t.is(gvk.kind, "SelfSubjectRulesReview");
240
- });
241
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1Service'", t => {
242
- const { name } = _1.a.Service;
243
- const gvk = (0, _1.modelToGroupVersionKind)(name);
244
- t.is(gvk.group, "");
245
- t.is(gvk.version, "v1");
246
- t.is(gvk.kind, "Service");
247
- });
248
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1ServiceAccount'", t => {
249
- const { name } = _1.a.ServiceAccount;
250
- const gvk = (0, _1.modelToGroupVersionKind)(name);
251
- t.is(gvk.group, "");
252
- t.is(gvk.version, "v1");
253
- t.is(gvk.kind, "ServiceAccount");
254
- });
255
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1StatefulSet'", t => {
256
- const { name } = _1.a.StatefulSet;
257
- const gvk = (0, _1.modelToGroupVersionKind)(name);
258
- t.is(gvk.group, "apps");
259
- t.is(gvk.version, "v1");
260
- t.is(gvk.kind, "StatefulSet");
261
- });
262
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1StorageClass'", t => {
263
- const { name } = _1.a.StorageClass;
264
- const gvk = (0, _1.modelToGroupVersionKind)(name);
265
- t.is(gvk.group, "storage.k8s.io");
266
- t.is(gvk.version, "v1");
267
- t.is(gvk.kind, "StorageClass");
268
- });
269
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1SubjectAccessReview'", t => {
270
- const { name } = _1.a.SubjectAccessReview;
271
- const gvk = (0, _1.modelToGroupVersionKind)(name);
272
- t.is(gvk.group, "authorization.k8s.io");
273
- t.is(gvk.version, "v1");
274
- t.is(gvk.kind, "SubjectAccessReview");
275
- });
276
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1TokenReview'", t => {
277
- const { name } = _1.a.TokenReview;
278
- const gvk = (0, _1.modelToGroupVersionKind)(name);
279
- t.is(gvk.group, "authentication.k8s.io");
280
- t.is(gvk.version, "v1");
281
- t.is(gvk.kind, "TokenReview");
282
- });
283
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1ValidatingWebhookConfiguration'", t => {
284
- const { name } = _1.a.ValidatingWebhookConfiguration;
285
- const gvk = (0, _1.modelToGroupVersionKind)(name);
286
- t.is(gvk.group, "admissionregistration.k8s.io");
287
- t.is(gvk.version, "v1");
288
- t.is(gvk.kind, "ValidatingWebhookConfiguration");
289
- });
290
- (0, ava_1.default)("should return the correct GroupVersionKind for 'a.V1VolumeAttachment'", t => {
291
- const { name } = _1.a.VolumeAttachment;
292
- const gvk = (0, _1.modelToGroupVersionKind)(name);
293
- t.is(gvk.group, "storage.k8s.io");
294
- t.is(gvk.version, "v1");
295
- t.is(gvk.kind, "VolumeAttachment");
296
- });
@@ -1,64 +0,0 @@
1
- "use strict";
2
- // SPDX-License-Identifier: Apache-2.0
3
- // SPDX-FileCopyrightText: 2023-Present The Pepr Authors
4
- var __importDefault = (this && this.__importDefault) || function (mod) {
5
- return (mod && mod.__esModule) ? mod : { "default": mod };
6
- };
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- const ava_1 = __importDefault(require("ava"));
9
- const logger_1 = require("./logger");
10
- (0, ava_1.default)("Logger debug logs correctly", t => {
11
- const logger = new logger_1.Logger(logger_1.LogLevel.debug); // Create a logger with debug level
12
- const message = "Debug message";
13
- const consoleLog = console.log; // Store the original console.log function
14
- const consoleOutput = [];
15
- // Replace console.log with a mock function to capture the output
16
- console.log = (output) => {
17
- consoleOutput.push(output);
18
- };
19
- logger.debug(message); // Call the debug method
20
- // Check that the output matches the expected value
21
- t.true(consoleOutput[0].includes(logger_1.LogLevel[logger_1.LogLevel.debug]));
22
- t.true(consoleOutput[0].includes(message));
23
- // Restore the original console.log function
24
- console.log = consoleLog;
25
- });
26
- (0, ava_1.default)("Logger info logs correctly", t => {
27
- const logger = new logger_1.Logger(logger_1.LogLevel.info); // Create a logger with info level
28
- const message = "Info message";
29
- const consoleLog = console.log;
30
- const consoleOutput = [];
31
- console.log = (output) => {
32
- consoleOutput.push(output);
33
- };
34
- logger.info(message);
35
- t.true(consoleOutput[0].includes(logger_1.LogLevel[logger_1.LogLevel.info]));
36
- t.true(consoleOutput[0].includes(message));
37
- console.log = consoleLog;
38
- });
39
- (0, ava_1.default)("Logger warn logs correctly", t => {
40
- const logger = new logger_1.Logger(logger_1.LogLevel.warn); // Create a logger with warn level
41
- const message = "Warning message";
42
- const consoleLog = console.log;
43
- const consoleOutput = [];
44
- console.log = (output) => {
45
- consoleOutput.push(output);
46
- };
47
- logger.warn(message);
48
- t.true(consoleOutput[0].includes(logger_1.LogLevel[logger_1.LogLevel.warn]));
49
- t.true(consoleOutput[0].includes(message));
50
- console.log = consoleLog;
51
- });
52
- (0, ava_1.default)("Logger error logs correctly", t => {
53
- const logger = new logger_1.Logger(logger_1.LogLevel.error); // Create a logger with error level
54
- const message = "Error message";
55
- const consoleLog = console.log;
56
- const consoleOutput = [];
57
- console.log = (output) => {
58
- consoleOutput.push(output);
59
- };
60
- logger.error(message);
61
- t.true(consoleOutput[0].includes(logger_1.LogLevel[logger_1.LogLevel.error]));
62
- t.true(consoleOutput[0].includes(message));
63
- console.log = consoleLog;
64
- });
@@ -1,13 +0,0 @@
1
- {
2
- "arrowParens": "avoid",
3
- "bracketSameLine": false,
4
- "bracketSpacing": true,
5
- "embeddedLanguageFormatting": "auto",
6
- "insertPragma": false,
7
- "printWidth": 80,
8
- "quoteProps": "as-needed",
9
- "requirePragma": false,
10
- "semi": true,
11
- "tabWidth": 2,
12
- "useTabs": false
13
- }
package/docs/actions.md DELETED
@@ -1,58 +0,0 @@
1
- # CapabilityActions
2
-
3
- A CapabilityAction is a discrete set of behaviors defined in a single function that acts on a given Kubernetes GroupVersionKind (GVK) passed in from Kubernetes. CapabilityActions are the atomic operations that are performed on Kubernetes resources by Pepr.
4
-
5
- For example, a CapabilityAction could be responsible for adding a specific label to a Kubernetes resource, or for modifying a specific field in a resource's metadata. CapabilityActions can be grouped together within a Capability to provide a more comprehensive set of operations that can be performed on Kubernetes resources.
6
-
7
- Let's look at some example CapabilityActions that are included in the `HelloPepr` capability that is created for you when you [`pepr init`](./cli.md#pepr-init):
8
-
9
- ---
10
-
11
- In this first example, Pepr is adding a label and annotation to a ConfigMap with tne name `example-1` when it is created. Comments are added to each line to explain in more detail what is happening.
12
-
13
- ```ts
14
- // When(a.<Kind>) tells Pepr what K8s GroupVersionKind (GVK) this CapabilityAction should act on.
15
- When(a.ConfigMap)
16
- // Next we tell Pepr to only act on new ConfigMaps that are created.
17
- .IsCreated()
18
- // Then we tell Pepr to only act on ConfigMaps with the name "example-1".
19
- .WithName("example-1")
20
- // Then() is where we define the actual behavior of this CapabilityAction.
21
- .Then(request => {
22
- // The request object is a wrapper around the K8s resource that Pepr is acting on.
23
- request
24
- // Here we are adding a label to the ConfigMap.
25
- .SetLabel("pepr", "was-here")
26
- // And here we are adding an annotation.
27
- .SetAnnotation("pepr.dev", "annotations-work-too");
28
-
29
- // Note that we are not returning anything here. This is because Pepr is tracking the changes in each CapabilityAction automatically.
30
- });
31
- ```
32
-
33
- ---
34
-
35
- This example is identical to the previous one, except we are acting on a different CongigMap name and using the `ThenSet()` shorthand to merge changes into the resource.
36
-
37
- ```ts
38
- // Once again, we tell Pepr what K8s GVK this CapabilityAction should act on.
39
- When(a.ConfigMap)
40
- // Next we tell Pepr to only act on new ConfigMaps that are created.
41
- .IsCreated()
42
- // This time we are acting on a ConfigMap with the name "example-2".
43
- .WithName("example-2")
44
- // Instead of using Then(), we are using ThenSet() to merge changes into the resource without a function call.
45
- .ThenSet({
46
- // Using Typescript, we will get intellisense for the ConfigMap object and immediate type-validation for the values we are setting.
47
- metadata: {
48
- labels: {
49
- pepr: "was-here",
50
- },
51
- annotations: {
52
- "pepr.dev": "annotations-work-too",
53
- },
54
- },
55
- });
56
- ```
57
-
58
- There are many more examples in the `HelloPepr` capability that you can use as a reference when creating your own CapabilityActions. Note that each time you run [`pepr update`](./cli.md#pepr-update), Pepr will automatically update the `HelloPepr` capability with the latest examples and best practices for you to reference and test directly in your Pepr Module.
@@ -1,17 +0,0 @@
1
- # Capabilities
2
-
3
- A capability is set of related [CapabilityActions](./actions.md) that work together to achieve a specific transformation or operation on Kubernetes resources. Capabilities are user-defined and can include one or more CapabilityActions. They are defined within a Pepr module and can be used in both MutatingWebhookConfigurations and ValidatingWebhookConfigurations. A Capability can have a specific scope, such as mutating or validating, and can be reused in multiple Pepr modules.
4
-
5
- When you [`pepr init`](./cli.md#pepr-init), a `capabilities` directory is created for you. This directory is where you will define your capabilities. You can create as many capabilities as you need, and each capability can contain one or more CapabilityActions. Pepr also automatically creates a `HelloPepr` capability with a number of example CapabilityActions to help you get started.
6
-
7
- ## Creating a Capability
8
-
9
- Define a new capability can be done via a [VSCode Snippet](https://code.visualstudio.com/docs/editor/userdefinedsnippets) generated during [`pepr init`](./cli.md#pepr-init).
10
-
11
- 1. Create a new file in the `capabilities` directory with the name of your capability. For example, `capabilities/my-capability.ts`.
12
-
13
- 1. Open the new file in VSCode and type `create` in the file. A suggestion should prompt you to generate the content from there.
14
-
15
- https://user-images.githubusercontent.com/882485/230897379-0bb57dff-9832-479f-8733-79e103703135.mp4
16
-
17
- _If you prefer not to use VSCode, you can also modify or copy the `HelloPepr` capability to meet your needs instead._