Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add typing support to regex-related adjudicators #1484

Closed
wants to merge 67 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
1137b84
Create full mocks of AdmissionRequest<KubernetesObject>
samayer12 Nov 7, 2024
9546791
Add return type to Admission Request adjudicators
samayer12 Nov 7, 2024
5d673d5
Address potentially undefined input to adjudicator
samayer12 Nov 7, 2024
12c8c4a
Add funciton return types
samayer12 Nov 7, 2024
cc3e810
Use consistent enum property names
samayer12 Nov 7, 2024
d94543d
Reworking types to remove typescript warnings so that I can actually …
samayer12 Nov 7, 2024
a169536
Work on resolving typing issues by using actual objects instead of pa…
samayer12 Nov 18, 2024
8300b37
use explicit imports in test file
samayer12 Nov 18, 2024
bf38e38
Fix failing tests in bindingadjudicator
samayer12 Nov 18, 2024
984660f
tidy test exports, add typing, get passing tests
samayer12 Nov 18, 2024
ecdd130
Merge branch 'main' into 1397-type-adjudicators
samayer12 Nov 18, 2024
f5c3a8d
Add typing to mismatchedEvent()
samayer12 Nov 18, 2024
2a0c025
Merge branch 'main' into 1397-type-adjudicators
samayer12 Nov 19, 2024
e7f9a5b
Update imports
samayer12 Nov 19, 2024
19a7dcd
Remove obsolete test cases now that we have typing support
samayer12 Nov 19, 2024
1eb7cde
Remove undefined return type on definedName()
samayer12 Nov 19, 2024
9aa94e9
Remove obsolete test cases now that we use typing, manage typing for …
samayer12 Nov 19, 2024
6fb930a
Update imports
samayer12 Nov 19, 2024
e7a2a86
Merge branch 'main' into 1397-type-adjudicators
samayer12 Nov 19, 2024
4c78fe0
Use regexes in test data to match typing
samayer12 Nov 20, 2024
dd2f84d
Update test case to handle typing with a null test case
samayer12 Nov 20, 2024
eaf481f
Resolve test failure for mismatchedNamespaceRegex()
samayer12 Nov 20, 2024
b790be3
Merge branch 'main' into 1397-type-adjudicators
samayer12 Nov 20, 2024
d7da7cf
Merge branch 'main' into 1397-type-adjudicators
samayer12 Nov 20, 2024
25081c2
Move default test objects to central location
samayer12 Nov 20, 2024
5cc5667
Use defaultTestObjects in bindingAdjudicators.test.ts
samayer12 Nov 20, 2024
aa24a30
Centralize more default test values
samayer12 Nov 20, 2024
dfa4eee
Merge branch 'main' into 1397-type-adjudicators
samayer12 Nov 20, 2024
2bdad5c
Undo type coversion to RexExp, use string
samayer12 Nov 21, 2024
e08e896
Remove unecessary message output sanitization
samayer12 Nov 21, 2024
786c1a2
Rearrange import and managed regex usage in tests
samayer12 Nov 21, 2024
9cc9267
Move filesystem helper to specific file
samayer12 Nov 21, 2024
a0dab61
Remove a test case obviated by the use of typing
samayer12 Nov 21, 2024
8bbcfd1
Remove kfc mock
samayer12 Nov 21, 2024
6ca317b
Use it() instead of test() to match domain-driven test naming style
samayer12 Nov 21, 2024
909e890
Rewrite test using full objects and it.each()
samayer12 Nov 21, 2024
937ce19
Remove unnecessary regex edge case now that we use typing
samayer12 Nov 21, 2024
a98e0df
Update regex to match test condition
samayer12 Nov 21, 2024
5a0753d
Restructure test format
samayer12 Nov 21, 2024
d983481
Restructure name equality test
samayer12 Nov 21, 2024
d887b53
Remove mockK8s.mockImplementation()
samayer12 Nov 21, 2024
2e44cc9
Restructure test
samayer12 Nov 21, 2024
5ac5159
Put related tests into a describe() block
samayer12 Nov 21, 2024
7c2ae10
Extract large function to new file
samayer12 Nov 21, 2024
7434ce8
Remove mocks and set return type
samayer12 Nov 21, 2024
172ebf4
Update import from cli
samayer12 Nov 21, 2024
ac8aa24
Update imports
samayer12 Nov 21, 2024
1a4e7dd
Merge branch 'main' into 1397-type-adjudicators
samayer12 Nov 21, 2024
06ea6cc
Update imports after file move
samayer12 Nov 21, 2024
0eb3f1e
Move some helper functions to deploymentChecks
samayer12 Nov 21, 2024
cb1d7bb
Remove file restructure for next commit
samayer12 Nov 21, 2024
7f98a9c
Merge branch '1397-split-helpers' into 1397-type-adjudicators
samayer12 Nov 21, 2024
8ecce94
Merge branch 'main' into 1397-type-adjudicators
samayer12 Nov 22, 2024
70c1178
Merge branch 'main' into 1397-type-adjudicators
samayer12 Nov 22, 2024
257c4b8
Undo regexp work to revisit on a separate PR
samayer12 Nov 22, 2024
7f1bbec
Revert "Undo regexp work to revisit on a separate PR"
samayer12 Nov 22, 2024
c88a28a
Merge branch 'main' into 1397-type-regex-adjudicators
samayer12 Dec 6, 2024
23adc9e
Merge branch 'main' into 1397-type-regex-adjudicators
samayer12 Dec 11, 2024
9c345aa
Update capability typing
samayer12 Dec 11, 2024
0917da5
Remove lint suppressions
samayer12 Dec 11, 2024
a98fdd9
Remove ternary in log message
samayer12 Dec 11, 2024
c36084b
Remove suppression
samayer12 Dec 11, 2024
843f70e
Revert changes to regex pipe() function
samayer12 Dec 11, 2024
dba5f25
Add typing
samayer12 Dec 11, 2024
12b815e
Merge branch 'main' into 1397-type-regex-adjudicators
samayer12 Dec 12, 2024
bddfcf8
Merge branch 'main' into 1397-type-regex-adjudicators
samayer12 Dec 16, 2024
3e9c842
Undo implementation change to adjudicators
samayer12 Dec 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/lib/capability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
* @param kind if using a custom KubernetesObject not available in `a.*`, specify the GroupVersionKind
* @returns
*/
When = <T extends GenericClass>(model: T, kind?: GroupVersionKind): WhenSelector<T> => {

Check warning on line 183 in src/lib/capability.ts

View workflow job for this annotation

GitHub Actions / format

Method 'When' has too many statements (26). Maximum allowed is 20
const matchedKind = modelToGroupVersionKind(model.name);

// If the kind is not specified and the model is not a KubernetesObject, throw an error
Expand Down Expand Up @@ -212,9 +212,9 @@
type ExtendedCommonChainType = CommonChainType & {
Alias: (alias: string) => CommonChainType;
InNamespace: (...namespaces: string[]) => BindingWithName<T>;
InNamespaceRegex: (...namespaces: RegExp[]) => BindingWithName<T>;
InNamespaceRegex: (...namespaces: string[]) => BindingWithName<T>;
WithName: (name: string) => BindingFilter<T>;
WithNameRegex: (regexName: RegExp) => BindingFilter<T>;
WithNameRegex: (regexName: string) => BindingFilter<T>;
WithDeletionTimestamp: () => BindingFilter<T>;
};

Expand Down Expand Up @@ -355,9 +355,9 @@
return { ...commonChain, WithName, WithNameRegex };
}

