Skip to content

Commit

Permalink
Revert "Fix issue with mixed v1 and v2 functions deployments (#6293)" (
Browse files Browse the repository at this point in the history
…#6295)

This reverts commit d44e236.
  • Loading branch information
blidd-google authored Aug 24, 2023
1 parent 42124d7 commit d2cd8e3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 56 deletions.
33 changes: 10 additions & 23 deletions src/deploy/functions/release/fabricator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,22 +130,17 @@ export class Fabricator {
};

const upserts: Array<Promise<void>> = [];
const scraperV1 = new SourceTokenScraper();
const scraperV2 = new SourceTokenScraper();
const scraper = new SourceTokenScraper();
for (const endpoint of changes.endpointsToCreate) {
this.logOpStart("creating", endpoint);
upserts.push(
handle("create", endpoint, () => this.createEndpoint(endpoint, scraperV1, scraperV2))
);
upserts.push(handle("create", endpoint, () => this.createEndpoint(endpoint, scraper)));
}
for (const endpoint of changes.endpointsToSkip) {
utils.logSuccess(this.getLogSuccessMessage("skip", endpoint));
}
for (const update of changes.endpointsToUpdate) {
this.logOpStart("updating", update.endpoint);
upserts.push(
handle("update", update.endpoint, () => this.updateEndpoint(update, scraperV1, scraperV2))
);
upserts.push(handle("update", update.endpoint, () => this.updateEndpoint(update, scraper)));
}
await utils.allSettled(upserts);

Expand All @@ -172,39 +167,31 @@ export class Fabricator {
return deployResults;
}

async createEndpoint(
endpoint: backend.Endpoint,
scraperV1: SourceTokenScraper,
scraperV2: SourceTokenScraper
): Promise<void> {
async createEndpoint(endpoint: backend.Endpoint, scraper: SourceTokenScraper): Promise<void> {
endpoint.labels = { ...endpoint.labels, ...deploymentTool.labels() };
if (endpoint.platform === "gcfv1") {
await this.createV1Function(endpoint, scraperV1);
await this.createV1Function(endpoint, scraper);
} else if (endpoint.platform === "gcfv2") {
await this.createV2Function(endpoint, scraperV2);
await this.createV2Function(endpoint, scraper);
} else {
assertExhaustive(endpoint.platform);
}

await this.setTrigger(endpoint);
}

async updateEndpoint(
update: planner.EndpointUpdate,
scraperV1: SourceTokenScraper,
scraperV2: SourceTokenScraper
): Promise<void> {
async updateEndpoint(update: planner.EndpointUpdate, scraper: SourceTokenScraper): Promise<void> {
update.endpoint.labels = { ...update.endpoint.labels, ...deploymentTool.labels() };
if (update.deleteAndRecreate) {
await this.deleteEndpoint(update.deleteAndRecreate);
await this.createEndpoint(update.endpoint, scraperV1, scraperV2);
await this.createEndpoint(update.endpoint, scraper);
return;
}

if (update.endpoint.platform === "gcfv1") {
await this.updateV1Function(update.endpoint, scraperV1);
await this.updateV1Function(update.endpoint, scraper);
} else if (update.endpoint.platform === "gcfv2") {
await this.updateV2Function(update.endpoint, scraperV2);
await this.updateV2Function(update.endpoint, scraper);
} else {
assertExhaustive(update.endpoint.platform);
}
Expand Down
43 changes: 10 additions & 33 deletions src/test/deploy/functions/release/fabricator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1216,11 +1216,7 @@ describe("Fabricator", () => {
const createV1Function = sinon.stub(fab, "createV1Function");
createV1Function.resolves();

await fab.createEndpoint(
ep,
new scraper.SourceTokenScraper(),
new scraper.SourceTokenScraper()
);
await fab.createEndpoint(ep, new scraper.SourceTokenScraper());
expect(createV1Function).is.calledOnce;
expect(setTrigger).is.calledOnce;
expect(setTrigger).is.calledAfter(createV1Function);
Expand All @@ -1233,11 +1229,7 @@ describe("Fabricator", () => {
const createV2Function = sinon.stub(fab, "createV2Function");
createV2Function.resolves();

await fab.createEndpoint(
ep,
new scraper.SourceTokenScraper(),
new scraper.SourceTokenScraper()
);
await fab.createEndpoint(ep, new scraper.SourceTokenScraper());
expect(createV2Function).is.calledOnce;
expect(setTrigger).is.calledOnce;
expect(setTrigger).is.calledAfter(createV2Function);
Expand All @@ -1249,9 +1241,10 @@ describe("Fabricator", () => {
const createV1Function = sinon.stub(fab, "createV1Function");
createV1Function.rejects(new reporter.DeploymentError(ep, "set invoker", undefined));

await expect(
fab.createEndpoint(ep, new scraper.SourceTokenScraper(), new scraper.SourceTokenScraper())
).to.be.rejectedWith(reporter.DeploymentError, "set invoker");
await expect(fab.createEndpoint(ep, new scraper.SourceTokenScraper())).to.be.rejectedWith(
reporter.DeploymentError,
"set invoker"
);
expect(createV1Function).is.calledOnce;
expect(setTrigger).is.not.called;
});
Expand All @@ -1265,11 +1258,7 @@ describe("Fabricator", () => {
const updateV1Function = sinon.stub(fab, "updateV1Function");
updateV1Function.resolves();

await fab.updateEndpoint(
{ endpoint: ep },
new scraper.SourceTokenScraper(),
new scraper.SourceTokenScraper()
);
await fab.updateEndpoint({ endpoint: ep }, new scraper.SourceTokenScraper());
expect(updateV1Function).is.calledOnce;
expect(setTrigger).is.calledOnce;
expect(setTrigger).is.calledAfter(updateV1Function);
Expand All @@ -1282,11 +1271,7 @@ describe("Fabricator", () => {
const updateV2Function = sinon.stub(fab, "updateV2Function");
updateV2Function.resolves();

await fab.updateEndpoint(
{ endpoint: ep },
new scraper.SourceTokenScraper(),
new scraper.SourceTokenScraper()
);
await fab.updateEndpoint({ endpoint: ep }, new scraper.SourceTokenScraper());
expect(updateV2Function).is.calledOnce;
expect(setTrigger).is.calledOnce;
expect(setTrigger).is.calledAfter(updateV2Function);
Expand All @@ -1299,11 +1284,7 @@ describe("Fabricator", () => {
updateV1Function.rejects(new reporter.DeploymentError(ep, "set invoker", undefined));

await expect(
fab.updateEndpoint(
{ endpoint: ep },
new scraper.SourceTokenScraper(),
new scraper.SourceTokenScraper()
)
fab.updateEndpoint({ endpoint: ep }, new scraper.SourceTokenScraper())
).to.be.rejectedWith(reporter.DeploymentError, "set invoker");
expect(updateV1Function).is.calledOnce;
expect(setTrigger).is.not.called;
Expand Down Expand Up @@ -1332,11 +1313,7 @@ describe("Fabricator", () => {
const createV2Function = sinon.stub(fab, "createV2Function");
createV2Function.resolves();

await fab.updateEndpoint(
update,
new scraper.SourceTokenScraper(),
new scraper.SourceTokenScraper()
);
await fab.updateEndpoint(update, new scraper.SourceTokenScraper());

expect(deleteTrigger).to.have.been.called;
expect(deleteV1Function).to.have.been.calledImmediatelyAfter(deleteTrigger);
Expand Down

0 comments on commit d2cd8e3

Please sign in to comment.