-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: additionalIgnoredNamespaces at runtime through helm (#1641)
## Description This feature: - [x] Adds additionalIgnoredNamespaces to values.yaml - [x] Sets additionalIgnoredNamespaces in controller container envs as `PEPR_ADDITIONAL_IGNORED_NAMESPACES` - [x] reads `PEPR_ADDITIONAL_IGNORED_NAMESPACES` env and adds namespaces to ignoredNamespaces - [x] Does **not** document PEPR_ADDITIONAL_IGNORED_NAMESPACES as feature is meant to be set through helm chart and not by hand, By hand you should set them in `package.json` In action: `package.json` ```json "alwaysIgnore": { "namespaces": ["something"] }, ``` `values.yaml` ```yaml additionalIgnoredNamespaces: - 'kube-system' - 'kube-public' - 'kube-node-lease' - 'default' - 'pepr' - 'pepr-system' - 'pepr-test-module' ``` `> helm template .` `controllers` ```yaml - name: PEPR__ADDITIONAL_IGNORED_NAMESPACES value: "kube-system, kube-public, kube-node-lease, default, pepr, pepr-system, pepr-test-module" ``` `webhook configs` ```yaml namespaceSelector: matchExpressions: - key: kubernetes.io/metadata.name operator: NotIn values: - kube-system - pepr-system - kube-system - kube-public - kube-node-lease - default - pepr - pepr-system - pepr-test-module - something ``` ## Related Issue Fixes #1610 #1617 <!-- or --> Relates to # ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] 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 --------- Signed-off-by: Case Wylie <[email protected]>
- Loading branch information
Showing
10 changed files
with
162 additions
and
14 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
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
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
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,30 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors | ||
import { it, describe, expect } from "@jest/globals"; | ||
import { resolveIgnoreNamespaces, peprIgnoreNamespaces } from "./webhooks"; | ||
|
||
describe("peprIgnoreNamespaces", () => { | ||
it("should have order of kube-system, then pepr-system for the helm templating", () => { | ||
expect(peprIgnoreNamespaces).toEqual(["kube-system", "pepr-system"]); | ||
expect(peprIgnoreNamespaces[0]).toEqual("kube-system"); | ||
expect(peprIgnoreNamespaces[1]).toEqual("pepr-system"); | ||
}); | ||
}); | ||
|
||
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
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