Skip to content
This repository was archived by the owner on Dec 9, 2024. It is now read-only.

Commit 82b19d7

Browse files
authored
waitForDeployment should also waits for service presence (#213)
1 parent 2253ce2 commit 82b19d7

File tree

4 files changed

+66
-6
lines changed

4 files changed

+66
-6
lines changed

lib/deploy.js

+30-5
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ function waitForDeployment(funcName, requestMoment, namespace, options) {
212212
let previousPodStatus = '';
213213
return new BbPromise((resolve, reject) => {
214214
const loop = setInterval(() => {
215-
if (retries > 3) {
215+
if (retries > 10) {
216216
opts.log(
217217
`Giving up, unable to retrieve the status of the ${funcName} deployment. `
218218
);
@@ -257,10 +257,35 @@ function waitForDeployment(funcName, requestMoment, namespace, options) {
257257
// The pods may be running for a short time
258258
// so we should ensure that they are stable
259259
successfulCount++;
260-
if (successfulCount === 2) {
261-
opts.log(`Function ${funcName} successfully deployed`);
262-
clearInterval(loop);
263-
resolve();
260+
if (successfulCount >= 2) {
261+
// The pod is running successfully. Check if the function service is ready
262+
core.ns.services.get((svcErr, svcsInfo) => {
263+
if (svcErr) {
264+
if (svcErr.message.match(/request timed out/)) {
265+
opts.log('Request timed out. Retrying...');
266+
} else {
267+
throw svcErr;
268+
}
269+
} else {
270+
// Get the svc for current function
271+
const functionSvcs = _.filter(
272+
svcsInfo.items,
273+
(svc) => (
274+
!_.isEmpty(svc.metadata.labels) &&
275+
svc.metadata.labels.function === funcName &&
276+
!svc.metadata.deletionTimestamp
277+
)
278+
);
279+
if (_.isEmpty(functionSvcs)) {
280+
retries++;
281+
opts.log(`Unable to find internal service for ${funcName}. Retrying...`);
282+
} else {
283+
opts.log(`Function ${funcName} successfully deployed`);
284+
clearInterval(loop);
285+
resolve();
286+
}
287+
}
288+
});
264289
}
265290
} else if (opts.verbose) {
266291
successfulCount = 0;

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-kubeless",
3-
"version": "0.10.0",
3+
"version": "0.10.1",
44
"description": "This plugin enables support for Kubeless within the [Serverless Framework](https://github.com/serverless).",
55
"main": "index.js",
66
"directories": {

test/kubelessDeploy.test.js

+22
Original file line numberDiff line numberDiff line change
@@ -1448,6 +1448,28 @@ describe('KubelessDeploy', () => {
14481448
},
14491449
}],
14501450
}));
1451+
nock(config.clusters[0].cluster.server)
1452+
.persist()
1453+
.get('/api/v1/namespaces/default/services')
1454+
.reply(200, () => ({
1455+
items: [
1456+
{
1457+
metadata: {
1458+
name: 'myFunction3',
1459+
labels: { function: 'myFunction3' },
1460+
annotations: {},
1461+
creationTimestamp: moment().add('60', 's'),
1462+
},
1463+
},
1464+
{
1465+
metadata: {
1466+
name: functionName,
1467+
labels: { function: functionName },
1468+
annotations: {},
1469+
creationTimestamp: moment().add('60', 's'),
1470+
},
1471+
}],
1472+
}));
14511473

14521474
// Call for myFunction1
14531475
mocks.createDeploymentNocks(config.clusters[0].cluster.server, functionName, funcSpec, {

test/lib/mocks.js

+13
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,19 @@ function createDeploymentNocks(endpoint, func, funcSpec, options) {
138138
},
139139
}],
140140
}));
141+
nock(endpoint)
142+
.persist()
143+
.get(`/api/v1/namespaces/${opts.namespace}/services`)
144+
.reply(200, JSON.stringify({
145+
items: [{
146+
metadata: {
147+
name: func,
148+
labels: { function: func },
149+
annotations: {},
150+
creationTimestamp: moment().add('60', 's'),
151+
},
152+
}],
153+
}));
141154
}
142155

143156
function createTriggerNocks(endpoint, func, hostname, p, options) {

0 commit comments

Comments
 (0)