Skip to content

Commit 5f567a9

Browse files
committed
Only determine default service account if none has been specified, and use convenience method to filter down to new endpoints
1 parent f5c053c commit 5f567a9

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/deploy/functions/checkIam.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ describe("checkIam", () => {
391391
expect(getIamStub).to.have.been.calledWith(projectNumber);
392392
expect(setIamStub).to.have.been.calledOnce;
393393
});
394+
394395
it("should not update policy if it already has necessary bindings", async () => {
395396
const serviceAccount = `test-sa@${projectId}.iam.gserviceaccount.com`;
396397
const iamPolicy = {

src/deploy/functions/checkIam.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -196,25 +196,26 @@ export async function ensureGenkitMonitoringRoles(
196196
dryRun?: boolean,
197197
): Promise<void> {
198198
const wantEndpoints = backend.allEndpoints(want).filter(isGenkitEndpoint);
199-
const haveEndpoints = backend.allEndpoints(have).filter(isGenkitEndpoint);
200-
const newEndpoints = wantEndpoints.filter(
201-
(wantE) => !haveEndpoints.find((haveE) => haveE.id === wantE.id),
202-
);
199+
const newEndpoints = wantEndpoints.filter(backend.missingEndpoint(have));
203200

204201
if (newEndpoints.length === 0) {
205202
return;
206203
}
207204

208-
const defaultComputeServiceAgent = await gce.getDefaultServiceAccount(projectNumber);
209205
const serviceAccounts = newEndpoints
210-
.map((endpoint) => endpoint.serviceAccount || defaultComputeServiceAgent)
211-
.filter((value, index, self) => self.indexOf(value) === index)
212-
.map((sa) => `serviceAccount:${sa}`);
206+
.map((endpoint) => endpoint.serviceAccount || "")
207+
.filter((value, index, self) => self.indexOf(value) === index);
208+
const defaultServiceAccountIndex = serviceAccounts.indexOf("");
209+
if (defaultServiceAccountIndex) {
210+
serviceAccounts[defaultServiceAccountIndex] = await gce.getDefaultServiceAccount(projectNumber);
211+
}
212+
213+
const members = serviceAccounts.map((sa) => `serviceAccount:${sa}`);
213214
const requiredBindings: iam.Binding[] = [];
214215
for (const monitoringRole of GENKIT_MONITORING_ROLES) {
215216
requiredBindings.push({
216217
role: monitoringRole,
217-
members: serviceAccounts,
218+
members: members,
218219
});
219220
}
220221
await ensureBindings(
@@ -288,7 +289,7 @@ async function ensureBindings(
288289
iam.printManualIamConfig(requiredBindings, projectId, "functions");
289290
utils.logLabeledBullet(
290291
"functions",
291-
"Could not verify the necessary IAM configuration for the following newly-integrated services or endpoints: " +
292+
"Could not verify the necessary IAM configuration for the following newly-integrated services: " +
292293
`${newServicesOrEndpoints.join(", ")}` +
293294
". Deployment may fail.",
294295
"warn",

0 commit comments

Comments
 (0)