pepr 0.37.1 → 0.37.3

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/src/lib/filter.ts CHANGED
@@ -4,6 +4,24 @@
4
4
  import { AdmissionRequest, Binding, Operation } from "./types";
5
5
  import {
6
6
  carriesIgnoredNamespace,
7
+ carriedName,
8
+ definedEvent,
9
+ declaredOperation,
10
+ definedName,
11
+ definedGroup,
12
+ declaredGroup,
13
+ definedVersion,
14
+ declaredVersion,
15
+ definedKind,
16
+ declaredKind,
17
+ definedNamespaces,
18
+ carriedNamespace,
19
+ definedLabels,
20
+ carriedLabels,
21
+ definedAnnotations,
22
+ carriedAnnotations,
23
+ definedNamespaceRegexes,
24
+ definedNameRegex,
7
25
  misboundDeleteWithDeletionTimestamp,
8
26
  mismatchedDeletionTimestamp,
9
27
  mismatchedAnnotations,
@@ -32,27 +50,94 @@ export function shouldSkipRequest(
32
50
  req: AdmissionRequest,
33
51
  capabilityNamespaces: string[],
34
52
  ignoredNamespaces?: string[],
35
- ): boolean {
53
+ ): string {
54
+ const prefix = "Ignoring Admission Callback:";
36
55
  const obj = req.operation === Operation.DELETE ? req.oldObject : req.object;
37
56
 
38
57
  // prettier-ignore
39
58
  return (
40
- misboundDeleteWithDeletionTimestamp(binding) ? true :
41
- mismatchedDeletionTimestamp(binding, obj) ? true :
42
- mismatchedEvent(binding, req) ? true :
43
- mismatchedName(binding, obj) ? true :
44
- mismatchedGroup(binding, req) ? true :
45
- mismatchedVersion(binding, req) ? true :
46
- mismatchedKind(binding, req) ? true :
47
- unbindableNamespaces(capabilityNamespaces, binding) ? true :
48
- uncarryableNamespace(capabilityNamespaces, obj) ? true :
49
- mismatchedNamespace(binding, obj) ? true :
50
- mismatchedLabels(binding, obj) ? true :
51
- mismatchedAnnotations(binding, obj) ? true :
52
- mismatchedNamespaceRegex(binding, obj) ? true :
53
- mismatchedNameRegex(binding, obj) ? true :
54
- carriesIgnoredNamespace(ignoredNamespaces, obj) ? true :
55
-
56
- false
59
+ misboundDeleteWithDeletionTimestamp(binding) ?
60
+ `${prefix} Cannot use deletionTimestamp filter on a DELETE operation.` :
61
+
62
+ mismatchedDeletionTimestamp(binding, obj) ?
63
+ `${prefix} Binding defines deletionTimestamp but Object does not carry it.` :
64
+
65
+ mismatchedEvent(binding, req) ?
66
+ (
67
+ `${prefix} Binding defines event '${definedEvent(binding)}' but ` +
68
+ `Request declares '${declaredOperation(req)}'.`
69
+ ) :
70
+
71
+ mismatchedName(binding, obj) ?
72
+ `${prefix} Binding defines name '${definedName(binding)}' but Object carries '${carriedName(obj)}'.` :
73
+
74
+ mismatchedGroup(binding, req) ?
75
+ (
76
+ `${prefix} Binding defines group '${definedGroup(binding)}' but ` +
77
+ `Request declares '${declaredGroup(req)}'.`
78
+ ) :
79
+
80
+ mismatchedVersion(binding, req) ?
81
+ (
82
+ `${prefix} Binding defines version '${definedVersion(binding)}' but ` +
83
+ `Request declares '${declaredVersion(req)}'.`
84
+ ) :
85
+
86
+ mismatchedKind(binding, req) ?
87
+ (
88
+ `${prefix} Binding defines kind '${definedKind(binding)}' but ` +
89
+ `Request declares '${declaredKind(req)}'.`
90
+ ) :
91
+
92
+ unbindableNamespaces(capabilityNamespaces, binding) ?
93
+ (
94
+ `${prefix} Binding defines namespaces ${JSON.stringify(definedNamespaces(binding))} ` +
95
+ `but namespaces allowed by Capability are '${JSON.stringify(capabilityNamespaces)}'.`
96
+ ) :
97
+
98
+ uncarryableNamespace(capabilityNamespaces, obj) ?
99
+ (
100
+ `${prefix} Object carries namespace '${carriedNamespace(obj)}' ` +
101
+ `but namespaces allowed by Capability are '${JSON.stringify(capabilityNamespaces)}'.`
102
+ ) :
103
+
104
+ mismatchedNamespace(binding, obj) ?
105
+ (
106
+ `${prefix} Binding defines namespaces '${JSON.stringify(definedNamespaces(binding))}' ` +
107
+ `but Object carries '${carriedNamespace(obj)}'.`
108
+ ) :
109
+
110
+ mismatchedLabels(binding, obj) ?
111
+ (
112
+ `${prefix} Binding defines labels '${JSON.stringify(definedLabels(binding))}' ` +
113
+ `but Object carries '${JSON.stringify(carriedLabels(obj))}'.`
114
+ ) :
115
+
116
+ mismatchedAnnotations(binding, obj) ?
117
+ (
118
+ `${prefix} Binding defines annotations '${JSON.stringify(definedAnnotations(binding))}' ` +
119
+ `but Object carries '${JSON.stringify(carriedAnnotations(obj))}'.`
120
+ ) :
121
+
122
+ mismatchedNamespaceRegex(binding, obj) ?
123
+ (
124
+ `${prefix} Binding defines namespace regexes ` +
125
+ `'${JSON.stringify(definedNamespaceRegexes(binding))}' ` +
126
+ `but Object carries '${carriedNamespace(obj)}'.`
127
+ ) :
128
+
129
+ mismatchedNameRegex(binding, obj) ?
130
+ (
131
+ `${prefix} Binding defines name regex '${definedNameRegex(binding)}' ` +
132
+ `but Object carries '${carriedName(obj)}'.`
133
+ ) :
134
+
135
+ carriesIgnoredNamespace(ignoredNamespaces, obj) ?
136
+ (
137
+ `${prefix} Object carries namespace '${carriedNamespace(obj)}' ` +
138
+ `but ignored namespaces include '${JSON.stringify(ignoredNamespaces)}'.`
139
+ ) :
140
+
141
+ ""
57
142
  );
58
143
  }
@@ -50,7 +50,9 @@ export async function mutateProcessor(
50
50
  }
51
51
 
52
52
  // Continue to the next action without doing anything if this one should be skipped
53
- if (shouldSkipRequest(action, req, namespaces, config?.alwaysIgnore?.namespaces)) {
53
+ const shouldSkip = shouldSkipRequest(action, req, namespaces, config?.alwaysIgnore?.namespaces);
54
+ if (shouldSkip !== "") {
55
+ Log.debug(shouldSkip);
54
56
  continue;
55
57
  }
56
58
 
@@ -44,7 +44,9 @@ export async function validateProcessor(
44
44
  };
45
45
 
46
46
  // Continue to the next action without doing anything if this one should be skipped
47
- if (shouldSkipRequest(action, req, namespaces, config?.alwaysIgnore?.namespaces)) {
47
+ const shouldSkip = shouldSkipRequest(action, req, namespaces, config?.alwaysIgnore?.namespaces);
48
+ if (shouldSkip !== "") {
49
+ Log.debug(shouldSkip);
48
50
  continue;
49
51
  }
50
52