-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: reduce complexity of helpers.ts (#1575)
## Description This PR addresses complexity in `helpers.ts` End to End Test: <!-- if applicable --> (See [Pepr Excellent Examples](https://github.com/defenseunicorns/pepr-excellent-examples)) ## Related Issue Fixes #1534 ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [x] Other (security config, docs update, etc) ## Checklist before merging - [x] Unit, [Journey](https://github.com/defenseunicorns/pepr/tree/main/journey), [E2E Tests](https://github.com/defenseunicorns/pepr-excellent-examples), [docs](https://github.com/defenseunicorns/pepr/tree/main/docs), [adr](https://github.com/defenseunicorns/pepr/tree/main/adr) added or updated as needed - [x] [Contributor Guide Steps](https://docs.pepr.dev/main/contribute/#submitting-a-pull-request) followed
- Loading branch information
Showing
4 changed files
with
135 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import { KubernetesObject } from "kubernetes-fluent-client"; | ||
import { | ||
mismatchedDeletionTimestamp, | ||
mismatchedName, | ||
definedName, | ||
carriedName, | ||
misboundNamespace, | ||
mismatchedLabels, | ||
definedLabels, | ||
carriedLabels, | ||
mismatchedAnnotations, | ||
definedAnnotations, | ||
carriedAnnotations, | ||
uncarryableNamespace, | ||
carriedNamespace, | ||
unbindableNamespaces, | ||
definedNamespaces, | ||
mismatchedNamespace, | ||
mismatchedNamespaceRegex, | ||
definedNamespaceRegexes, | ||
mismatchedNameRegex, | ||
definedNameRegex, | ||
carriesIgnoredNamespace, | ||
missingCarriableNamespace, | ||
} from "./adjudicators/adjudicators"; | ||
import { Binding } from "../types"; | ||
|
||
/** | ||
* Decide to run callback after the event comes back from API Server | ||
**/ | ||
|
||
export function filterNoMatchReason( | ||
binding: Binding, | ||
kubernetesObject: Partial<KubernetesObject>, | ||
capabilityNamespaces: string[], | ||
ignoredNamespaces?: string[], | ||
): string { | ||
const prefix = "Ignoring Watch Callback:"; | ||
|
||
// prettier-ignore | ||
return ( | ||
mismatchedDeletionTimestamp(binding, kubernetesObject) ? | ||
`${prefix} Binding defines deletionTimestamp but Object does not carry it.` : | ||
|
||
mismatchedName(binding, kubernetesObject) ? | ||
`${prefix} Binding defines name '${definedName(binding)}' but Object carries '${carriedName(kubernetesObject)}'.` : | ||
|
||
misboundNamespace(binding) ? | ||
`${prefix} Cannot use namespace filter on a namespace object.` : | ||
|
||
mismatchedLabels(binding, kubernetesObject) ? | ||
( | ||
`${prefix} Binding defines labels '${JSON.stringify(definedLabels(binding))}' ` + | ||
`but Object carries '${JSON.stringify(carriedLabels(kubernetesObject))}'.` | ||
) : | ||
|
||
mismatchedAnnotations(binding, kubernetesObject) ? | ||
( | ||
`${prefix} Binding defines annotations '${JSON.stringify(definedAnnotations(binding))}' ` + | ||
`but Object carries '${JSON.stringify(carriedAnnotations(kubernetesObject))}'.` | ||
) : | ||
|
||
uncarryableNamespace(capabilityNamespaces, kubernetesObject) ? | ||
( | ||
`${prefix} Object carries namespace '${carriedNamespace(kubernetesObject)}' ` + | ||
`but namespaces allowed by Capability are '${JSON.stringify(capabilityNamespaces)}'.` | ||
) : | ||
|
||
unbindableNamespaces(capabilityNamespaces, binding) ? | ||
( | ||
`${prefix} Binding defines namespaces ${JSON.stringify(definedNamespaces(binding))} ` + | ||
`but namespaces allowed by Capability are '${JSON.stringify(capabilityNamespaces)}'.` | ||
) : | ||
|
||
mismatchedNamespace(binding, kubernetesObject) ? | ||
( | ||
`${prefix} Binding defines namespaces '${JSON.stringify(definedNamespaces(binding))}' ` + | ||
`but Object carries '${carriedNamespace(kubernetesObject)}'.` | ||
) : | ||
|
||
mismatchedNamespaceRegex(binding, kubernetesObject) ? | ||
( | ||
`${prefix} Binding defines namespace regexes ` + | ||
`'${JSON.stringify(definedNamespaceRegexes(binding))}' ` + | ||
`but Object carries '${carriedNamespace(kubernetesObject)}'.` | ||
) : | ||
|
||
mismatchedNameRegex(binding, kubernetesObject) ? | ||
( | ||
`${prefix} Binding defines name regex '${definedNameRegex(binding)}' ` + | ||
`but Object carries '${carriedName(kubernetesObject)}'.` | ||
) : | ||
|
||
carriesIgnoredNamespace(ignoredNamespaces, kubernetesObject) ? | ||
( | ||
`${prefix} Object carries namespace '${carriedNamespace(kubernetesObject)}' ` + | ||
`but ignored namespaces include '${JSON.stringify(ignoredNamespaces)}'.` | ||
) : | ||
|
||
missingCarriableNamespace(capabilityNamespaces, kubernetesObject) ? | ||
( | ||
`${prefix} Object does not carry a namespace ` + | ||
`but namespaces allowed by Capability are '${JSON.stringify(capabilityNamespaces)}'.` | ||
) : | ||
|
||
"" | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters