Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

Commit

Permalink
Move Zarf constants to constants.ts file
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Rodriguez committed Dec 8, 2023
1 parent 7a05b5c commit e16618a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 22 deletions.
11 changes: 6 additions & 5 deletions capabilities/ecr-webhook/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
DeployedComponent,
DeployedPackage,
} from "../../zarf-types";
import { zarfNamespace } from "../../lib/constants";

/**
* Represents a component check result, indicating whether a component is ready for a webhook to execute.
Expand Down Expand Up @@ -183,11 +184,11 @@ export async function updateWebhookStatus(
webhookName: string,
status: string,
): Promise<void> {
const ns = "zarf";

try {
// Fetch the package secret
const secret = await K8s(kind.Secret).InNamespace(ns).Get(secretName);
const secret = await K8s(kind.Secret)
.InNamespace(zarfNamespace)
.Get(secretName);

if (secret.data === undefined) {
throw new Error(
Expand All @@ -211,7 +212,7 @@ export async function updateWebhookStatus(
{
metadata: {
name: secretName,
namespace: ns,
namespace: zarfNamespace,
},
data: {
data: secret.data.data,
Expand All @@ -221,7 +222,7 @@ export async function updateWebhookStatus(
);
} catch (err) {
throw new Error(
`unable to update webhook status for package secret '${secretName}' in namespace '${ns}': ${JSON.stringify(
`unable to update webhook status for package secret '${secretName}' in namespace '${zarfNamespace}': ${JSON.stringify(
err,
)}`,
);
Expand Down
5 changes: 3 additions & 2 deletions capabilities/ecr-webhook/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@ import {
createReposAndUpdateStatus,
componentReadyForWebhook,
} from "./lib/utils";
import { zarfNamespace } from "../lib/constants";

/**
* The ECR Capability creates ECR repositories for a Zarf managed ECR registry
*/
export const ECRhook = new Capability({
name: "ecr",
description: "Create ECR repositories for a Zarf managed ECR registry",
namespaces: ["pepr-system", "zarf"],
namespaces: ["pepr-system", zarfNamespace],
});

const { When } = ECRhook;

When(a.Secret)
.IsCreatedOrUpdated()
.InNamespace("zarf")
.InNamespace(zarfNamespace)
.WithLabel("package-deploy-info")
.Mutate(async request => {
const result = await isECRregistry();
Expand Down
5 changes: 5 additions & 0 deletions capabilities/lib/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const zarfNamespace = "zarf";
export const zarfStateSecret = "zarf-state";
export const zarfImagePullSecret = "private-registry";
export const zarfAgentLabel = "zarf.dev/agent";
export const zarfManagedByLabel = "app.kubernetes.io/managed-by";
13 changes: 7 additions & 6 deletions capabilities/lib/zarf.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { ZarfState } from "../zarf-types";
import { K8s, kind, Log } from "pepr";

const zarfNamespace = "zarf";
const zarfStateSecret = "zarf-state";
const zarfImagePullSecret = "private-registry";
const zarfAgentLabel = "zarf.dev/agent";
const zarfManagedByLabel = "app.kubernetes.io/managed-by";
import {
zarfNamespace,
zarfStateSecret,
zarfImagePullSecret,
zarfManagedByLabel,
zarfAgentLabel,
} from "./constants";

export async function getZarfRegistryURL(): Promise<string> {
try {
Expand Down
18 changes: 9 additions & 9 deletions manifests/pepr-module-b95dbd80-e078-5eb9-aaf3-bcb9567417d0.yaml

Large diffs are not rendered by default.

0 comments on commit e16618a

Please sign in to comment.