Skip to content

Commit

Permalink
Merge branch 'main' into 1327
Browse files Browse the repository at this point in the history
  • Loading branch information
cmwylie19 authored Oct 31, 2024
2 parents 0199864 + 12b3613 commit 7f1a026
Show file tree
Hide file tree
Showing 22 changed files with 58 additions and 99 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/dependency-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# This Action will scan dependency manifest files that change as part of a Pull Request,
# surfacing known-vulnerable versions of the packages declared or updated in the PR.
# Once installed, if the workflow run is marked as required,
# Once installed, if the workflow run is marked as required,
# PRs introducing known-vulnerable packages will be blocked from merging.
#
# Source repository: https://github.com/actions/dependency-review-action
Expand Down Expand Up @@ -35,11 +35,11 @@ jobs:
run: |
npx madge --circular --ts-config tsconfig.json --extensions ts,js src/ > tmp.log || true # Force exit 0 for post-processing
tail -n +4 tmp.log > circular-deps.log
if [ $(wc -l < circular-deps.log) -gt 17 ]; then
echo "circular-deps.log has more than 17 circular dependencies."
if [ $(wc -l < circular-deps.log) -gt 11 ]; then
echo "circular-deps.log has more than 11 circular dependencies."
wc -l circular-deps.log
exit 1
else
echo "circular-deps.log has 17 or fewer circular dependencies."
echo "circular-deps.log has 11 or fewer circular dependencies."
exit 0
fi
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/lib/assets/rbac.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CapabilityExport } from "../types";
import { it, describe, expect, beforeEach, jest } from "@jest/globals";
import { GenericClass } from "kubernetes-fluent-client";
import { V1PolicyRule as PolicyRule } from "@kubernetes/client-node";
import { Event } from "../types";
import { Event } from "../enums";
import fs from "fs";
import * as helpers from "../helpers";

Expand Down
2 changes: 1 addition & 1 deletion src/lib/assets/webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { kind } from "kubernetes-fluent-client";
import { concat, equals, uniqWith } from "ramda";

import { Assets } from ".";
import { Event } from "../types";
import { Event } from "../enums";

