Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

docs(hcc): land cheap #486 review nits (#472)

Alfredo Lopez35f304c102f3
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.json
index 6bf7bdca1..0b28c1870 100644
--- a/host-context-controller/package-lock.json
+++ b/host-context-controller/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-host-context-controller",
- "version": "0.1.258",
+ "version": "0.1.259",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-host-context-controller",
- "version": "0.1.258",
+ "version": "0.1.259",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@clerum/image-policy": "file:../packages/image-policy",
diff --git a/host-context-controller/package.json b/host-context-controller/package.json
index e041cde2c..e07c3453f 100644
--- a/host-context-controller/package.json
+++ b/host-context-controller/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-host-context-controller",
- "version": "0.1.258",
+ "version": "0.1.259",
"description": "Host Context Controller - provides McpServer CRDs to mcp-host via REST API",
"main": "dist/main.js",
"engines": {
diff --git a/host-context-controller/src/__tests__/applyNetworkPolicyNoopGate.test.ts b/host-context-controller/src/__tests__/applyNetworkPolicyNoopGate.test.ts
index 6c4b5574b..f55690950 100644
--- a/host-context-controller/src/__tests__/applyNetworkPolicyNoopGate.test.ts
+++ b/host-context-controller/src/__tests__/applyNetworkPolicyNoopGate.test.ts
@@ -1,8 +1,13 @@
import { describe, expect, it, vi } from 'vitest'
+import { ApiException } from '@kubernetes/client-node'
import type * as k8s from '@kubernetes/client-node'
import { applyNetworkPolicy, networkPolicyMatchesDesired } from '../utils'
import { asApiserverNetworkPolicy, updatedPolicyLogs } from './asApiserverNetworkPolicy'
+function apiException(code: number): ApiException<unknown> {
+ return new ApiException(code, 'test', {}, {})
+}
+
function desiredPolicy(): k8s.V1NetworkPolicy {
return {
apiVersion: 'networking.k8s.io/v1',
@@ -99,7 +104,7 @@ describe('applyNetworkPolicy no-op gate', () => {
})
it.each([
- { form: 'code', error: { code: 404 } },
+ { form: 'ApiException', error: apiException(404) },
{ form: 'statusCode', error: { response: { statusCode: 404 } } },
])('TOCTOU-NP-1: create 409 + read 404 ($form) returns without replace', async ({ error }) => {
const api = fakeNetworkingApi()
@@ -116,11 +121,11 @@ describe('applyNetworkPolicy no-op gate', () => {
})
it.each([
- { status: 403, form: 'code', error: { code: 403 } },
+ { status: 403, form: 'ApiException', error: apiException(403) },
{ status: 403, form: 'statusCode', error: { response: { statusCode: 403 } } },
- { status: 500, form: 'code', error: { code: 500 } },
+ { status: 500, form: 'ApiException', error: apiException(500) },
{ status: 500, form: 'statusCode', error: { response: { statusCode: 500 } } },
- ])('TOCTOU-NP-2: create 409 + read $status ($form) still throws', async ({ error }) => {
+ ])('TOCTOU-NP-2-APPLY: create 409 + read $status ($form) still throws', async ({ error }) => {
const api = fakeNetworkingApi()
api.createNamespacedNetworkPolicy.mockRejectedValue({ code: 409 })
api.readNamespacedNetworkPolicy.mockRejectedValue(error)
diff --git a/host-context-controller/src/__tests__/replaceWithConflictRetryOrder.test.ts b/host-context-controller/src/__tests__/replaceWithConflictRetryOrder.test.ts
index e0147ac83..ab838428a 100644
--- a/host-context-controller/src/__tests__/replaceWithConflictRetryOrder.test.ts
+++ b/host-context-controller/src/__tests__/replaceWithConflictRetryOrder.test.ts
@@ -1,4 +1,5 @@
import { describe, expect, it, vi } from 'vitest'
+import { ApiException } from '@kubernetes/client-node'
import type * as k8s from '@kubernetes/client-node'
import {
preserveServiceAssignedFields,
@@ -6,6 +7,10 @@ import {
serviceMatchesDesired,
} from '../utils'
+function apiException(code: number): ApiException<unknown> {
+ return new ApiException(code, 'test', {}, {})
+}
+
const desired: k8s.V1Service = {
apiVersion: 'v1',
kind: 'Service',
@@ -95,9 +100,9 @@ describe('replaceWithConflictRetry order and retry', () => {
})
it.each([
- { status: 403, form: 'code', error: { code: 403 } },
+ { status: 403, form: 'ApiException', error: apiException(403) },
{ status: 403, form: 'statusCode', error: { response: { statusCode: 403 } } },
- { status: 500, form: 'code', error: { code: 500 } },
+ { status: 500, form: 'ApiException', error: apiException(500) },
{ status: 500, form: 'statusCode', error: { response: { statusCode: 500 } } },
])('TOCTOU-NP-2: helper read $status ($form) still throws', async ({ error }) => {
const replace = vi.fn()
@@ -123,7 +128,7 @@ describe('replaceWithConflictRetry order and retry', () => {
})
it.each([
- { form: 'code', error: { code: 404 } },
+ { form: 'ApiException', error: apiException(404) },
{ form: 'statusCode', error: { response: { statusCode: 404 } } },
])(
'TOCTOU-NP-3: replace 409 then second read 404 ($form) returns without a third replace',
@@ -177,7 +182,7 @@ describe('replaceWithConflictRetry order and retry', () => {
})
it.each([
- { form: 'code', error: { code: 404 } },
+ { form: 'ApiException', error: apiException(404) },
{ form: 'statusCode', error: { response: { statusCode: 404 } } },
])('TOCTOU-NP-5: helper replace 404 ($form) still throws', async ({ error }) => {
const read = vi.fn().mockResolvedValue(existing)
@@ -200,9 +205,9 @@ describe('replaceWithConflictRetry order and retry', () => {
})
it.each([
- { status: 403, form: 'code', error: { code: 403 } },
+ { status: 403, form: 'ApiException', error: apiException(403) },
{ status: 403, form: 'statusCode', error: { response: { statusCode: 403 } } },
- { status: 500, form: 'code', error: { code: 500 } },
+ { status: 500, form: 'ApiException', error: apiException(500) },
{ status: 500, form: 'statusCode', error: { response: { statusCode: 500 } } },
])(
'TOCTOU-NP-6: replace 409 then second read $status ($form) still throws',
diff --git a/host-context-controller/src/hostReconciler.ts b/host-context-controller/src/hostReconciler.ts
index 9d42f94d7..5710552a9 100644
--- a/host-context-controller/src/hostReconciler.ts
+++ b/host-context-controller/src/hostReconciler.ts
@@ -2287,6 +2287,10 @@ export class HostReconciler {
)
return
}
+ // The outer read above treats 404 as a transient throw so this Host
+ // reconcile requeues and recreates. The helper read below is the #472
+ // contract: 404 means gone, return, and the next Host reconcile
+ // recreates. Same object, two 404 policies — accepted, not a bug.
try {
await replaceWithConflictRetry({
description: `channel-reader Deployment "${name}"`,