Skip to content

Commit 4ea8418

Browse files
authored
fix: Fix handling of maxInstances setting (#199)
1 parent 3229c49 commit 4ea8418

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

package/lib/compileFunctions.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ module.exports = {
5555
});
5656
}
5757

58-
funcTemplate.properties.maxInstances = funcObject.maxInstances;
58+
if (funcObject.maxInstances) {
59+
funcTemplate.properties.maxInstances = funcObject.maxInstances;
60+
}
5961

6062
if (!_.size(funcTemplate.properties.environmentVariables)) {
6163
delete funcTemplate.properties.environmentVariables;

package/lib/compileFunctions.test.js

+65
Original file line numberDiff line numberDiff line change
@@ -683,5 +683,70 @@ describe('CompileFunctions', () => {
683683
).toEqual(compiledResources);
684684
});
685685
});
686+
687+
it('should not require max instances on each function configuration', () => {
688+
googlePackage.serverless.service.functions = {
689+
func1: {
690+
handler: 'func1',
691+
memorySize: 128,
692+
runtime: 'nodejs8',
693+
vpc: 'projects/pg-us-n-app-123456/locations/us-central1/connectors/my-vpc',
694+
events: [{ http: 'foo' }],
695+
},
696+
func2: {
697+
handler: 'func2',
698+
memorySize: 128,
699+
runtime: 'nodejs8',
700+
maxInstances: 10,
701+
vpc: 'projects/pg-us-n-app-123456/locations/us-central1/connectors/my-vpc',
702+
events: [{ http: 'bar' }],
703+
},
704+
};
705+
706+
const compiledResources = [
707+
{
708+
type: 'cloudfunctions.v1beta2.function',
709+
name: 'my-service-dev-func1',
710+
properties: {
711+
location: 'us-central1',
712+
runtime: 'nodejs8',
713+
function: 'func1',
714+
availableMemoryMb: 128,
715+
timeout: '60s',
716+
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
717+
httpsTrigger: {
718+
url: 'foo',
719+
},
720+
labels: {},
721+
vpcConnector: 'projects/pg-us-n-app-123456/locations/us-central1/connectors/my-vpc',
722+
},
723+
},
724+
{
725+
type: 'cloudfunctions.v1beta2.function',
726+
name: 'my-service-dev-func2',
727+
properties: {
728+
location: 'us-central1',
729+
runtime: 'nodejs8',
730+
function: 'func2',
731+
availableMemoryMb: 128,
732+
timeout: '60s',
733+
maxInstances: 10,
734+
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
735+
httpsTrigger: {
736+
url: 'bar',
737+
},
738+
labels: {},
739+
vpcConnector: 'projects/pg-us-n-app-123456/locations/us-central1/connectors/my-vpc',
740+
},
741+
},
742+
];
743+
744+
return googlePackage.compileFunctions().then(() => {
745+
expect(consoleLogStub.called).toEqual(true);
746+
expect(
747+
googlePackage.serverless.service.provider.compiledConfigurationTemplate.resources
748+
).toEqual(compiledResources);
749+
});
750+
});
686751
});
687752
});

0 commit comments

Comments
 (0)