const peprIgnoreLabel: V1LabelSelectorRequirement = {
key: "pepr.dev",
Expand Down
3 changes: 1 addition & 2 deletions src/lib/capability.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import { CapabilityCfg, FinalizeAction, MutateAction, ValidateAction, WatchLogAc
import { a } from "../lib";
import { V1Pod } from "@kubernetes/client-node";
import { expect, describe, jest, beforeEach, it } from "@jest/globals";
import { Operation } from "./mutate-types";
import { Event, Operation } from "./enums";
import { PeprMutateRequest } from "./mutate-request";
import { PeprValidateRequest } from "./validate-request";
import { AdmissionRequest } from "./types";
import { WatchPhase } from "kubernetes-fluent-client/dist/fluent/types";
import { Event } from "./types";
import { GenericClass } from "kubernetes-fluent-client";
import { Schedule } from "./schedule";
import { OnSchedule } from "./schedule";
Expand Down
3 changes: 2 additions & 1 deletion src/lib/capability.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable max-statements */
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors

Expand All @@ -7,13 +8,13 @@ import Log from "./logger";
import { isBuildMode, isDevMode, isWatchMode } from "./module";
import { PeprStore, Storage } from "./storage";
import { OnSchedule, Schedule } from "./schedule";
import { Event } from "./enums";
import {
Binding,
BindingFilter,
BindingWithName,
CapabilityCfg,
CapabilityExport,
Event,
MutateAction,
MutateActionChain,
ValidateAction,
Expand Down
21 changes: 21 additions & 0 deletions src/lib/enums.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors

// Operation type for mutation operations
export enum Operation {
CREATE = "CREATE",
UPDATE = "UPDATE",
DELETE = "DELETE",
CONNECT = "CONNECT",
}

/**
* The type of Kubernetes mutating webhook event that the action is registered for.
*/
export enum Event {
Create = "CREATE",
Update = "UPDATE",
Delete = "DELETE",
CreateOrUpdate = "CREATEORUPDATE",
Any = "*",
}
4 changes: 2 additions & 2 deletions src/lib/filter/adjudicators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import { expect, describe, it } from "@jest/globals";
import * as sut from "./adjudicators";
import { KubernetesObject } from "kubernetes-fluent-client";
import { AdmissionRequest, Binding, Event } from "../types";
import { DeepPartial, Operation } from "../mutate-types";
import { AdmissionRequest, Binding, DeepPartial } from "../types";
import { Event, Operation } from "../enums";

describe("definesDeletionTimestamp", () => {
//[ Binding, result ]
Expand Down
3 changes: 1 addition & 2 deletions src/lib/filter/adjudicators.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors

import { Event } from "../types";
import { Operation } from "../mutate-types";
import { Event, Operation } from "../enums";
import {
__,
allPass,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/filter/filtersWithLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
mismatchedVersion,
uncarryableNamespace,
} from "./adjudicators";
import { Operation } from "../mutate-types";
import { Operation } from "../enums";
import { FilterInput, FilterParams } from "../types";
import { commonLogMessage } from "./logMessages";

Expand Down
3 changes: 2 additions & 1 deletion src/lib/filter/shouldSkipRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { kind, modelToGroupVersionKind } from "kubernetes-fluent-client";
import * as fc from "fast-check";
import { CreatePod, DeletePod } from "../../fixtures/loader";
import { shouldSkipRequest } from "./shouldSkipRequest";
import { AdmissionRequest, Binding, Event } from "../types";
import { AdmissionRequest, Binding } from "../types";
import { Event } from "../enums";

export const callback = () => undefined;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/finalizer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { addFinalizer, removeFinalizer } from "./finalizer";
import { KubernetesObject, K8s, GenericClass, RegisterKind } from "kubernetes-fluent-client";
import { K8sInit } from "kubernetes-fluent-client/dist/fluent/types";
import { AdmissionRequest } from "./types";
import { Operation } from "./mutate-types";
import { Operation } from "./enums";
import { PeprMutateRequest } from "./mutate-request";
import { Binding } from "./types";

Expand Down
4 changes: 2 additions & 2 deletions src/lib/finalizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

import { K8s, KubernetesObject, RegisterKind } from "kubernetes-fluent-client";
import Log from "./logger";
import { Binding } from "./types";
import { Operation, DeepPartial } from "./mutate-types";
import { Binding, DeepPartial } from "./types";
import { Operation } from "./enums";
import { PeprMutateRequest } from "./mutate-request";

export function addFinalizer<K extends KubernetesObject>(request: PeprMutateRequest<K>) {
Expand Down
3 changes: 2 additions & 1 deletion src/lib/helpers.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors

import { Binding, CapabilityExport, Event } from "./types";
import { Binding, CapabilityExport } from "./types";
import { Event } from "./enums";
import {
addVerbIfNotExists,
bindingAndCapabilityNSConflict,
Expand Down
2 changes: 1 addition & 1 deletion src/lib/mutate-request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { beforeEach, describe, expect, it } from "@jest/globals";
import { KubernetesObject } from "kubernetes-fluent-client";
import { AdmissionRequest } from "./types";
import { Operation } from "./mutate-types";
import { Operation } from "./enums";
import { PeprMutateRequest } from "./mutate-request";

describe("PeprMutateRequest", () => {
Expand Down
11 changes: 2 additions & 9 deletions src/lib/mutate-request.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors

import { Operation, AdmissionRequest, DeepPartial } from "./mutate-types";
import { AdmissionRequest, DeepPartial } from "./types";
import { Operation } from "./enums";
import { KubernetesObject } from "kubernetes-fluent-client";
import { clone, mergeDeepRight } from "ramda";
import { Logger } from "pino";
import { GenericClass } from "kubernetes-fluent-client";

// MutateAction type for handling mutation callbacks
export type MutateAction<T extends GenericClass, K extends KubernetesObject = InstanceType<T>> = (
req: PeprMutateRequest<K>,
logger?: Logger,
) => Promise<void> | void | Promise<PeprMutateRequest<K>> | PeprMutateRequest<K>;

// PeprMutateRequest class for mutation request handling
export class PeprMutateRequest<T extends KubernetesObject> {
Expand Down
50 changes: 0 additions & 50 deletions src/lib/mutate-types.ts

This file was deleted.

18 changes: 6 additions & 12 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors

import { GenericClass, GroupVersionKind, KubernetesObject } from "kubernetes-fluent-client";
import { Operation } from "./mutate-types";
import { Event, Operation } from "./enums";
import { WatchPhase } from "kubernetes-fluent-client/dist/fluent/types";
import { Logger } from "pino";
import { PeprMutateRequest } from "./mutate-request";
Expand Down Expand Up @@ -34,17 +34,6 @@ export interface ResponseItem {
};
}

/**
* The type of Kubernetes mutating webhook event that the action is registered for.
*/
export enum Event {
Create = "CREATE",
Update = "UPDATE",
Delete = "DELETE",
CreateOrUpdate = "CREATEORUPDATE",
Any = "*",
}

export interface CapabilityCfg {
/**
* The name of the capability. This should be unique.
Expand Down Expand Up @@ -370,3 +359,8 @@ export type FilterParams = {
};

export type FilterInput = Binding | KubernetesObject | AdmissionRequest | string[] | undefined;

// DeepPartial utility type for deep optional properties
export type DeepPartial<T> = {
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
};
2 changes: 1 addition & 1 deletion src/lib/validate-request.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { beforeEach, describe, expect, it } from "@jest/globals";
import { KubernetesObject } from "kubernetes-fluent-client";
import { ValidateActionResponse, AdmissionRequest } from "./types";
import { Operation } from "./mutate-types";
import { Operation } from "./enums";
import { PeprValidateRequest } from "./validate-request";
describe("PeprValidateRequest", () => {
let mockRequest: AdmissionRequest<KubernetesObject>;
Expand Down
2 changes: 1 addition & 1 deletion src/lib/validate-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { KubernetesObject } from "kubernetes-fluent-client";
import { clone } from "ramda";
import { AdmissionRequest } from "./types";
import { ValidateActionResponse } from "./types";
import { Operation } from "./mutate-types";
import { Operation } from "./enums";

/**
* The RequestWrapper class provides methods to modify Kubernetes objects in the context
Expand Down
3 changes: 2 additions & 1 deletion src/lib/watch-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import { filterNoMatchReason } from "./helpers";
import { removeFinalizer } from "./finalizer";
import Log from "./logger";
import { Queue } from "./queue";
import { Binding, Event } from "./types";
import { Binding } from "./types";
import { Event } from "./enums";
import { metricsCollector } from "./metrics";

// stores Queue instances
Expand Down
3 changes: 1 addition & 2 deletions src/sdk/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import { PeprValidateRequest } from "../lib/validate-request";
import { PeprMutateRequest } from "../lib/mutate-request";
import { a } from "../lib";
import { V1OwnerReference } from "@kubernetes/client-node";
import { GenericKind } from "kubernetes-fluent-client";
import { K8s, kind } from "kubernetes-fluent-client";
Expand All @@ -16,7 +15,7 @@ import Log from "../lib/logger";
* @returns the list of containers in the pod
*/
export function containers(
request: PeprValidateRequest<a.Pod> | PeprMutateRequest<a.Pod>,
request: PeprValidateRequest<kind.Pod> | PeprMutateRequest<kind.Pod>,
containerType?: "containers" | "initContainers" | "ephemeralContainers",
) {
const containers = request.Raw.spec?.containers || [];
Expand Down

0 comments on commit 7f1a026

Please sign in to comment.