function InNamespaceRegex(...namespaces: RegExp[]): BindingWithName<T> {
function InNamespaceRegex(...namespaces: string[]): BindingWithName<T> {

Check warning on line 358 in src/lib/capability.ts

View check run for this annotation

Codecov / codecov/patch

src/lib/capability.ts#L358

Added line #L358 was not covered by tests
Log.debug(`Add regex namespaces filter ${namespaces}`, prefix);
binding.filters.regexNamespaces.push(...namespaces.map(regex => regex.source));
binding.filters.regexNamespaces.push(...namespaces);

Check warning on line 360 in src/lib/capability.ts

View check run for this annotation

Codecov / codecov/patch

src/lib/capability.ts#L360

Added line #L360 was not covered by tests
return { ...commonChain, WithName, WithNameRegex };
}

Expand All @@ -367,9 +367,9 @@
return commonChain;
}

function WithNameRegex(regexName: RegExp): BindingFilter<T> {
function WithNameRegex(regexName: string): BindingFilter<T> {

Check warning on line 370 in src/lib/capability.ts

View check run for this annotation

Codecov / codecov/patch

src/lib/capability.ts#L370

Added line #L370 was not covered by tests
Log.debug(`Add regex name filter ${regexName}`, prefix);
binding.filters.regexName = regexName.source;
binding.filters.regexName = regexName;

Check warning on line 372 in src/lib/capability.ts

View check run for this annotation

Codecov / codecov/patch

src/lib/capability.ts#L372

Added line #L372 was not covered by tests
return commonChain;
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/filter/adjudicators/adjudicators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export const mismatchedNamespace = allPass([

export const mismatchedNamespaceRegex = allPass([
pipe(nthArg(0), definesNamespaceRegexes),
pipe((binding, kubernetesObject) =>
pipe((binding: Binding, kubernetesObject: KubernetesObject) =>
pipe(
any((regEx: string) => new RegExp(regEx).test(carriedNamespace(kubernetesObject))),
not,
Expand Down
4 changes: 2 additions & 2 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@ export type BindingWithName<T extends GenericClass> = BindingFilter<T> & {
/** Only apply the action if the resource name matches the specified name. */
WithName: (name: string) => BindingFilter<T>;
/** Only apply the action if the resource name matches the specified regex name. */
WithNameRegex: (name: RegExp) => BindingFilter<T>;
WithNameRegex: (name: string) => BindingFilter<T>;
};

export type BindingAll<T extends GenericClass> = BindingWithName<T> & {
/** Only apply the action if the resource is in one of the specified namespaces.*/
InNamespace: (...namespaces: string[]) => BindingWithName<T>;
/** Only apply the action if the resource is in one of the specified regex namespaces.*/
InNamespaceRegex: (...namespaces: RegExp[]) => BindingWithName<T>;
InNamespaceRegex: (...namespaces: string[]) => BindingWithName<T>;
};

export type CommonActionChain<T extends GenericClass> = MutateActionChain<T> & {
Expand Down
Loading