-
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.
Signed-off-by: Case Wylie <[email protected]>
- Loading branch information
Showing
6 changed files
with
111 additions
and
4 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,61 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors | ||
import { it, describe, expect } from "@jest/globals"; | ||
import { createWebhookYaml } from "./index"; | ||
import { kind } from "kubernetes-fluent-client"; | ||
|
||
describe("createWebhookYaml", () => { | ||
const webhookConfiguration = new kind.MutatingWebhookConfiguration(); | ||
webhookConfiguration.apiVersion = "admissionregistration.k8s.io/v1"; | ||
webhookConfiguration.kind = "MutatingWebhookConfiguration"; | ||
webhookConfiguration.metadata = { name: "pepr-static-test" }; | ||
webhookConfiguration.webhooks = [ | ||
{ | ||
name: "pepr-static-test.pepr.dev", | ||
admissionReviewVersions: ["v1", "v1beta1"], | ||
clientConfig: { | ||
caBundle: "", | ||
service: { | ||
name: "pepr-static-test", | ||
namespace: "pepr-system", | ||
path: "", | ||
}, | ||
}, | ||
failurePolicy: "Fail", | ||
matchPolicy: "Equivalent", | ||
timeoutSeconds: 15, | ||
namespaceSelector: { | ||
matchExpressions: [ | ||
{ | ||
key: "kubernetes.io/metadata.name", | ||
operator: "NotIn", | ||
values: ["kube-system", "pepr-system", "something"], | ||
}, | ||
], | ||
}, | ||
sideEffects: "None", | ||
}, | ||
]; | ||
|
||
const moduleConfig = { | ||
onError: "reject", | ||
webhookTimeout: 15, | ||
uuid: "some-uuid", | ||
alwaysIgnore: { | ||
namespaces: ["kube-system", "pepr-system"], | ||
}, | ||
}; | ||
|
||
it("replaces placeholders in the YAML correctly", () => { | ||
const result = createWebhookYaml("pepr-static-test", moduleConfig, webhookConfiguration); | ||
console.log(result); | ||
expect(result).toContain("{{ .Values.uuid }}"); | ||
expect(result).toContain("{{ .Values.admission.failurePolicy }}"); | ||
expect(result).toContain("{{ .Values.admission.webhookTimeout }}"); | ||
expect(result).toContain("- pepr-system"); | ||
expect(result).toContain("- kube-system"); | ||
expect(result).toContain("{{- range .Values.additionalIgnoredNamespaces }}"); | ||
expect(result).toContain("{{ . }}"); | ||
expect(result).toContain("{{- end }}"); | ||
}); | ||
}); |
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,22 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors | ||
import { it, describe, expect } from "@jest/globals"; | ||
import { resolveIgnoreNamespaces } from "./webhooks"; | ||
|
||
describe("resolveIgnoreNamespaces", () => { | ||
it("should default to empty array ig config is empty", () => { | ||
const result = resolveIgnoreNamespaces(); | ||
expect(result).toEqual([]); | ||
}); | ||
|
||
it("should return the config ignore namespaces if not provided PEPR_ADDITIONAL_IGNORED_NAMESPACES is not provided", () => { | ||
const result = resolveIgnoreNamespaces(["payments", "istio-system"]); | ||
expect(result).toEqual(["payments", "istio-system"]); | ||
}); | ||
|
||
it("should include additionalIgnoredNamespaces when PEPR_ADDITIONAL_IGNORED_NAMESPACES is provided", () => { | ||
process.env.PEPR_ADDITIONAL_IGNORED_NAMESPACES = "uds, project-fox"; | ||
const result = resolveIgnoreNamespaces(["zarf", "lula"]); | ||
expect(result).toEqual(["uds", "project-fox", "zarf", "lula"]); | ||
}); | ||
}); |
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
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