Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(workflow-recipes): run the oauth token delete once per first-deploy pass
Alfredo Lopez666531219df9
diff --git a/workflow-recipes/package-lock.json b/workflow-recipes/package-lock.jsonindex 931536e58..73bb7e1f4 100644--- a/workflow-recipes/package-lock.json+++ b/workflow-recipes/package-lock.json@@ -1,12 +1,12 @@{"name": "workload-recipes-controller",- "version": "0.1.415",+ "version": "0.1.416","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "workload-recipes-controller",- "version": "0.1.415",+ "version": "0.1.416","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 bf5cae8c4..4cd8722a8 100644--- a/workflow-recipes/package.json+++ b/workflow-recipes/package.json@@ -1,6 +1,6 @@{"name": "workload-recipes-controller",- "version": "0.1.415",+ "version": "0.1.416","description": "Workload Recipes Controller (WRC) - WorkloadRecipe lifecycle management and MCP server interface","main": "dist/main.js","engines": {diff --git a/workflow-recipes/src/reconciler/reconciler.test.ts b/workflow-recipes/src/reconciler/reconciler.test.tsindex cc0a16561..9f0346828 100644--- a/workflow-recipes/src/reconciler/reconciler.test.ts+++ b/workflow-recipes/src/reconciler/reconciler.test.ts@@ -3269,9 +3269,13 @@ describe('WorkflowRecipeReconciler', () => {const deployWorkflowWorkloads = () =>(reconciler as unknown as {- deployWorkflowWorkloads: (r: WorkflowRecipeCRD, n: string) => Promise<unknown>+ deployWorkflowWorkloads: (+ r: WorkflowRecipeCRD,+ n: string,+ oauthBrokerTokenReapedEarly: boolean+ ) => Promise<unknown>}- ).deployWorkflowWorkloads(recipe, recipe.metadata.name)+ ).deployWorkflowWorkloads(recipe, recipe.metadata.name, false)await deployWorkflowWorkloads()const created = onlyPost(mockCoreApi.createNamespacedService)const name = created.body.metadata.name@@ -15840,6 +15844,75 @@ describe('WorkflowRecipeReconciler', () => {expect(secretDeletes()).toBe(1)})})++ function installFirstDeployWorkflow(): {+ recipe: WorkflowRecipeCRD+ workflowReconcile: ReturnType<typeof vi.fn>+ } {+ const workflowReconcile = vi.fn().mockResolvedValue({+ phase: 'deploying',+ message: 'Workflow infrastructure created',+ workflowPhase: 'initializing',+ })+ ;(+ reconciler as unknown as {+ workflowReconciler: {+ reconcile: typeof workflowReconcile+ validateWorkflowSpec: () => undefined+ }+ }+ ).workflowReconciler = { reconcile: workflowReconcile, validateWorkflowSpec: () => undefined }+ const recipe = makeRecipe({+ metadata: {+ name: 'test-recipe',+ namespace: 'sandbox-recipes',+ uid: 'uid-123',+ generation: 4,+ },+ spec: {+ workloads: [{ id: 'app', type: 'deployment', image: 'nginx:1.30.1-alpine', port: 8080 }],+ steps: [{ id: 'run', run: snippetRun() }],+ },+ })+ return { recipe, workflowReconcile }+ }++ it('R2-L3: without a token ADDED the first-deploy pass still sends its one DELETE', async () => {+ const { recipe, workflowReconcile } = installFirstDeployWorkflow()++ await reconciler.reconcile(recipe)++ // Witness that the pass went through deployWorkflowWorkloads.+ expect(workflowReconcile).toHaveBeenCalledTimes(1)+ expect(secretDeletes()).toBe(1)+ })++ it('R2-L3: a first-deploy pass sends one token DELETE when it fails, and the next pass retries', async () => {+ const { recipe, workflowReconcile } = installFirstDeployWorkflow()+ let tokenDeletes = 0+ mockCoreApi.deleteNamespacedSecret.mockImplementation(async ({ name }: { name: string }) => {+ if (name !== SECRET_NAME) return {}+ tokenDeletes += 1+ if (tokenDeletes === 1) throw { code: 503 }+ return {}+ })+ try {+ // A token ADDED was observed, so the early reap runs in this pass.+ reconciler.invalidateOAuthBrokerSecretLedger('test-recipe')+ await reconciler.reconcile(recipe)++ // Witness that the pass went through deployWorkflowWorkloads.+ expect(workflowReconcile).toHaveBeenCalledTimes(1)+ expect(secretDeletes()).toBe(1)++ // The failed DELETE was not recorded, so the next pass retries it.+ await reconciler.reconcile(recipe)+ expect(workflowReconcile).toHaveBeenCalledTimes(2)+ expect(secretDeletes()).toBe(2)+ } finally {+ mockCoreApi.deleteNamespacedSecret.mockResolvedValue({})+ }+ })})describe('G2 skipStatusPatch must not leave GFS deleted', () => {diff --git a/workflow-recipes/src/reconciler/workflowRecipeReconciler.ts b/workflow-recipes/src/reconciler/workflowRecipeReconciler.tsindex 399df8df8..51858a580 100644--- a/workflow-recipes/src/reconciler/workflowRecipeReconciler.ts+++ b/workflow-recipes/src/reconciler/workflowRecipeReconciler.ts@@ -1974,11 +1974,13 @@ export class WorkflowRecipeReconciler {// bounds it to one DELETE per generation or ADDED. It runs only once a// token ADDED was observed for the recipe: a fresh process would otherwise// send one DELETE per recipe, and the Secret watch's initial list replays- // ADDED for every token that exists.- if (+ // ADDED for every token that exists. The first-deploy path below skips+ // its own call when this one ran, so a failed DELETE is not repeated in+ // the same pass.+ const oauthBrokerTokenReapedEarly =!rb.recipeHasBackgroundAccessClient(recipe) &&this.oauthBrokerDeleteLedger.secretEpoch(recipe.metadata.name) !== 0- ) {+ if (oauthBrokerTokenReapedEarly) {await this.ensureOAuthBrokerTokenSecret(recipe)}@@ -2307,7 +2309,11 @@ export class WorkflowRecipeReconciler {name,})try {- const workflowDeploy = await this.deployWorkflowWorkloads(recipe, name)+ const workflowDeploy = await this.deployWorkflowWorkloads(+ recipe,+ name,+ oauthBrokerTokenReapedEarly+ )workflowInternalDependencyConditions = workflowDeploy.internalDependencyConditionsworkflowWorkloadConditions = workflowDeploy.workloadConditionsworkflowTransportNetworkConditions = workflowDeploy.transportNetworkConditions@@ -3648,7 +3654,8 @@ export class WorkflowRecipeReconciler {private async deployWorkflowWorkloads(recipe: WorkflowRecipeCRD,- name: string+ name: string,+ oauthBrokerTokenReapedEarly: boolean): Promise<{internalDependencyConditions: StatusCondition[]secretOwnershipConditions: StatusCondition[]@@ -3740,14 +3747,17 @@ export class WorkflowRecipeReconciler {// Provision the OAuth broker token Secret before workloads so the// RECIPE_OAUTH_BROKER_TOKEN secretKeyRef resolves on first pod start.// Non-fatal — same rationale as the non-workflow branch above. The- // periodic rotation loop will retry on its own cadence.- try {- await this.ensureOAuthBrokerTokenSecret(recipe)- } catch (err) {- createLogger('wrc', recipe.metadata.name).warn(- 'Broker-token issuance failed during workflow reconciliation; rotation will retry',- { name, err }- )+ // periodic rotation loop will retry on its own cadence. Skipped when the+ // early reap in reconcile() already ran the delete branch for this pass.+ if (!oauthBrokerTokenReapedEarly) {+ try {+ await this.ensureOAuthBrokerTokenSecret(recipe)+ } catch (err) {+ createLogger('wrc', recipe.metadata.name).warn(+ 'Broker-token issuance failed during workflow reconciliation; rotation will retry',+ { name, err }+ )+ }}// Create/update workload resources in dependency order. Secret ownership was