Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
refactor(wrc): translate the NetworkPolicy apply summary in one helper
Alfredo Lopez863f4a6d0f4a
diff --git a/workflow-recipes/package-lock.json b/workflow-recipes/package-lock.jsonindex c46aea988..476422c54 100644--- a/workflow-recipes/package-lock.json+++ b/workflow-recipes/package-lock.json@@ -1,12 +1,12 @@{"name": "workload-recipes-controller",- "version": "0.1.399",+ "version": "0.1.400","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "workload-recipes-controller",- "version": "0.1.399",+ "version": "0.1.400","license": "SEE LICENSE IN LICENSE","dependencies": {"@aws-sdk/client-s3": "^3.1009.0",diff --git a/workflow-recipes/package.json b/workflow-recipes/package.jsonindex a0c99f94d..da3cf0c2b 100644--- a/workflow-recipes/package.json+++ b/workflow-recipes/package.json@@ -1,6 +1,6 @@{"name": "workload-recipes-controller",- "version": "0.1.399",+ "version": "0.1.400","description": "Workload Recipes Controller (WRC) - WorkloadRecipe lifecycle management and MCP server interface","main": "dist/main.js","engines": {diff --git a/workflow-recipes/src/reconciler/workflowRecipeReconciler.ts b/workflow-recipes/src/reconciler/workflowRecipeReconciler.tsindex d73eac8e0..d3e6409a1 100644--- a/workflow-recipes/src/reconciler/workflowRecipeReconciler.ts+++ b/workflow-recipes/src/reconciler/workflowRecipeReconciler.ts@@ -67,7 +67,7 @@ import {WORKFLOW_OUTPUT_CONDITION_TYPES,WorkflowReconciler,WorkflowReconcilerDeps,- buildNetworkPolicyOwnershipConditions,+ translateNetworkPolicyApplySummary,} from '../workflow/workflowReconciler'import { evaluateComputedValues } from './computedValuesEvaluator'import { CRD_GROUP, CRD_VERSION, WORKFLOWRECIPE_PLURAL } from './crdConstants'@@ -635,7 +635,8 @@ export interface ReconcileResult {/*** `WorkflowNetworkPolicyOwnership` from this pass's policy apply. Undefined* keeps the published condition (the pass never reached the apply); `[]`- * removes it (every policy converged, or the lane manages none).+ * removes it (no policy is owned by another controller — a pending retry+ * does not count as a conflict — or the lane manages none).*/networkPolicyOwnershipConditions?: StatusCondition[]/** SDK-only eager-host provider health, kept separate from workflow phase. */@@ -2911,6 +2912,19 @@ export class WorkflowRecipeReconciler {sdkOnlyRuntime?.phase === 'active' &&recipe.spec.pluginWorkloadSdk !== undefined &&sdkOnlyRuntime.pluginWorkloadSdkBootstrapProof?.ready !== true+ // Without an SDK runtime this lane manages no policies: nothing conflicts+ // and nothing is pending, so a condition published by an earlier pass is+ // stale and `[]` removes it. A runtime without a summary did not evaluate+ // the policies (the host returned before the apply), so the ownership+ // field stays absent and patchStatus keeps what was published.+ const {+ networkPolicyRetryPending: sdkOnlyNetworkPolicyRetryPending,+ ...sdkOnlyNetworkPolicyOwnership+ } = translateNetworkPolicyApplySummary(+ sdkOnlyRuntime ? sdkOnlyRuntime.networkPolicies : { conflicts: [], retryPending: false },+ recipe.status?.conditions,+ new Date().toISOString()+ )if (sdkOnlyRuntime?.phase === 'failed') {return {phase: 'failed',@@ -2924,19 +2938,11 @@ export class WorkflowRecipeReconciler {// Without a summary the host returned before the policy apply, so// the field stays undefined and patchStatus keeps what was published.// A pod that failed after the apply publishes what the apply found.- ...(sdkOnlyRuntime.networkPolicies !== undefined- ? {- networkPolicyOwnershipConditions: buildNetworkPolicyOwnershipConditions(- sdkOnlyRuntime.networkPolicies,- new Date().toISOString(),- recipe.status?.conditions- ),- }- : {}),+ ...sdkOnlyNetworkPolicyOwnership,// A policy the apply left pending a retry is requeued on the backoff// path, as the workflow lane does for its eager `failed` return.// `failed` itself sets no requeue.- ...(sdkOnlyRuntime.networkPolicies?.retryPending+ ...(sdkOnlyNetworkPolicyRetryPending? { requeueAfterMs: TRANSIENT_REQUEUE_BASE_MS, requeueFixedInterval: false }: {}),}@@ -2992,18 +2998,7 @@ export class WorkflowRecipeReconciler {secretOwnershipConditions: secretOwnership.conditions,workloadConditions,transportNetworkConditions: [],- // Without an SDK runtime this lane manages no policies, so a condition- // published by an earlier pass is stale and `[]` removes it. A runtime- // without a summary did not evaluate the policies, so undefined keeps it.- networkPolicyOwnershipConditions: !sdkOnlyRuntime- ? []- : sdkOnlyRuntime.networkPolicies === undefined- ? undefined- : buildNetworkPolicyOwnershipConditions(- sdkOnlyRuntime.networkPolicies,- new Date().toISOString(),- recipe.status?.conditions- ),+ ...sdkOnlyNetworkPolicyOwnership,pluginWorkloadSdkProviderUnavailable: sdkOnlyProviderUnavailable,pluginWorkloadSdkPolicyPending: sdkOnlyPolicyPending,pluginWorkloadSdkBootstrapProof: sdkOnlyRuntime?.pluginWorkloadSdkBootstrapProof,@@ -3019,7 +3014,7 @@ export class WorkflowRecipeReconciler {sdkOnlyRuntime?.phase === 'provider_unavailable' ||sdkOnlyPolicyPending ||sdkOnlyBootstrapPending ||- sdkOnlyRuntime?.networkPolicies?.retryPending+ sdkOnlyNetworkPolicyRetryPending? TRANSIENT_REQUEUE_BASE_MS: undefined,// Policy-pending waits for an operator grant (event or the 30s refreshdiff --git a/workflow-recipes/src/workflow/workflowReconciler.ts b/workflow-recipes/src/workflow/workflowReconciler.tsindex 13ad60c1e..fc4ba197d 100644--- a/workflow-recipes/src/workflow/workflowReconciler.ts+++ b/workflow-recipes/src/workflow/workflowReconciler.ts@@ -267,9 +267,10 @@ export const WORKFLOW_OUTPUT_CONDITION_TYPES = new Set([/*** The ownership condition for one policy apply pass: `False` naming every- * policy another controller owns, or `[]` when every policy converged. The- * result goes in `networkPolicyOwnershipConditions`, where `[]` removes a- * previously published condition and `undefined` keeps it.+ * policy another controller owns, or `[]` when no policy is owned by another+ * controller (a pending retry does not count as a conflict). The result goes in+ * `networkPolicyOwnershipConditions`, where `[]` removes a previously published+ * condition and `undefined` keeps it.*/export function buildNetworkPolicyOwnershipConditions(summary: WorkflowNetworkPolicyApplySummary,@@ -295,6 +296,29 @@ export function buildNetworkPolicyOwnershipConditions(]}+/**+ * The status fields one policy apply pass contributes, shared by the run lane+ * and the SDK-only lane so both translate a summary the same way. No summary+ * (the pass returned before the apply) yields neither field, which keeps the+ * published condition. A summary always yields the ownership conditions, `[]`+ * included, and the retry flag only when a policy was left pending a retry.+ */+export function translateNetworkPolicyApplySummary(+ summary: WorkflowNetworkPolicyApplySummary | undefined,+ existingConditions: StatusCondition[] | undefined,+ now: string+): Pick<WorkflowReconcileResult, 'networkPolicyOwnershipConditions' | 'networkPolicyRetryPending'> {+ if (summary === undefined) return {}+ return {+ networkPolicyOwnershipConditions: buildNetworkPolicyOwnershipConditions(+ summary,+ now,+ existingConditions+ ),+ ...(summary.retryPending ? { networkPolicyRetryPending: true } : {}),+ }+}+interface CoordinatorTokenRefreshOptions {includeMcpHostToken?: booleanuseCustomCoordinatorWrcToken?: boolean@@ -815,7 +839,8 @@ export interface WorkflowReconcileResult {/*** The `WorkflowNetworkPolicyOwnership` condition from this pass's policy* apply. Undefined when the pass returned before the apply, which keeps the- * published condition; `[]` when every policy converged, which removes it.+ * published condition; `[]` when no policy is owned by another controller (a+ * pending retry does not count as a conflict), which removes it.*/networkPolicyOwnershipConditions?: StatusCondition[]/**@@ -1664,18 +1689,14 @@ export class WorkflowReconciler {new Date().toISOString(),currentStatus?.conditions)- // Undefined until this pass applies the policies, then what the apply- // found. A return before the apply leaves it undefined, and patchStatus- // keeps the published condition.- let networkPolicyOwnershipConditions: StatusCondition[] | undefined- let networkPolicyRetryPending = false+ // Empty until this pass applies the policies, then what the apply found.+ // A return before the apply leaves it empty, and patchStatus keeps the+ // published condition.+ let networkPolicyStatus: ReturnType<typeof translateNetworkPolicyApplySummary> = {}const withWorkflowConditions = (result: WorkflowReconcileResult): WorkflowReconcileResult => ({...result,workflowConditions,- ...(networkPolicyOwnershipConditions !== undefined- ? { networkPolicyOwnershipConditions }- : {}),- ...(networkPolicyRetryPending ? { networkPolicyRetryPending } : {}),+ ...networkPolicyStatus,})const outputAnchorPodName = runtime.output.anchorRequired? buildWorkflowOutputAnchorPodName(runtimeScopeRecipeName)@@ -1819,14 +1840,11 @@ export class WorkflowReconciler {// No summary means the host returned before the apply, so the pass// cannot say whether a conflict is gone. A `failed` pod after the// apply still carries a real summary and publishes it.- if (eagerNetworkPolicies !== undefined) {- networkPolicyOwnershipConditions = buildNetworkPolicyOwnershipConditions(- eagerNetworkPolicies,- new Date().toISOString(),- currentStatus?.conditions- )- networkPolicyRetryPending = eagerNetworkPolicies.retryPending- }+ networkPolicyStatus = translateNetworkPolicyApplySummary(+ eagerNetworkPolicies,+ currentStatus?.conditions,+ new Date().toISOString()+ )if (eagerStatus === 'failed') {return withWorkflowConditions({phase: 'failed',@@ -2287,12 +2305,11 @@ export class WorkflowReconciler {false,codexVerdict.grokProjection)- networkPolicyOwnershipConditions = buildNetworkPolicyOwnershipConditions(+ networkPolicyStatus = translateNetworkPolicyApplySummary(runLaneNetworkPolicies,- new Date().toISOString(),- currentStatus?.conditions+ currentStatus?.conditions,+ new Date().toISOString())- networkPolicyRetryPending = runLaneNetworkPolicies.retryPending// 6. Create Pods — mcp-host FIRST, then coordinator. If the coordinator// resolves DNS before mcp-host's EndpointSlice exists, undici caches thediff --git a/workflow-recipes/tests/unit/workflow/workflowReconciler.test.ts b/workflow-recipes/tests/unit/workflow/workflowReconciler.test.tsindex 66b91e46b..6d28706bc 100644--- a/workflow-recipes/tests/unit/workflow/workflowReconciler.test.ts+++ b/workflow-recipes/tests/unit/workflow/workflowReconciler.test.ts@@ -35,6 +35,7 @@ import {WorkflowReconciler,type WorkflowReconcilerDeps,buildNetworkPolicyOwnershipConditions,+ translateNetworkPolicyApplySummary,} from '../../../src/workflow/workflowReconciler'import { asApiserverNetworkPolicy } from './asApiserverNetworkPolicy'@@ -7497,3 +7498,106 @@ describe('buildNetworkPolicyOwnershipConditions', () => {])})})++// The one translation of an apply summary into status fields, shared by the+// run lane and the SDK-only lane. `toStrictEqual` pins which keys are present:+// an absent ownership key keeps the published condition, so it must not be+// emitted as an explicit `undefined`.+describe('translateNetworkPolicyApplySummary', () => {+ const now = '2026-09-23T12:00:00.000Z'+ const earlier = '2026-09-20T08:00:00.000Z'+ const conflictSummary = {+ conflicts: [{ policy: 'test-wf-coord-to-wrc', reason: 'owner-reference-mismatch' as const }],+ retryPending: false,+ }+ const publishedConflict = {+ type: 'WorkflowNetworkPolicyOwnership',+ status: 'False' as const,+ reason: 'OwnershipConflict',+ message: 'NetworkPolicy ownership conflict: test-wf-coord-to-wrc (owner-reference-mismatch)',+ lastTransitionTime: earlier,+ }++ it('emits neither field when the pass produced no summary, so the published condition is kept', () => {+ const result = translateNetworkPolicyApplySummary(undefined, [publishedConflict], now)++ expect(result).toStrictEqual({})+ // Witness: the same existing conditions with a summary do produce the+ // field, so the empty result above is caused by the missing summary.+ expect(+ translateNetworkPolicyApplySummary(conflictSummary, [publishedConflict], now)+ .networkPolicyOwnershipConditions+ ).toEqual([publishedConflict])+ })++ it('clears the condition with [] and sets no retry flag when nothing conflicts or is pending', () => {+ const result = translateNetworkPolicyApplySummary(+ { conflicts: [], retryPending: false },+ [publishedConflict],+ now+ )++ expect(result.networkPolicyOwnershipConditions).toEqual([])+ expect(result).not.toHaveProperty('networkPolicyRetryPending')+ expect(result).toStrictEqual({ networkPolicyOwnershipConditions: [] })+ })++ it('clears the condition with [] and sets the retry flag when a retry is pending without a conflict', () => {+ const result = translateNetworkPolicyApplySummary(+ { conflicts: [], retryPending: true },+ [publishedConflict],+ now+ )++ expect(result).toStrictEqual({+ networkPolicyOwnershipConditions: [],+ networkPolicyRetryPending: true,+ })+ })++ it('replaces the condition with one False condition naming every conflicting policy', () => {+ const result = translateNetworkPolicyApplySummary(+ {+ conflicts: [+ { policy: 'test-wf-wrc-to-artifact-reader', reason: 'identity-label-mismatch' },+ { policy: 'test-wf-coord-to-wrc', reason: 'owner-reference-mismatch' },+ ],+ retryPending: false,+ },+ undefined,+ now+ )++ expect(result.networkPolicyOwnershipConditions).toEqual([+ {+ type: 'WorkflowNetworkPolicyOwnership',+ status: 'False',+ reason: 'OwnershipConflict',+ message:+ 'NetworkPolicy ownership conflict: test-wf-coord-to-wrc (owner-reference-mismatch), test-wf-wrc-to-artifact-reader (identity-label-mismatch)',+ lastTransitionTime: now,+ },+ ])+ expect(result).not.toHaveProperty('networkPolicyRetryPending')+ })++ it('keeps the lastTransitionTime of an identical published condition', () => {+ const result = translateNetworkPolicyApplySummary(conflictSummary, [publishedConflict], now)++ expect(result).toStrictEqual({ networkPolicyOwnershipConditions: [publishedConflict] })+ expect(result.networkPolicyOwnershipConditions?.[0]?.lastTransitionTime).toBe(earlier)+ })++ it('reports a conflict and a pending retry from the same pass together', () => {+ const result = translateNetworkPolicyApplySummary(+ { ...conflictSummary, retryPending: true },+ undefined,+ now+ )++ expect(result).toStrictEqual({+ networkPolicyOwnershipConditions: [{ ...publishedConflict, lastTransitionTime: now }],+ networkPolicyRetryPending: true,+ })+ })+})