pepr 0.42.1 → 0.42.2
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/dist/cli/deploy.d.ts +15 -0
- package/dist/cli/deploy.d.ts.map +1 -1
- package/dist/cli/dev.d.ts.map +1 -1
- package/dist/cli/format.d.ts.map +1 -1
- package/dist/cli/format.helpers.d.ts +3 -0
- package/dist/cli/format.helpers.d.ts.map +1 -0
- package/dist/cli/init/enums.d.ts +10 -0
- package/dist/cli/init/enums.d.ts.map +1 -0
- package/dist/cli/init/index.d.ts.map +1 -1
- package/dist/cli/init/templates.d.ts +15 -11
- package/dist/cli/init/templates.d.ts.map +1 -1
- package/dist/cli/init/utils.d.ts.map +1 -1
- package/dist/cli/init/walkthrough.d.ts +3 -2
- package/dist/cli/init/walkthrough.d.ts.map +1 -1
- package/dist/cli/kfc.d.ts.map +1 -1
- package/dist/cli/root.d.ts.map +1 -1
- package/dist/cli/update.d.ts.map +1 -1
- package/dist/cli/uuid.d.ts.map +1 -1
- package/dist/cli.js +145 -306
- package/dist/controller.js +1 -195
- package/dist/fixtures/loader.d.ts.map +1 -1
- package/dist/lib/assets/deploy.d.ts.map +1 -1
- package/dist/lib/assets/index.d.ts +1 -1
- package/dist/lib/assets/index.d.ts.map +1 -1
- package/dist/lib/assets/pods.d.ts +1 -3
- package/dist/lib/assets/pods.d.ts.map +1 -1
- package/dist/lib/assets/rbac.d.ts.map +1 -1
- package/dist/lib/assets/webhooks.d.ts.map +1 -1
- package/dist/lib/controller/index.d.ts +2 -2
- package/dist/lib/controller/index.d.ts.map +1 -1
- package/dist/lib/controller/store.d.ts +1 -1
- package/dist/lib/controller/store.d.ts.map +1 -1
- package/dist/lib/controller/storeCache.d.ts +1 -1
- package/dist/lib/controller/storeCache.d.ts.map +1 -1
- package/dist/lib/{capability.d.ts → core/capability.d.ts} +1 -1
- package/dist/lib/core/capability.d.ts.map +1 -0
- package/dist/lib/{module.d.ts → core/module.d.ts} +2 -2
- package/dist/lib/core/module.d.ts.map +1 -0
- package/dist/lib/core/queue.d.ts.map +1 -0
- package/dist/lib/{schedule.d.ts → core/schedule.d.ts} +0 -1
- package/dist/lib/core/schedule.d.ts.map +1 -0
- package/dist/lib/core/storage.d.ts.map +1 -0
- package/dist/lib/deploymentChecks.d.ts.map +1 -1
- package/dist/lib/errors.d.ts +0 -5
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/filesystemService.d.ts.map +1 -1
- package/dist/lib/filter/adjudicators/adjudicators.d.ts +5 -4
- package/dist/lib/filter/adjudicators/adjudicators.d.ts.map +1 -1
- package/dist/lib/filter/filter.d.ts +33 -1
- package/dist/lib/filter/filter.d.ts.map +1 -1
- package/dist/lib/finalizer.d.ts.map +1 -1
- package/dist/lib/helpers.d.ts +4 -9
- package/dist/lib/helpers.d.ts.map +1 -1
- package/dist/lib/included-files.d.ts.map +1 -1
- package/dist/lib/mutate-request.d.ts.map +1 -1
- package/dist/lib/processors/mutate-processor.d.ts +28 -0
- package/dist/lib/processors/mutate-processor.d.ts.map +1 -0
- package/dist/lib/{validate-processor.d.ts → processors/validate-processor.d.ts} +5 -5
- package/dist/lib/processors/validate-processor.d.ts.map +1 -0
- package/dist/lib/{watch-processor.d.ts → processors/watch-processor.d.ts} +2 -2
- package/dist/lib/processors/watch-processor.d.ts.map +1 -0
- package/dist/lib/telemetry/logger.d.ts.map +1 -1
- package/dist/lib/telemetry/metrics.d.ts.map +1 -1
- package/dist/lib/validate-request.d.ts +2 -2
- package/dist/lib/validate-request.d.ts.map +1 -1
- package/dist/lib.d.ts +2 -2
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +383 -243
- package/dist/lib.js.map +4 -4
- package/dist/sdk/heredoc.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/cli/deploy.ts +113 -74
- package/src/cli/dev.ts +2 -2
- package/src/cli/format.helpers.ts +27 -0
- package/src/cli/format.ts +4 -18
- package/src/cli/init/enums.ts +9 -0
- package/src/cli/init/index.ts +4 -3
- package/src/cli/init/templates.ts +30 -2
- package/src/cli/init/utils.ts +3 -3
- package/src/cli/init/walkthrough.ts +7 -8
- package/src/cli/kfc.ts +1 -1
- package/src/cli/root.ts +1 -1
- package/src/cli/update.ts +1 -1
- package/src/cli/uuid.ts +1 -1
- package/src/fixtures/loader.ts +2 -2
- package/src/lib/assets/deploy.ts +5 -5
- package/src/lib/assets/index.ts +1 -1
- package/src/lib/assets/pods.ts +1 -1
- package/src/lib/assets/webhooks.ts +30 -45
- package/src/lib/controller/index.ts +4 -4
- package/src/lib/controller/store.ts +2 -2
- package/src/lib/controller/storeCache.ts +6 -2
- package/src/lib/{capability.ts → core/capability.ts} +4 -4
- package/src/lib/{module.ts → core/module.ts} +10 -10
- package/src/lib/{queue.ts → core/queue.ts} +1 -1
- package/src/lib/deploymentChecks.ts +2 -2
- package/src/lib/errors.ts +3 -8
- package/src/lib/filesystemService.ts +1 -1
- package/src/lib/filter/adjudicators/adjudicators.ts +40 -9
- package/src/lib/filter/filter.ts +204 -111
- package/src/lib/finalizer.ts +2 -2
- package/src/lib/helpers.ts +20 -133
- package/src/lib/included-files.ts +1 -1
- package/src/lib/processors/mutate-processor.ts +225 -0
- package/src/lib/{validate-processor.ts → processors/validate-processor.ts} +8 -8
- package/src/lib/{watch-processor.ts → processors/watch-processor.ts} +8 -8
- package/src/lib/telemetry/logger.ts +3 -1
- package/src/lib/tls.ts +5 -1
- package/src/lib/validate-request.ts +4 -4
- package/src/lib.ts +2 -2
- package/src/runtime/controller.ts +2 -2
- package/src/sdk/heredoc.ts +1 -1
- package/dist/lib/capability.d.ts.map +0 -1
- package/dist/lib/module.d.ts.map +0 -1
- package/dist/lib/mutate-processor.d.ts +0 -6
- package/dist/lib/mutate-processor.d.ts.map +0 -1
- package/dist/lib/queue.d.ts.map +0 -1
- package/dist/lib/schedule.d.ts.map +0 -1
- package/dist/lib/storage.d.ts.map +0 -1
- package/dist/lib/validate-processor.d.ts.map +0 -1
- package/dist/lib/watch-processor.d.ts.map +0 -1
- package/src/lib/mutate-processor.ts +0 -165
- /package/dist/lib/{queue.d.ts → core/queue.d.ts} +0 -0
- /package/dist/lib/{storage.d.ts → core/storage.d.ts} +0 -0
- /package/src/lib/{schedule.ts → core/schedule.ts} +0 -0
- /package/src/lib/{storage.ts → core/storage.ts} +0 -0
|
@@ -11,6 +11,7 @@ import { concat, equals, uniqWith } from "ramda";
|
|
|
11
11
|
|
|
12
12
|
import { Assets } from ".";
|
|
13
13
|
import { Event } from "../enums";
|
|
14
|
+
import { Binding } from "../types";
|
|
14
15
|
|
|
15
16
|
const peprIgnoreLabel: V1LabelSelectorRequirement = {
|
|
16
17
|
key: "pepr.dev",
|
|
@@ -20,57 +21,41 @@ const peprIgnoreLabel: V1LabelSelectorRequirement = {
|
|
|
20
21
|
|
|
21
22
|
const peprIgnoreNamespaces: string[] = ["kube-system", "pepr-system"];
|
|
22
23
|
|
|
24
|
+
const validateRule = (binding: Binding, isMutateWebhook: boolean): V1RuleWithOperations | undefined => {
|
|
25
|
+
const { event, kind, isMutate, isValidate } = binding;
|
|
26
|
+
|
|
27
|
+
// Skip invalid bindings based on webhook type
|
|
28
|
+
if ((isMutateWebhook && !isMutate) || (!isMutateWebhook && !isValidate)) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Translate event to operations
|
|
33
|
+
const operations = event === Event.CREATE_OR_UPDATE ? [Event.CREATE, Event.UPDATE] : [event];
|
|
34
|
+
|
|
35
|
+
// Use the plural property if it exists, otherwise use lowercase kind + s
|
|
36
|
+
const resource = kind.plural || `${kind.kind.toLowerCase()}s`;
|
|
37
|
+
|
|
38
|
+
const ruleObject: V1RuleWithOperations = {
|
|
39
|
+
apiGroups: [kind.group],
|
|
40
|
+
apiVersions: [kind.version || "*"],
|
|
41
|
+
operations,
|
|
42
|
+
resources: [resource, ...(resource === "pods" ? ["pods/ephemeralcontainers"] : [])],
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
return ruleObject;
|
|
46
|
+
};
|
|
47
|
+
|
|
23
48
|
export async function generateWebhookRules(assets: Assets, isMutateWebhook: boolean): Promise<V1RuleWithOperations[]> {
|
|
24
49
|
const { config, capabilities } = assets;
|
|
25
|
-
const rules: V1RuleWithOperations[] = [];
|
|
26
50
|
|
|
27
|
-
|
|
28
|
-
for (const capability of capabilities) {
|
|
51
|
+
const rules = capabilities.flatMap(capability => {
|
|
29
52
|
console.info(`Module ${config.uuid} has capability: ${capability.name}`);
|
|
30
53
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
// If the module doesn't have a callback for the event, skip it
|
|
36
|
-
if (isMutateWebhook && !isMutate) {
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (!isMutateWebhook && !isValidate) {
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const operations: string[] = [];
|
|
45
|
-
|
|
46
|
-
// CreateOrUpdate is a Pepr-specific event that is translated to Create and Update
|
|
47
|
-
if (event === Event.CREATE_OR_UPDATE) {
|
|
48
|
-
operations.push(Event.CREATE, Event.UPDATE);
|
|
49
|
-
} else {
|
|
50
|
-
operations.push(event);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Use the plural property if it exists, otherwise use lowercase kind + s
|
|
54
|
-
const resource = kind.plural || `${kind.kind.toLowerCase()}s`;
|
|
55
|
-
|
|
56
|
-
const ruleObject = {
|
|
57
|
-
apiGroups: [kind.group],
|
|
58
|
-
apiVersions: [kind.version || "*"],
|
|
59
|
-
operations,
|
|
60
|
-
resources: [resource],
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
// If the resource is pods, add ephemeralcontainers as well
|
|
64
|
-
if (resource === "pods") {
|
|
65
|
-
ruleObject.resources.push("pods/ephemeralcontainers");
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Add the rule to the rules array
|
|
69
|
-
rules.push(ruleObject);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
54
|
+
return capability.bindings
|
|
55
|
+
.map(binding => validateRule(binding, isMutateWebhook))
|
|
56
|
+
.filter((rule): rule is V1RuleWithOperations => !!rule);
|
|
57
|
+
});
|
|
72
58
|
|
|
73
|
-
// Return the rules with duplicates removed
|
|
74
59
|
return uniqWith(equals, rules);
|
|
75
60
|
}
|
|
76
61
|
|
|
@@ -5,13 +5,13 @@ import express, { NextFunction } from "express";
|
|
|
5
5
|
import fs from "fs";
|
|
6
6
|
import https from "https";
|
|
7
7
|
|
|
8
|
-
import { Capability } from "../capability";
|
|
8
|
+
import { Capability } from "../core/capability";
|
|
9
9
|
import { MutateResponse, ValidateResponse } from "../k8s";
|
|
10
10
|
import Log from "../telemetry/logger";
|
|
11
11
|
import { metricsCollector, MetricsCollector } from "../telemetry/metrics";
|
|
12
|
-
import { ModuleConfig, isWatchMode } from "../module";
|
|
13
|
-
import { mutateProcessor } from "../mutate-processor";
|
|
14
|
-
import { validateProcessor } from "../validate-processor";
|
|
12
|
+
import { ModuleConfig, isWatchMode } from "../core/module";
|
|
13
|
+
import { mutateProcessor } from "../processors/mutate-processor";
|
|
14
|
+
import { validateProcessor } from "../processors/validate-processor";
|
|
15
15
|
import { StoreController } from "./store";
|
|
16
16
|
import { AdmissionRequest } from "../types";
|
|
17
17
|
import { karForMutate, karForValidate, KubeAdmissionReview } from "./index.util";
|
|
@@ -5,10 +5,10 @@ import { Operation } from "fast-json-patch";
|
|
|
5
5
|
import { K8s } from "kubernetes-fluent-client";
|
|
6
6
|
import { startsWith } from "ramda";
|
|
7
7
|
|
|
8
|
-
import { Capability } from "../capability";
|
|
8
|
+
import { Capability } from "../core/capability";
|
|
9
9
|
import { Store } from "../k8s";
|
|
10
10
|
import Log, { redactedPatch, redactedStore } from "../telemetry/logger";
|
|
11
|
-
import { DataOp, DataSender, DataStore, Storage } from "../storage";
|
|
11
|
+
import { DataOp, DataSender, DataStore, Storage } from "../core/storage";
|
|
12
12
|
import { fillStoreCache, sendUpdatesAndFlushCache } from "./storeCache";
|
|
13
13
|
|
|
14
14
|
const namespace = "pepr-system";
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import { DataOp } from "../storage";
|
|
1
|
+
import { DataOp } from "../core/storage";
|
|
2
2
|
import Log from "../telemetry/logger";
|
|
3
3
|
import { K8s } from "kubernetes-fluent-client";
|
|
4
4
|
import { Store } from "../k8s";
|
|
5
5
|
import { StatusCodes } from "http-status-codes";
|
|
6
6
|
import { Operation } from "fast-json-patch";
|
|
7
7
|
|
|
8
|
-
export const sendUpdatesAndFlushCache = async (
|
|
8
|
+
export const sendUpdatesAndFlushCache = async (
|
|
9
|
+
cache: Record<string, Operation>,
|
|
10
|
+
namespace: string,
|
|
11
|
+
name: string,
|
|
12
|
+
): Promise<Record<string, Operation>> => {
|
|
9
13
|
const indexes = Object.keys(cache);
|
|
10
14
|
const payload = Object.values(cache);
|
|
11
15
|
|
|
@@ -3,11 +3,11 @@
|
|
|
3
3
|
|
|
4
4
|
import { GenericClass, GroupVersionKind, modelToGroupVersionKind } from "kubernetes-fluent-client";
|
|
5
5
|
import { pickBy } from "ramda";
|
|
6
|
-
import Log from "
|
|
6
|
+
import Log from "../telemetry/logger";
|
|
7
7
|
import { isBuildMode, isDevMode, isWatchMode } from "./module";
|
|
8
8
|
import { PeprStore, Storage } from "./storage";
|
|
9
9
|
import { OnSchedule, Schedule } from "./schedule";
|
|
10
|
-
import { Event } from "
|
|
10
|
+
import { Event } from "../enums";
|
|
11
11
|
import {
|
|
12
12
|
Binding,
|
|
13
13
|
BindingFilter,
|
|
@@ -22,8 +22,8 @@ import {
|
|
|
22
22
|
FinalizeAction,
|
|
23
23
|
FinalizeActionChain,
|
|
24
24
|
WhenSelector,
|
|
25
|
-
} from "
|
|
26
|
-
import { addFinalizer } from "
|
|
25
|
+
} from "../types";
|
|
26
|
+
import { addFinalizer } from "../finalizer";
|
|
27
27
|
|
|
28
28
|
const registerAdmission = isBuildMode() || !isWatchMode();
|
|
29
29
|
const registerWatch = isBuildMode() || isWatchMode() || isDevMode();
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
|
|
3
3
|
import { clone } from "ramda";
|
|
4
4
|
import { Capability } from "./capability";
|
|
5
|
-
import { Controller } from "
|
|
6
|
-
import { ValidateError } from "
|
|
7
|
-
import { MutateResponse, ValidateResponse, WebhookIgnore } from "
|
|
8
|
-
import { CapabilityExport, AdmissionRequest } from "
|
|
9
|
-
import { setupWatch } from "
|
|
10
|
-
import { Log } from "
|
|
5
|
+
import { Controller } from "../controller";
|
|
6
|
+
import { ValidateError } from "../errors";
|
|
7
|
+
import { MutateResponse, ValidateResponse, WebhookIgnore } from "../k8s";
|
|
8
|
+
import { CapabilityExport, AdmissionRequest } from "../types";
|
|
9
|
+
import { setupWatch } from "../processors/watch-processor";
|
|
10
|
+
import { Log } from "../../lib";
|
|
11
11
|
import { V1PolicyRule as PolicyRule } from "@kubernetes/client-node";
|
|
12
12
|
|
|
13
13
|
/** Custom Labels Type for package.json */
|
|
@@ -58,12 +58,12 @@ export type PeprModuleOptions = {
|
|
|
58
58
|
};
|
|
59
59
|
|
|
60
60
|
// Track if this is a watch mode controller
|
|
61
|
-
export const isWatchMode = () => process.env.PEPR_WATCH_MODE === "true";
|
|
61
|
+
export const isWatchMode = (): boolean => process.env.PEPR_WATCH_MODE === "true";
|
|
62
62
|
|
|
63
63
|
// Track if Pepr is running in build mode
|
|
64
|
-
export const isBuildMode = () => process.env.PEPR_MODE === "build";
|
|
64
|
+
export const isBuildMode = (): boolean => process.env.PEPR_MODE === "build";
|
|
65
65
|
|
|
66
|
-
export const isDevMode = () => process.env.PEPR_MODE === "dev";
|
|
66
|
+
export const isDevMode = (): boolean => process.env.PEPR_MODE === "dev";
|
|
67
67
|
|
|
68
68
|
export class PeprModule {
|
|
69
69
|
#controller!: Controller;
|
|
@@ -135,7 +135,7 @@ export class PeprModule {
|
|
|
135
135
|
*
|
|
136
136
|
* @param port
|
|
137
137
|
*/
|
|
138
|
-
start = (port = 3000) => {
|
|
138
|
+
start = (port = 3000): void => {
|
|
139
139
|
this.#controller.startServer(port);
|
|
140
140
|
};
|
|
141
141
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { KubernetesObject } from "@kubernetes/client-node";
|
|
4
4
|
import { WatchPhase } from "kubernetes-fluent-client/dist/fluent/types";
|
|
5
5
|
import { randomBytes } from "node:crypto";
|
|
6
|
-
import Log from "
|
|
6
|
+
import Log from "../telemetry/logger";
|
|
7
7
|
|
|
8
8
|
type WatchCallback = (obj: KubernetesObject, phase: WatchPhase) => Promise<void>;
|
|
9
9
|
|
|
@@ -4,7 +4,7 @@ import { K8s, kind } from "kubernetes-fluent-client";
|
|
|
4
4
|
import Log from "./telemetry/logger";
|
|
5
5
|
|
|
6
6
|
// returns true if all deployments are ready, false otherwise
|
|
7
|
-
export async function checkDeploymentStatus(namespace: string) {
|
|
7
|
+
export async function checkDeploymentStatus(namespace: string): Promise<boolean> {
|
|
8
8
|
const deployments = await K8s(kind.Deployment).InNamespace(namespace).Get();
|
|
9
9
|
let status = false;
|
|
10
10
|
let readyCount = 0;
|
|
@@ -29,7 +29,7 @@ export async function checkDeploymentStatus(namespace: string) {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
// wait for all deployments in the pepr-system namespace to be ready
|
|
32
|
-
export async function namespaceDeploymentsReady(namespace: string = "pepr-system") {
|
|
32
|
+
export async function namespaceDeploymentsReady(namespace: string = "pepr-system"): Promise<true | undefined> {
|
|
33
33
|
Log.info(`Checking ${namespace} deployments status...`);
|
|
34
34
|
let ready = false;
|
|
35
35
|
while (!ready) {
|
package/src/lib/errors.ts
CHANGED
|
@@ -1,19 +1,14 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
audit: "audit",
|
|
6
|
-
ignore: "ignore",
|
|
7
|
-
reject: "reject",
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const ErrorList = Object.values(Errors);
|
|
4
|
+
import { OnError } from "../cli/init/enums";
|
|
11
5
|
|
|
6
|
+
export const ErrorList = Object.values(OnError) as string[];
|
|
12
7
|
/**
|
|
13
8
|
* Validate the error or throw an error
|
|
14
9
|
* @param error
|
|
15
10
|
*/
|
|
16
|
-
export function ValidateError(error = "") {
|
|
11
|
+
export function ValidateError(error: string = ""): void {
|
|
17
12
|
if (!ErrorList.includes(error)) {
|
|
18
13
|
throw new Error(`Invalid error: ${error}. Must be one of: ${ErrorList.join(", ")}`);
|
|
19
14
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
|
|
3
3
|
|
|
4
4
|
import { Event, Operation } from "../../enums";
|
|
5
|
-
import { AdmissionRequest, Binding } from "../../types";
|
|
5
|
+
import { AdmissionRequest, Binding, FinalizeAction, WatchLogAction, MutateAction, ValidateAction } from "../../types";
|
|
6
6
|
import {
|
|
7
7
|
__,
|
|
8
8
|
allPass,
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
nthArg,
|
|
20
20
|
pipe,
|
|
21
21
|
} from "ramda";
|
|
22
|
-
import { KubernetesObject } from "kubernetes-fluent-client";
|
|
22
|
+
import { GenericClass, KubernetesObject } from "kubernetes-fluent-client";
|
|
23
23
|
|
|
24
24
|
/*
|
|
25
25
|
Naming scheme:
|
|
@@ -77,6 +77,7 @@ export const carriedNamespace = pipe(
|
|
|
77
77
|
(kubernetesObject: KubernetesObject): string | undefined => kubernetesObject?.metadata?.namespace,
|
|
78
78
|
defaultTo(""),
|
|
79
79
|
);
|
|
80
|
+
|
|
80
81
|
export const carriesNamespace = pipe(carriedNamespace, equals(""), not);
|
|
81
82
|
|
|
82
83
|
export const carriedAnnotations = pipe(
|
|
@@ -144,7 +145,7 @@ export const definesVersion = pipe(definedVersion, equals(""), not);
|
|
|
144
145
|
export const definedKind = pipe((binding): string => binding?.kind?.kind, defaultTo(""));
|
|
145
146
|
export const definesKind = pipe(definedKind, equals(""), not);
|
|
146
147
|
|
|
147
|
-
export const definedCategory = (binding: Partial<Binding>) => {
|
|
148
|
+
export const definedCategory = (binding: Partial<Binding>): string => {
|
|
148
149
|
// Ordering matters, finalize is a "watch"
|
|
149
150
|
// prettier-ignore
|
|
150
151
|
return binding.isFinalize ? "Finalize" :
|
|
@@ -153,8 +154,15 @@ export const definedCategory = (binding: Partial<Binding>) => {
|
|
|
153
154
|
binding.isValidate ? "Validate" :
|
|
154
155
|
"";
|
|
155
156
|
};
|
|
156
|
-
|
|
157
|
-
|
|
157
|
+
export type DefinedCallbackReturnType =
|
|
158
|
+
| FinalizeAction<GenericClass, InstanceType<GenericClass>>
|
|
159
|
+
| WatchLogAction<GenericClass, InstanceType<GenericClass>>
|
|
160
|
+
| MutateAction<GenericClass, InstanceType<GenericClass>>
|
|
161
|
+
| ValidateAction<GenericClass, InstanceType<GenericClass>>
|
|
162
|
+
| null
|
|
163
|
+
| undefined;
|
|
164
|
+
|
|
165
|
+
export const definedCallback = (binding: Partial<Binding>): DefinedCallbackReturnType => {
|
|
158
166
|
// Ordering matters, finalize is a "watch"
|
|
159
167
|
// prettier-ignore
|
|
160
168
|
return binding.isFinalize ? binding.finalizeCallback :
|
|
@@ -241,10 +249,21 @@ export const mismatchedLabels = allPass([
|
|
|
241
249
|
pipe((binding, kubernetesObject) => metasMismatch(definedLabels(binding), carriedLabels(kubernetesObject))),
|
|
242
250
|
]);
|
|
243
251
|
|
|
252
|
+
/*
|
|
253
|
+
* If the object does not have a namespace, and it is not a namespace,
|
|
254
|
+
* then we must return false because it cannot be uncarryable
|
|
255
|
+
*/
|
|
244
256
|
export const uncarryableNamespace = allPass([
|
|
245
257
|
pipe(nthArg(0), length, gt(__, 0)),
|
|
246
|
-
pipe(
|
|
247
|
-
|
|
258
|
+
pipe((namespaceSelector, kubernetesObject) => {
|
|
259
|
+
if (kubernetesObject?.kind === "Namespace") {
|
|
260
|
+
return namespaceSelector.includes(kubernetesObject?.metadata?.name);
|
|
261
|
+
}
|
|
262
|
+
if (carriesNamespace(kubernetesObject)) {
|
|
263
|
+
return namespaceSelector.includes(carriedNamespace(kubernetesObject));
|
|
264
|
+
}
|
|
265
|
+
return true;
|
|
266
|
+
}, not),
|
|
248
267
|
]);
|
|
249
268
|
|
|
250
269
|
export const missingCarriableNamespace = allPass([
|
|
@@ -256,10 +275,22 @@ export const missingCarriableNamespace = allPass([
|
|
|
256
275
|
),
|
|
257
276
|
]);
|
|
258
277
|
|
|
278
|
+
/*
|
|
279
|
+
* If the object does not have a namespace, and it is not a namespace,
|
|
280
|
+
* then we must return false because it cannot be ignored
|
|
281
|
+
*/
|
|
259
282
|
export const carriesIgnoredNamespace = allPass([
|
|
260
283
|
pipe(nthArg(0), length, gt(__, 0)),
|
|
261
|
-
pipe(
|
|
262
|
-
|
|
284
|
+
pipe((namespaceSelector, kubernetesObject) => {
|
|
285
|
+
if (kubernetesObject?.kind === "Namespace") {
|
|
286
|
+
return namespaceSelector.includes(kubernetesObject?.metadata?.name);
|
|
287
|
+
}
|
|
288
|
+
if (carriesNamespace(kubernetesObject)) {
|
|
289
|
+
return namespaceSelector.includes(carriedNamespace(kubernetesObject));
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
return false;
|
|
293
|
+
}),
|
|
263
294
|
]);
|
|
264
295
|
|
|
265
296
|
export const unbindableNamespaces = allPass([
|