From d7b679b6eb4ecc0def3b3b42a7ef62a82d6dc1fd Mon Sep 17 00:00:00 2001 From: Sam Mayer Date: Tue, 14 Jan 2025 09:27:12 -0600 Subject: [PATCH 1/3] chore: add return types to loader.ts (#1648) ## Description In support of #1364, this PR adds typing to previously-untyped functions. End to End Test: (See [Pepr Excellent Examples](https://github.com/defenseunicorns/pepr-excellent-examples)) ## Related Issue Fixes # Relates to # ## 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 - [ ] 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 - [ ] [Contributor Guide Steps](https://docs.pepr.dev/main/contribute/#submitting-a-pull-request) followed --- src/fixtures/loader.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fixtures/loader.ts b/src/fixtures/loader.ts index 5ad3f3c37..a837dc9cf 100644 --- a/src/fixtures/loader.ts +++ b/src/fixtures/loader.ts @@ -6,11 +6,11 @@ import admissionRequestDeletePod from "./data/admission-delete-pod.json"; import admissionRequestCreateClusterRole from "./data/admission-create-clusterrole.json"; import admissionRequestCreateDeployment from "./data/admission-create-deployment.json"; -export function AdmissionRequestCreateDeployment() { +export function AdmissionRequestCreateDeployment(): AdmissionRequest { return cloneObject(admissionRequestCreateDeployment); } -export function AdmissionRequestCreatePod() { +export function AdmissionRequestCreatePod(): AdmissionRequest { return cloneObject(admissionRequestCreatePod); } From d9e4303aab48bb1ceb5f0a38724bbda68baff66c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 14 Jan 2025 16:02:03 +0000 Subject: [PATCH 2/3] chore: bump @types/node from 22.10.5 to 22.10.6 in the development-dependencies group (#1653) Bumps the development-dependencies group with 1 update: [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node). Updates `@types/node` from 22.10.5 to 22.10.6
Commits

Most Recent Ignore Conditions Applied to This Pull Request | Dependency Name | Ignore Conditions | | --- | --- | | @types/node | [>= 20.a, < 21] |
[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=@types/node&package-manager=npm_and_yarn&previous-version=22.10.5&new-version=22.10.6)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) ---
Dependabot commands and options
You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore major version` will close this group update PR and stop Dependabot creating any more for the specific dependency's major version (unless you unignore this specific dependency's major version or upgrade to it yourself) - `@dependabot ignore minor version` will close this group update PR and stop Dependabot creating any more for the specific dependency's minor version (unless you unignore this specific dependency's minor version or upgrade to it yourself) - `@dependabot ignore ` will close this group update PR and stop Dependabot creating any more for the specific dependency (unless you unignore this specific dependency or upgrade to it yourself) - `@dependabot unignore ` will remove all of the ignore conditions of the specified dependency - `@dependabot unignore ` will remove the ignore condition of the specified dependency and ignore conditions
Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sam Mayer --- package-lock.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 72ab3e8a7..bf5a2895a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2686,9 +2686,9 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "22.10.5", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.5.tgz", - "integrity": "sha512-F8Q+SeGimwOo86fiovQh8qiXfFEh2/ocYv7tU5pJ3EXMSSxk1Joj5wefpFK2fHTf/N6HKGSxIDBT9f3gCxXPkQ==", + "version": "22.10.6", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.6.tgz", + "integrity": "sha512-qNiuwC4ZDAUNcY47xgaSuS92cjf8JbSUoaKS77bmLG1rU7MlATVSiw/IlrjtIyyskXBZ8KkNfjK/P5na7rgXbQ==", "dependencies": { "undici-types": "~6.20.0" } From a4a942ff5ec59fcf98fecc13fdb11f8a6d7f00ad Mon Sep 17 00:00:00 2001 From: Sam Mayer Date: Tue, 14 Jan 2025 11:51:57 -0600 Subject: [PATCH 3/3] chore: remove unused property in assets class (#1647) ## Description This PR removes the `Assets.hash` property and calculates the hash of a pepr module _just_ before we need to provide that value to a consuming function. This will avoid potential issues with state and removes some dead code. End to End Test: (See [Pepr Excellent Examples](https://github.com/defenseunicorns/pepr-excellent-examples)) ## Related Issue Fixes #1638 ## Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Other (security config, docs update, etc) ## Checklist before merging - [ ] 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 - [ ] [Contributor Guide Steps](https://docs.pepr.dev/main/contribute/#submitting-a-pull-request) followed Co-authored-by: Barrett <81570928+btlghrants@users.noreply.github.com> --- src/lib/assets/assets.ts | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/lib/assets/assets.ts b/src/lib/assets/assets.ts index ee84354db..08f39b0f2 100644 --- a/src/lib/assets/assets.ts +++ b/src/lib/assets/assets.ts @@ -33,7 +33,6 @@ export class Assets { image: string; buildTimestamp: string; - hash: string; constructor( readonly config: ModuleConfig, @@ -44,7 +43,6 @@ export class Assets { this.buildTimestamp = `${Date.now()}`; this.alwaysIgnore = config.alwaysIgnore; this.image = `ghcr.io/defenseunicorns/pepr/controller:v${config.peprVersion}`; - this.hash = ""; // Generate the ephemeral tls things this.tls = genTLS(this.host || `${this.name}.pepr-system.svc`); @@ -52,10 +50,6 @@ export class Assets { this.apiToken = crypto.randomBytes(32).toString("hex"); } - setHash = (hash: string): void => { - this.hash = hash; - }; - deploy = async (force: boolean, webhookTimeout?: number): Promise => { this.capabilities = await loadCapabilities(this.path); await deploy(this, force, webhookTimeout); @@ -79,19 +73,18 @@ export class Assets { const code = await fs.readFile(this.path); - // Generate a hash of the code - this.hash = crypto.createHash("sha256").update(code).digest("hex"); + const moduleHash = crypto.createHash("sha256").update(code).digest("hex"); const deployments = { - default: getDeployment(this, this.hash, this.buildTimestamp, imagePullSecret), - watch: getWatcher(this, this.hash, this.buildTimestamp, imagePullSecret), + default: getDeployment(this, moduleHash, this.buildTimestamp, imagePullSecret), + watch: getWatcher(this, moduleHash, this.buildTimestamp, imagePullSecret), }; const assetsInputs = { apiToken: this.apiToken, capabilities: this.capabilities, config: this.config, - hash: this.hash, + hash: moduleHash, name: this.name, path: this.path, tls: this.tls, @@ -129,6 +122,7 @@ export class Assets { ); const code = await fs.readFile(this.path); + const moduleHash = crypto.createHash("sha256").update(code).digest("hex"); const pairs: [string, () => string][] = [ [helm.files.chartYaml, (): string => dedent(chartYaml(this.config.uuid, this.config.description || ""))], @@ -142,12 +136,12 @@ export class Assets { [helm.files.clusterRoleYaml, (): string => dedent(clusterRoleTemplate())], [helm.files.clusterRoleBindingYaml, (): string => toYaml(clusterRoleBinding(this.name))], [helm.files.serviceAccountYaml, (): string => toYaml(serviceAccount(this.name))], - [helm.files.moduleSecretYaml, (): string => toYaml(getModuleSecret(this.name, code, this.hash))], + [helm.files.moduleSecretYaml, (): string => toYaml(getModuleSecret(this.name, code, moduleHash))], ]; await Promise.all(pairs.map(async ([file, content]) => await fs.writeFile(file, content()))); const overrideData = { - hash: this.hash, + hash: moduleHash, name: this.name, image: this.image, config: this.config, @@ -163,7 +157,7 @@ export class Assets { await this.writeWebhookFiles(validateWebhook, mutateWebhook, helm); - const watchDeployment = getWatcher(this, this.hash, this.buildTimestamp); + const watchDeployment = getWatcher(this, moduleHash, this.buildTimestamp); if (watchDeployment) { await fs.writeFile(helm.files.watcherDeploymentYaml, dedent(watcherDeployTemplate(this.buildTimestamp))); await fs.writeFile(helm.files.watcherServiceMonitorYaml, dedent(serviceMonitorTemplate("watcher")));