Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove unused property in assets class #1647

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions src/lib/assets/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export class Assets {

image: string;
buildTimestamp: string;
hash: string;

constructor(
readonly config: ModuleConfig,
Expand All @@ -44,18 +43,13 @@ 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`);

// Generate the api token for the controller / webhook
this.apiToken = crypto.randomBytes(32).toString("hex");
}

setHash = (hash: string): void => {
this.hash = hash;
};

deploy = async (force: boolean, webhookTimeout?: number): Promise<void> => {
this.capabilities = await loadCapabilities(this.path);
await deploy(this, force, webhookTimeout);
Expand All @@ -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,
Expand Down Expand Up @@ -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 || ""))],
Expand All @@ -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,
Expand All @@ -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")));
Expand Down
Loading