Skip to content
Merged
Show file tree
Hide file tree
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
15 changes: 15 additions & 0 deletions .github/workflows/tts-audio-ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ jobs:
- name: Checkout Repository
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7

# Required to build the arm64 half of the published manifest on an amd64 runner.
- name: Set up QEMU
uses: docker/setup-qemu-action@v3.6.0

- name: Set up Buildx
uses: docker/setup-buildx-action@v4.4.1
with:
Expand Down Expand Up @@ -120,6 +124,14 @@ jobs:
with:
context: deploy/tts-audio/worker
file: deploy/tts-audio/worker/Dockerfile
# The local cluster mixes architectures: the amd64 k3s worker runs these pods
# today, but the control-plane node is arm64 and only cordoned, so a pod could
# land there and fail with ImagePullBackOff against an amd64-only manifest.
#
# That is the *push* step below. This one still builds amd64 only, because
# `load: true` cannot take a multi-platform build and the smoke test runs on the
# amd64 runner.
platforms: linux/amd64
load: true
tags: |
${{ env.IMAGE }}:${{ steps.meta.outputs.tag }}
Expand Down Expand Up @@ -163,6 +175,9 @@ jobs:
context: deploy/tts-audio/worker
file: deploy/tts-audio/worker/Dockerfile
push: true
# Both architectures the cluster has. arm64 is emulated via QEMU on the amd64
# runner, which only affects build time, not the result.
platforms: linux/amd64,linux/arm64
tags: |
${{ env.IMAGE }}:${{ steps.meta.outputs.tag }}
${{ env.IMAGE }}:main
Expand Down
21 changes: 17 additions & 4 deletions deploy/tts-audio/base/netpol.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,28 @@ spec:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: allow-webhook-kubernetes-api
name: allow-kubernetes-api-egress
namespace: tts-audio
labels:
app.kubernetes.io/name: tts-audio
spec:
# Both workloads that *create* Jobs need API access: the receiver on every webhook, and
# the backfill once per post it queues. This used to select only `component=webhook`, so
# the backfill authenticated to Ghost, listed all 221 posts, and then failed to create a
# single Job with `connect ECONNREFUSED <apiserver>:443`.
#
# The worker is deliberately excluded even though it shares `name=tts-audio`: it runs
# with `automountServiceAccountToken: false` and has no business reaching the API server,
# so widening the selector to the shared label would quietly grant it egress it does not
# need. Two selectors, one per component that actually needs it.
podSelector:
matchLabels:
app.kubernetes.io/name: tts-audio
app.kubernetes.io/component: webhook
matchExpressions:
- key: app.kubernetes.io/name
operator: In
values: ["tts-audio"]
- key: app.kubernetes.io/component
operator: In
values: ["webhook", "backfill"]
policyTypes:
- Egress
egress:
Expand Down
17 changes: 14 additions & 3 deletions deploy/tts-audio/worker/src/backfill.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,15 @@ export async function planPost(config, post, { fetchImpl = fetch } = {}) {
* production, because it says how many posts and how many minutes of CPU a full
* backfill is about to cost.
*/
export async function backfill({ config, log = () => {}, fetchImpl = fetch, dryRun = process.env.DRY_RUN === "1" }) {
export async function backfill({
config,
log = () => {},
fetchImpl = fetch,
dryRun = process.env.DRY_RUN === "1",
// Injectable so a test can drive the "the API server is unreachable" path, which is
// exactly what a NetworkPolicy blocking the backfill looks like.
createJob = createPostJob,
}) {
let page = 1;
let pages = 1;
const totals = { scanned: 0, eligible: 0, created: 0, skipped: 0, ineligible: 0, failed: 0 };
Expand Down Expand Up @@ -137,7 +145,7 @@ export async function backfill({ config, log = () => {}, fetchImpl = fetch, dryR
totals.created += 1;
continue;
}
const result = await createPostJob(config, { postId: post.id, hash: plan.hash });
const result = await createJob(config, { postId: post.id, hash: plan.hash });
// `exists` is a success: a previous run already queued this exact article.
if (result === "exists") {
totals.skipped += 1;
Expand All @@ -153,6 +161,9 @@ export async function backfill({ config, log = () => {}, fetchImpl = fetch, dryR
page += 1;
} while (page <= pages);

log(JSON.stringify({ result: dryRun ? "dry-run" : "ok", ...totals }));
// The exit code already reflected failures, but the line said "ok" — so a run that
// queued nothing out of 221 posts finished as `{"result":"ok","failed":221}`.
const result = dryRun ? "dry-run" : totals.failed > 0 ? "failed" : "ok";
log(JSON.stringify({ result, ...totals }));
return totals.failed > 0 ? 1 : 0;
}
31 changes: 31 additions & 0 deletions deploy/tts-audio/worker/test/ghost.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -368,3 +368,34 @@ test("the backfill listing names the failing key on INVALID_JWT", async () => {
// And the run ends with a structured line rather than an escaping exception.
assert.match(joined, /"result":"failed"/);
});

test("a backfill whose Jobs cannot be created reports failed, not ok", async () => {
// Observed in the cluster: 221 posts read fine, then every Job creation failed with
// `connect ECONNREFUSED <apiserver>:443` (a NetworkPolicy blocking the backfill). The
// run logged {"result":"ok","failed":221} and exited 1 — the pod was right, the summary
// line was not.
const { backfill } = await import("../src/backfill.mjs");
const listOk = {
ok: true,
status: 200,
json: async () => ({
posts: [{ id: "p1", slug: "s1", tags: [{ name: "Español", slug: "es" }], html: "<p>Hola.</p>" }],
meta: { pagination: { page: 1, pages: 1 } },
}),
};
const lines = [];
const code = await backfill({
config,
log: (line) => lines.push(line),
fetchImpl: async () => listOk,
createJob: async () => {
throw new Error("connect ECONNREFUSED 10.43.0.1:443");
},
});

assert.equal(code, 1, "a run that created nothing must exit non-zero");
const summary = JSON.parse(lines.at(-1));
assert.equal(summary.result, "failed");
assert.equal(summary.failed, 1);
assert.equal(summary.created, 0);
});
Loading