Skip to content

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

TypeScript

fix(hcc): drop foreign GFS pod-template annotations

Alfredo Lopez22cf9cc8e251
diff --git a/host-context-controller/package-lock.json b/host-context-controller/package-lock.json
index 8e2309e28..23580e225 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.341",
+ "version": "0.1.342",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-host-context-controller",
- "version": "0.1.341",
+ "version": "0.1.342",
"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.json
index 543c8b462..1c1e7faec 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.341",
+ "version": "0.1.342",
"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/k8s/gfsK8sApi.readFirst.test.ts b/host-context-controller/src/k8s/gfsK8sApi.readFirst.test.ts
index 2686ec995..29689de64 100644
--- a/host-context-controller/src/k8s/gfsK8sApi.readFirst.test.ts
+++ b/host-context-controller/src/k8s/gfsK8sApi.readFirst.test.ts
@@ -351,6 +351,7 @@ describe('K8sGfsApi PodDisruptionBudget no-op gate (T4)', () => {
const REVISION_ANNOTATION = 'deployment.kubernetes.io/revision'
const RESTARTED_AT = 'kubectl.kubernetes.io/restartedAt'
+const FOREIGN_TEMPLATE_ANNOTATION = 'container.apparmor.security.beta.kubernetes.io/gfsc'
const readerProducerConfig: GfsFactoryConfig = {
gfsNamespace: 'gfs',
@@ -502,6 +503,53 @@ describe('K8sGfsApi Deployment no-op gate (T3, T8)', () => {
expect(await deploymentSkipCount()).toBe(0)
})
+ it('M1: a foreign pod-template annotation is stripped and forces a replace', async () => {
+ const desired = producedReader()
+ const live = asApiserverDeployment(desired)
+ const templateMeta = live.spec?.template?.metadata
+ if (!templateMeta) throw new Error('expected pod template metadata')
+ templateMeta.annotations = {
+ ...templateMeta.annotations,
+ [RESTARTED_AT]: '2026-09-16T20:33:45Z',
+ [FOREIGN_TEMPLATE_ANNOTATION]: 'unconfined',
+ }
+ const drifted = harness('Deployment')
+ drifted.read.mockImplementation(async () => {
+ drifted.events.push('GET')
+ return live
+ })
+ await drifted.api.applyDeployment(desired, namespace)
+ expect(drifted.replace).toHaveBeenCalledTimes(1)
+ const replaced = drifted.replace.mock.calls[0][0].body as k8s.V1Deployment
+ const written = replaced.spec?.template?.metadata?.annotations ?? {}
+ expect(written[FOREIGN_TEMPLATE_ANNOTATION]).toBeUndefined()
+ expect(written[RESTARTED_AT]).toBe('2026-09-16T20:33:45Z')
+ expect(written['clerum.io/gfsc-template-hash']).toBe(
+ desired.spec?.template?.metadata?.annotations?.['clerum.io/gfsc-template-hash']
+ )
+ expect(await deploymentSkipCount()).toBe(0)
+ })
+
+ it('M1: an object-level foreign annotation still skips the replace', async () => {
+ const desired = producedReader()
+ const live = asApiserverDeployment(desired)
+ live.metadata = {
+ ...live.metadata,
+ annotations: {
+ ...live.metadata?.annotations,
+ 'kubectl.kubernetes.io/last-applied-configuration': '{}',
+ },
+ }
+ const equal = harness('Deployment')
+ equal.read.mockImplementation(async () => {
+ equal.events.push('GET')
+ return live
+ })
+ await equal.api.applyDeployment(desired, namespace)
+ expect(equal.replace).toHaveBeenCalledTimes(0)
+ expect(await deploymentSkipCount()).toBe(1)
+ })
+
it('T8: skips replace when live template has restartedAt and increments writeSkipsTotal', async () => {
const desired = desiredReaderFromFixture()
const restarted = harness('Deployment')
diff --git a/host-context-controller/src/k8s/gfsK8sApi.ts b/host-context-controller/src/k8s/gfsK8sApi.ts
index a82e093e6..7e7c4a22f 100644
--- a/host-context-controller/src/k8s/gfsK8sApi.ts
+++ b/host-context-controller/src/k8s/gfsK8sApi.ts
@@ -11,17 +11,54 @@ import {
observeCreate,
observeExistenceRead,
podDisruptionBudgetMatchesDesired,
- preserveDeploymentAnnotations,
preserveObjectAnnotations,
replaceWithConflictRetry,
} from '../utils'
import { GFS_TEMPLATE_HASH_ANNOTATION } from './gfsFactory'
+/** Live-only pod-template key kubectl stamps on `rollout restart`. */
+const RESTARTED_AT_ANNOTATION = 'kubectl.kubernetes.io/restartedAt'
+
const GROUP = 'clerum.io'
const VERSION = 'v1alpha1'
const PLURAL = 'globalfilesystems'
const LOG = '[gfsReconciler]'
+/**
+ * Object annotations stay fully merged so last-applied-configuration and
+ * deployment.kubernetes.io/revision do not churn the no-op gate. Pod-template
+ * annotations keep what the builder authored, plus restartedAt. Any other
+ * live-only template key is dropped so a foreign annotation cannot stick
+ * across a skipped replace.
+ */
+function preserveGfsDeploymentAnnotations(
+ desired: k8s.V1Deployment,
+ existing: k8s.V1Deployment
+): k8s.V1Deployment {
+ const objectPreserved = preserveObjectAnnotations(desired, existing)
+ const templateAnnotations: Record<string, string> = {
+ ...(desired.spec?.template?.metadata?.annotations ?? {}),
+ }
+ const restartedAt = existing.spec?.template?.metadata?.annotations?.[RESTARTED_AT_ANNOTATION]
+ if (restartedAt !== undefined && templateAnnotations[RESTARTED_AT_ANNOTATION] === undefined) {
+ templateAnnotations[RESTARTED_AT_ANNOTATION] = restartedAt
+ }
+ return {
+ ...objectPreserved,
+ spec: {
+ ...objectPreserved.spec,
+ template: {
+ ...objectPreserved.spec?.template,
+ metadata: {
+ ...objectPreserved.spec?.template?.metadata,
+ annotations:
+ Object.keys(templateAnnotations).length > 0 ? templateAnnotations : undefined,
+ },
+ },
+ },
+ }
+}
+
/**
* Real Kubernetes adapter for the gfs reconciler. Wraps @kubernetes/client-node
* with the same create-or-replace / idempotent-delete conventions the
@@ -135,7 +172,7 @@ export class K8sGfsApi implements GfsK8sApi {
body: dep,
read,
replace: body => this.appsApi.replaceNamespacedDeployment({ name, namespace, body }),
- mergeExisting: preserveDeploymentAnnotations,
+ mergeExisting: preserveGfsDeploymentAnnotations,
isUpToDate: deploymentMatchesDesired,
}),
})
diff --git a/host-context-controller/src/utils.ts b/host-context-controller/src/utils.ts
index 035db37f0..247074f05 100644
--- a/host-context-controller/src/utils.ts
+++ b/host-context-controller/src/utils.ts
@@ -292,11 +292,10 @@ export function preserveObjectAnnotations<
* Pod-template annotations include operational restart markers such as
* kubectl.kubernetes.io/restartedAt.
*
- * This merges every live annotation, not only operational keys. Narrowing
- * the merge to an allowlist is a separate design (#698): object-level keys
- * such as last-applied-configuration must keep merging or the gate churns,
- * while pod-template security annotations are the injection surface. Do not
- * allowlist here without a churn tripwire.
+ * This merges every live annotation. GFS applyDeployment does not use it:
+ * that path keeps object annotations and drops live-only pod-template keys
+ * other than kubectl.kubernetes.io/restartedAt. Host, SFS, McpServer, and
+ * LlmHook still merge every template annotation (#698).
*/
export function preserveDeploymentAnnotations<
T extends {