Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(hcc): author imagePullPolicy on the stdio-bridge sidecar
Alfredo Lopezcce4850369ed
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.jsonindex 3f201c337..317dddde4 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.279",+ "version": "0.1.280","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-host-context-controller",- "version": "0.1.279",+ "version": "0.1.280","license": "SEE LICENSE IN LICENSE","dependencies": {"@clerum/codex-catalog-projection": "file:../packages/codex-catalog-projection",diff --git a/host-context-controller/package.json b/host-context-controller/package.jsonindex a0b974a32..193b0b3fe 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.279",+ "version": "0.1.280","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__/asApiserverDeployment.ts b/host-context-controller/src/__tests__/asApiserverDeployment.tsindex cf8815b10..865a4b3c8 100644--- a/host-context-controller/src/__tests__/asApiserverDeployment.ts+++ b/host-context-controller/src/__tests__/asApiserverDeployment.ts@@ -4,8 +4,10 @@ import type * as k8s from '@kubernetes/client-node'* Apply documented apps/v1 defaulting onto a desired Deployment. Unlike* `asApiserverService`, this is not a recorded-blob overlay: it fills fields* the apiserver would default-fill, leaving every HCC-authored value intact.- * Refresh this function when a live `kubectl get deploy -o json` reveals a- * default the fixture does not model (PR G §8).+ * Container `imagePullPolicy` follows kube `DefaultImagePullPolicy` (Always+ * for `:latest` / untagged; IfNotPresent otherwise). Refresh this function+ * when a live `kubectl get deploy -o json` reveals a default the fixture+ * does not model (PR G §8).*/const SERVER_TIME = new Date('2026-04-01T00:00:00.000Z')const SERVER_UID = '11111111-2222-3333-4444-555555555555'@@ -96,6 +98,9 @@ function applyPodSpecDefaults(podSpec: k8s.V1PodSpec | undefined): void {}function applyContainerDefaults(container: k8s.V1Container): void {+ if (container.imagePullPolicy === undefined) {+ container.imagePullPolicy = defaultImagePullPolicy(container.image)+ }if (container.terminationMessagePath === undefined) {container.terminationMessagePath = '/dev/termination-log'}@@ -125,6 +130,21 @@ function applyProbeDefaults(probe: k8s.V1Probe | undefined): void {if (probe.httpGet && probe.httpGet.scheme === undefined) probe.httpGet.scheme = 'HTTP'}+/**+ * Mirror kube `DefaultImagePullPolicy` / `tags.Latest`: Always when the+ * reference has no tag or the tag is `latest`; IfNotPresent for any other+ * tag or a digest. This is not a full docker-reference parser.+ */+function defaultImagePullPolicy(image: string | undefined): 'Always' | 'IfNotPresent' {+ if (!image) return 'Always'+ if (image.includes('@')) return 'IfNotPresent'+ const slash = image.lastIndexOf('/')+ const name = slash === -1 ? image : image.slice(slash + 1)+ const colon = name.lastIndexOf(':')+ if (colon === -1) return 'Always'+ return name.slice(colon + 1) === 'latest' ? 'Always' : 'IfNotPresent'+}+function applyVolumeDefaults(volume: k8s.V1Volume): void {if (volume.secret && volume.secret.defaultMode === undefined) volume.secret.defaultMode = 420if (volume.secret && volume.secret.optional === undefined) volume.secret.optional = falsediff --git a/host-context-controller/src/__tests__/deploymentMatchesDesired.test.ts b/host-context-controller/src/__tests__/deploymentMatchesDesired.test.tsindex c0a00d2dd..e5e0bbe46 100644--- a/host-context-controller/src/__tests__/deploymentMatchesDesired.test.ts+++ b/host-context-controller/src/__tests__/deploymentMatchesDesired.test.ts@@ -136,6 +136,29 @@ describe('asApiserverDeployment', () => {) as k8s.V1Deploymentexpect(asApiserverDeployment(desired)).not.toEqual(desired)})++ it('FIXTURE-1: fills omitted imagePullPolicy the way apps/v1 defaults it', () => {+ const containerOf = (desired: k8s.V1Deployment) =>+ asApiserverDeployment(desired).spec?.template?.spec?.containers?.[0]++ expect(containerOf(sparseDeployment())?.imagePullPolicy).toBe('IfNotPresent')++ const latest = sparseDeployment()+ latest.spec!.template.spec!.containers![0].image = 'img:latest'+ expect(containerOf(latest)?.imagePullPolicy).toBe('Always')++ const untagged = sparseDeployment()+ untagged.spec!.template.spec!.containers![0].image = 'img'+ expect(containerOf(untagged)?.imagePullPolicy).toBe('Always')++ const digested = sparseDeployment()+ digested.spec!.template.spec!.containers![0].image = 'img@sha256:aaaaaaaa'+ expect(containerOf(digested)?.imagePullPolicy).toBe('IfNotPresent')++ const authored = sparseDeployment()+ authored.spec!.template.spec!.containers![0].imagePullPolicy = 'Never'+ expect(containerOf(authored)?.imagePullPolicy).toBe('Never')+ })})type CanonicalPodSpec = {@@ -168,6 +191,7 @@ function deploymentWithProbe({name: 'c',image: 'img:1',+ imagePullPolicy: 'IfNotPresent',livenessProbe: {httpGet: { path: '/live', port: 80 },periodSeconds: 5,@@ -223,6 +247,13 @@ describe('safe-strip lemma equality guards', () => {})describe('deploymentMatchesDesired', () => {+ it('omitted imagePullPolicy is not a no-op against the apiserver default-fill', () => {+ const desired = sparseDeployment()+ const existing = asApiserverDeployment(desired)+ expect(existing.spec?.template?.spec?.containers?.[0]?.imagePullPolicy).toBe('IfNotPresent')+ expect(deploymentMatchesDesired(mergedForCompare(desired, existing), existing)).toBe(false)+ })+it('returns false when either spec is missing (fail-open-to-write)', () => {const desired = sparseDeployment()expect(deploymentMatchesDesired(undefined, desired)).toBe(false)diff --git a/host-context-controller/src/__tests__/deploymentWriterInventory.test.ts b/host-context-controller/src/__tests__/deploymentWriterInventory.test.tsindex a3e1b8e46..cf9042e23 100644--- a/host-context-controller/src/__tests__/deploymentWriterInventory.test.ts+++ b/host-context-controller/src/__tests__/deploymentWriterInventory.test.ts@@ -48,6 +48,12 @@ describe('Deployment writer inventory', () => {source.includes('deploymentMatchesDesired'),`${rel} is gated but does not reference deploymentMatchesDesired`).toBe(true)+ const directGates = source.match(/isUpToDate:\s*deploymentMatchesDesired\b/g)?.length ?? 0+ const wrapperGates = source.match(/return deploymentMatchesDesired\s*\(/g)?.length ?? 0+ expect(+ directGates + wrapperGates,+ `${rel} has ${count} Deployment replace(s) but ${directGates + wrapperGates} isUpToDate gate(s)`+ ).toBe(count)}if (isExempt) {expect(diff --git a/host-context-controller/src/__tests__/mcpServerDeploymentNoopGate.test.ts b/host-context-controller/src/__tests__/mcpServerDeploymentNoopGate.test.tsindex cb610bf3d..277b22b9e 100644--- a/host-context-controller/src/__tests__/mcpServerDeploymentNoopGate.test.ts+++ b/host-context-controller/src/__tests__/mcpServerDeploymentNoopGate.test.ts@@ -54,6 +54,20 @@ function makeServer(): McpServerCRD {}}+function makeStdioServer(): McpServerCRD {+ return {+ name: 'test-mcp',+ namespace: 'mcp-server',+ uid: 'uid-test-1234',+ spec: {+ contextRef: 'ctx1',+ image: 'my-mcp-server:v1',+ transport: { type: 'stdio', port: 3000 },+ command: ['/mcp-bin/mcp-server'],+ },+ }+}+function mergedForCompare(desired: k8s.V1Deployment, existing: k8s.V1Deployment): k8s.V1Deployment {return preserveDeploymentAnnotations({@@ -164,3 +178,75 @@ describe('McpServer ensureDeployment no-op gate', () => {expect(isCurrent).toHaveBeenCalled()})})++describe('McpServer stdio ensureDeployment no-op gate', () => {+ let appsApi: MockAppsApi+ let reconciler: McpServerReconciler+ const server = makeStdioServer()++ beforeEach(() => {+ appsApi = createMockAppsApi()+ reconciler = new McpServerReconciler({} as k8s.KubeConfig, {+ assumeInventoryAuthorityWhenUnconfigured: true,+ appsApi: asAppsApi(appsApi),+ coreApi: asCoreApi(createMockCoreApi()),+ customApi: asCustomApi(createMockCustomApi()),+ })+ appsApi.createNamespacedDeployment.mockRejectedValue({ code: 409 })+ })++ it('stdio-bridge authors imagePullPolicy so the live default-fill is a no-op', () => {+ const desired = (reconciler as any).buildDeployment(server, 'rev-1') as k8s.V1Deployment+ const podSpec = desired.spec?.template?.spec+ expect(podSpec?.initContainers?.find(c => c.name === 'copy-mcp-app')?.imagePullPolicy).toBe(+ 'IfNotPresent'+ )+ expect(podSpec?.containers?.find(c => c.name === 'stdio-bridge')?.imagePullPolicy).toBe(+ 'IfNotPresent'+ )+ const existing = asApiserverDeployment(desired)+ expect(deploymentMatchesDesired(mergedForCompare(desired, existing), existing)).toBe(true)+ })++ it('McpServer stdio mutation sweep: every desired leaf is detectable', () => {+ const desired = (reconciler as any).buildDeployment(server, 'rev-1') as k8s.V1Deployment+ const existing = asApiserverDeployment(desired)+ const undetectable: string[] = []+ for (const path of collectLeafPaths(desired)) {+ const mutated = cloneAndMutateLeaf(desired, path) as k8s.V1Deployment+ if (deploymentMatchesDesired(mergedForCompare(mutated, existing), existing)) {+ undetectable.push(formatLeafPath(path))+ }+ }+ expect(undetectable, `undetectable leaf path(s): ${undetectable.join(', ')}`).toEqual([])+ })++ it('NOOP-MCPDEP-STDIO-1: equivalent stdio Deployment skips replace and Updated logs', async () => {+ const desired = (reconciler as any).buildDeployment(server, 'rev-1') as k8s.V1Deployment+ appsApi.readNamespacedDeployment.mockResolvedValue(asApiserverDeployment(desired))+ const log = vi.spyOn(console, 'log')+ try {+ await (reconciler as any).ensureDeployment(server, 'rev-1')+ expect(appsApi.replaceNamespacedDeployment).not.toHaveBeenCalled()+ expect(updatedLogs(log, 'Updated', 'Deployment "test-mcp"')).toEqual([])+ } finally {+ log.mockRestore()+ }+ })++ it('IMAGE-MCPDEP-STDIO-1: image bump replaces the copy init container once', async () => {+ const live = (reconciler as any).buildDeployment(server, 'rev-1') as k8s.V1Deployment+ appsApi.readNamespacedDeployment.mockResolvedValue(asApiserverDeployment(live))+ const bumped = makeStdioServer()+ bumped.spec.image = 'my-mcp-server:v2'+ await (reconciler as any).ensureDeployment(bumped, 'rev-1')+ expect(appsApi.replaceNamespacedDeployment).toHaveBeenCalledOnce()+ const body = (+ appsApi.replaceNamespacedDeployment.mock.calls[0][0] as { body: k8s.V1Deployment }+ ).body+ const copyImage = body.spec?.template?.spec?.initContainers?.find(+ c => c.name === 'copy-mcp-app'+ )?.image+ expect(copyImage).toBe('my-mcp-server:v2')+ })+})diff --git a/host-context-controller/src/__tests__/reconciler.sanitize.test.ts b/host-context-controller/src/__tests__/reconciler.sanitize.test.tsindex 38b7c571f..a9dd07df6 100644--- a/host-context-controller/src/__tests__/reconciler.sanitize.test.ts+++ b/host-context-controller/src/__tests__/reconciler.sanitize.test.ts@@ -284,6 +284,7 @@ describe('CRD Field Injection Prevention (sanitizeCrdSpec)', () => {const copyContainer = capturedInitContainer(appsApi, 'copy-mcp-app')const bridgeContainer = capturedContainer(appsApi, 'stdio-bridge')for (const container of [copyContainer, bridgeContainer]) {+ expect(container.imagePullPolicy).toBe('IfNotPresent')expect(container.securityContext?.allowPrivilegeEscalation).toBe(false)expect(container.securityContext?.capabilities?.drop).toEqual(['ALL'])expect(container.securityContext?.capabilities?.add).toBeUndefined()diff --git a/host-context-controller/src/reconciler.ts b/host-context-controller/src/reconciler.tsindex 76fe4cf3a..db48b0f64 100644--- a/host-context-controller/src/reconciler.ts+++ b/host-context-controller/src/reconciler.ts@@ -1370,6 +1370,8 @@ ${authHeaderLines ? '\n # ── Credential auth headers (envsubst-resolv{name: 'stdio-bridge',image: config.stdioBridgeImage, // G10: configurable bridge image+ imagePullPolicy:+ server.spec.imagePullPolicy || config.mcpServerImagePullPolicy,env: [{name: 'STDIO_COMMAND',