Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
66a83c5
new generated code, updating version to 0.8.0
alexander-fenster Dec 13, 2017
47b82eb
Better readme and quickstart (#4)
alexander-fenster Dec 15, 2017
d5a235c
Upgrade repo-tools and regenerate scaffolding. (#19)
jmdobry Mar 16, 2018
39dd755
v0.2.0 (#20)
callmehiphop May 1, 2018
1151e1e
chore: lock files maintenance (#24)
alexander-fenster May 2, 2018
74be623
chore: lock files maintenance (#26)
alexander-fenster May 8, 2018
aa0a486
chore: lock files maintenance (#29)
alexander-fenster May 22, 2018
a73b07f
chore: update sample lockfiles (#38)
JustinBeckwith Jun 25, 2018
514a418
chore(deps): update dependency @google-cloud/nodejs-repo-tools to v2.…
renovate[bot] Jun 27, 2018
6ba06de
chore(deps): lock file maintenance (#44)
renovate[bot] Jul 3, 2018
8d10a63
chore(deps): lock file maintenance (#47)
renovate[bot] Jul 10, 2018
1fc3ae1
fix: drop support for node.js 4.x and 9.x (#46)
JustinBeckwith Jul 10, 2018
78e84b5
chore(deps): lock file maintenance (#48)
renovate[bot] Jul 10, 2018
3eb8040
chore(deps): lock file maintenance (#49)
renovate[bot] Jul 10, 2018
595a11d
chore(deps): lock file maintenance (#51)
renovate[bot] Jul 17, 2018
2c29594
chore(deps): lock file maintenance (#54)
renovate[bot] Jul 24, 2018
a7fc57d
chore: require node 8 for samples (#56)
JustinBeckwith Jul 30, 2018
18dfbfb
chore(deps): lock file maintenance (#57)
renovate[bot] Jul 31, 2018
a62d4a9
chore(deps): lock file maintenance (#61)
renovate[bot] Aug 7, 2018
433b0be
chore: ignore package-lock.json (#63)
JustinBeckwith Aug 7, 2018
0d71c94
Remove unused dependencies (#72)
JustinBeckwith Sep 5, 2018
8066392
chore(deps): update dependency @google-cloud/nodejs-repo-tools to v3 …
renovate[bot] Nov 10, 2018
53b0368
docs(samples): updated samples code to use async await (#122)
praveenqlogic Nov 22, 2018
0e2b531
Release v0.3.0 (#141)
jkwlui Dec 11, 2018
093d07a
test: add sample tests (#143)
JustinBeckwith Dec 17, 2018
21d1467
chore(deps): update dependency mocha to v6
renovate[bot] Feb 19, 2019
db0df82
Release v0.3.1 (#168)
JustinBeckwith Mar 12, 2019
7cdb465
refactor: use execSync for tests (#176)
JustinBeckwith Apr 4, 2019
aaa87d1
refactor: wrap execSync with encoding: utf-8 (#177)
jkwlui Apr 5, 2019
30f94ba
chore: release 1.0.0 (#193)
May 13, 2019
dde01b2
refactor: use repo-metadata to generate readme (#196)
JustinBeckwith May 21, 2019
8af8479
chore: release 1.1.0 (#204)
yoshi-automation Jun 5, 2019
27a253f
chore: release 1.1.1 (#206)
yoshi-automation Jun 14, 2019
30ea559
chore: release 1.1.2 (#209)
yoshi-automation Jun 21, 2019
a8a35b1
chore: release 1.1.3 (#211)
yoshi-automation Jun 26, 2019
752e0da
chore: release 1.1.4 (#222)
yoshi-automation Aug 28, 2019
eb11be0
chore: release 1.2.0 (#225)
yoshi-automation Sep 16, 2019
f6f1d4a
chore: release 1.3.1 (#241)
release-please[bot] Oct 22, 2019
f31e213
chore: release 1.4.0 (#248)
release-please[bot] Nov 15, 2019
08ebe14
chore: update license headers
JustinBeckwith Nov 25, 2019
ae160c5
refactor: use explicit mocha imports
JustinBeckwith Dec 30, 2019
8459db4
chore(deps): update dependency mocha to v7 (#269)
renovate-bot Jan 6, 2020
b22613b
chore: release 1.5.0
release-please[bot] Jan 6, 2020
22d2478
chore: release 1.6.0 (#274)
release-please[bot] Jan 28, 2020
28c0163
chore: release 1.6.1 (#278)
release-please[bot] Jan 28, 2020
3321925
chore: release 1.6.2 (#287)
release-please[bot] Feb 10, 2020
efc9eec
chore: release 1.7.0 (#296)
release-please[bot] Mar 12, 2020
745de9c
chore: release 2.0.0 (#319)
release-please[bot] Jun 4, 2020
8a0c8f7
chore(deps): update dependency mocha to v8 (#349)
renovate-bot Jun 11, 2020
ed1af4d
chore: release 2.1.0 (#348)
release-please[bot] Jun 16, 2020
4f14490
chore: release 2.1.1 (#359)
release-please[bot] Jul 10, 2020
5ebc25c
chore: release 2.1.2 (#399)
release-please[bot] Nov 11, 2020
2758878
chore: release 2.2.0 (#402)
release-please[bot] Dec 2, 2020
9c56e21
chore: release 2.2.1 (#432)
release-please[bot] May 13, 2021
1eb93fb
chore: release 2.2.2 (#442)
release-please[bot] May 25, 2021
b678cf8
chore: release 2.3.0 (#447)
release-please[bot] Jun 9, 2021
137ff7b
chore: release 2.3.1 (#456)
release-please[bot] Jun 28, 2021
2a9c182
chore: release 2.3.2 (#461)
release-please[bot] Jun 30, 2021
7436f4c
chore: release 2.4.0 (#465)
release-please[bot] Jul 9, 2021
811ceed
chore: release 2.4.1 (#467)
release-please[bot] Jul 12, 2021
3c67c14
chore: release 2.4.2 (#469)
release-please[bot] Jul 16, 2021
100ff4c
chore: release 2.4.3 (#478)
release-please[bot] Aug 16, 2021
9fe51f2
chore: release 2.4.4 (#479)
release-please[bot] Aug 17, 2021
b942fec
chore: release 2.5.0 (#481)
release-please[bot] Aug 23, 2021
550ae6a
docs(samples): add auto-generated Node samples (#488)
gcf-owl-bot[bot] Sep 24, 2021
667b184
chore: release 2.6.0 (#498)
release-please[bot] Dec 9, 2021
b2c7e9f
docs(samples): add usage samples to show handling of LRO response Ope…
Shabirmean Feb 17, 2022
40f7283
chore(main): release 3.0.0 (#511)
release-please[bot] Feb 26, 2022
a2506e6
chore(main): release 3.0.1 (#529)
release-please[bot] May 6, 2022
a8ecff7
build!: update library to use Node 12 (#539)
sofisl May 20, 2022
ba8f064
chore(main): release 4.0.0 (#540)
release-please[bot] May 24, 2022
50db079
chore(main): release 4.0.1 (#542)
release-please[bot] Jun 20, 2022
bab2176
chore(main): release 4.1.0 (#550)
release-please[bot] Jul 4, 2022
f289ade
chore(main): release 4.1.1 (#559)
release-please[bot] Aug 29, 2022
8ee8bfa
chore(main): release 4.1.2 (#565)
release-please[bot] Sep 8, 2022
cfb6cbe
fix(deps): update dependency uuid to v9 (#564)
renovate-bot Sep 8, 2022
a57bd29
build: skip flaky tests if flaky (#567)
sofisl Sep 13, 2022
8c43a11
chore(main): release 4.1.3 (#566)
release-please[bot] Sep 14, 2022
4771ee7
chore(main): release 4.2.0 (#569)
release-please[bot] Sep 26, 2022
b3b1f5b
chore(main): release 4.3.0 (#579)
release-please[bot] Oct 17, 2022
9dbb22b
chore(main): release 4.4.0 (#584)
release-please[bot] Nov 11, 2022
2c18f74
Merge remote-tracking branch 'migration/main' into nodejs-cloud-conta…
grayside Nov 16, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions container/snippets/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "nodejs-docs-samples-container",
"license": "Apache-2.0",
"author": "Google Inc.",
"engines": {
"node": ">=12.0.0"
},
"repository": "googleapis/nodejs-cloud-container",
"private": true,
"files": [
"*.js"
],
"scripts": {
"test": "mocha system-test --timeout 1000000"
},
"dependencies": {
"@google-cloud/container": "^4.4.0",
"uuid": "^9.0.0"
},
"devDependencies": {
"chai": "^4.2.0",
"mocha": "^8.0.0"
}
}
41 changes: 41 additions & 0 deletions container/snippets/quickstart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright 2017 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

// [START gke_list_cluster]
async function main() {
// [START container_quickstart]
const container = require('@google-cloud/container');

// Create the Cluster Manager Client
const client = new container.v1.ClusterManagerClient();

async function quickstart() {
const zone = 'us-central1-a';
const projectId = await client.getProjectId();
const request = {
projectId: projectId,
zone: zone,
};

const [response] = await client.listClusters(request);
console.log('Clusters: ', response);
}
quickstart();
// [END container_quickstart]
}

main().catch(console.error);
// [END gke_list_cluster]
91 changes: 91 additions & 0 deletions container/snippets/system-test/create_cluster.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

const {assert, expect} = require('chai');
const {describe, it, before, after} = require('mocha');
const uuid = require('uuid');
const cp = require('child_process');
const container = require('@google-cloud/container');
const untilDone = require('./test_util.js');

const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
const zones = [
'us-central1-a',
'us-central1-b',
'us-central1-c',
'us-central1-f',
];
const randomZone = zones[Math.floor(Math.random() * zones.length)];
const randomUUID = uuid.v1().substring(0, 8);
const randomClusterName = `nodejs-container-test-${randomUUID}`;
const client = new container.v1.ClusterManagerClient();
const ciNetwork = 'default-compute';
let projectId;
let clusterLocation;

// create a new cluster to test the delete sample on
before(async () => {
projectId = await client.getProjectId();
clusterLocation = `projects/${projectId}/locations/${randomZone}`;
});

// clean up the cluster regardless of whether the test passed or not
after(async () => {
const request = {name: `${clusterLocation}/clusters/${randomClusterName}`};
const [deleteOperation] = await client.deleteCluster(request);
const opIdentifier = `${clusterLocation}/operations/${deleteOperation.name}`;
await untilDone(client, opIdentifier);
});

describe('container samples - create cluster long running op', () => {
it('should create cluster and wait for completion, and see the cluster in list', async () => {
let stdout;
let test = true;
try {
stdout = execSync(
`node create_cluster.js ${randomClusterName} ${randomZone} ${ciNetwork}`
);
} catch (err) {
if (
err
.toString()
.includes('7 PERMISSION_DENIED: Insufficient regional quota')
) {
test = false;
} else {
throw err;
}
}

if (test) {
assert.match(
stdout,
/Cluster creation not complete. will try after .* delay/
);
assert.match(stdout, /Cluster creation completed./);

const [response] = await client.listClusters({
projectId: projectId,
zone: randomZone,
});
const clustersList = response.clusters.reduce(
(acc, curr) => [curr.name, ...acc],
[]
);
expect(clustersList).to.include(randomClusterName);
}
});
});
115 changes: 115 additions & 0 deletions container/snippets/system-test/delete_cluster.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

const {assert, expect} = require('chai');
const {describe, it, after, before} = require('mocha');
const uuid = require('uuid');
const cp = require('child_process');
const container = require('@google-cloud/container');
const untilDone = require('./test_util.js');

const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
const zones = [
'us-central1-a',
'us-central1-b',
'us-central1-c',
'us-central1-f',
];
const randomZone = zones[Math.floor(Math.random() * zones.length)];
const randomUUID = uuid.v1().substring(0, 8);
const randomClusterName = `nodejs-container-test-${randomUUID}`;
const client = new container.v1.ClusterManagerClient();
const ciNetwork = 'default-compute';
let projectId;
let clusterLocation;
let test = true;

// create a new cluster to test the delete sample on
before(async () => {
projectId = await client.getProjectId();
clusterLocation = `projects/${projectId}/locations/${randomZone}`;
const request = {
parent: clusterLocation,
cluster: {
name: randomClusterName,
network: ciNetwork,
initialNodeCount: 2,
nodeConfig: {machineType: 'e2-standard-2'},
},
};
let createOperation;
let opIdentifier;
try {
[createOperation] = await client.createCluster(request);
opIdentifier = `${clusterLocation}/operations/${createOperation.name}`;
await untilDone(client, opIdentifier);
} catch (err) {
if (
err
.toString()
.includes('7 PERMISSION_DENIED: Insufficient regional quota')
) {
test = false;
} else {
throw err;
}
}
});

// clean up the cluster regardless of whether the test passed or not
after(async () => {
const request = {name: `${clusterLocation}/clusters/${randomClusterName}`};
try {
const [deleteOperation] = await client.deleteCluster(request);
const opIdentifier = `${clusterLocation}/operations/${deleteOperation.name}`;
await untilDone(client, opIdentifier);
} catch (ex) {
// Error code 5 is NOT_FOUND meaning the cluster was deleted during the test
if (ex.code === 5) {
return;
}
}
});

// run the tests
describe('container samples - delete cluster long running op', () => {
it('should delete cluster and wait for completion', async () => {
if (test) {
const stdout = execSync(
`node delete_cluster.js ${randomClusterName} ${randomZone}`
);
assert.match(
stdout,
/Cluster deletion not complete. will try after .* delay/
);
assert.match(stdout, /Cluster deletion completed./);
}
});

it('should not see the deleted cluster in the list', async () => {
if (test) {
const [response] = await client.listClusters({
projectId: projectId,
zone: randomZone,
});
const clustersList = response.clusters.reduce(
(acc, curr) => [curr.name, ...acc],
[]
);
expect(clustersList).to.not.include(randomClusterName);
}
});
});
28 changes: 28 additions & 0 deletions container/snippets/system-test/quicktest.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2017 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

const {assert} = require('chai');
const {describe, it} = require('mocha');
const cp = require('child_process');

const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});

describe('container samples - quickstart', () => {
it('should run the quickstart', async () => {
const stdout = execSync('node quickstart');
assert.match(stdout, /Clusters:/);
});
});
66 changes: 66 additions & 0 deletions container/snippets/system-test/test_util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Copyright 2022 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

'use strict';

const container = require('@google-cloud/container');
const STATUS_ENUM = container.protos.google.container.v1.Operation.Status;

const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
const maxRetries = 20;
let retryCount;
let prevDelay;
let currDelay;

/**
* We use a custom wait and retry method for the test cases, which is different
* from the approach we have for the samples itself. The samples use an async
* function with delayed setIntervals. Since, the last function call of the
* samples is the wait for the long running operation to complete, the program
* waits until the delayed setInterval async functions resolve.
*
* However, when running the tests we have certain setup to be done in the
* before() hook which are also long running operations. We would want to block
* until these setup steps are fully complete before allowing for the tests to
* start. If we use the same approach used in the samples (with an async
* function scheduled on setIntervals), the before() hook will not block. Rather
* it will return and the tests will start running.
*
* To prevent this scenario, we have employed a sleep based retry and wait
* method below to be used only for the test cases.
*
* @param {container.v1.ClusterManagerClient} client the google cloud API client used to submit the request
* @param {string} opIdentifier the unique identifier of the operation we want to check
*/
async function retryUntilDone(client, opIdentifier) {
retryCount = 0;
prevDelay = 0;
currDelay = 1000;

while (retryCount <= maxRetries) {
const [longRunningOp] = await client.getOperation({name: opIdentifier});
const status = longRunningOp.status;
if (status !== STATUS_ENUM[STATUS_ENUM.DONE]) {
const fibonacciDelay = prevDelay + currDelay;
prevDelay = currDelay;
currDelay = fibonacciDelay;
await sleep(fibonacciDelay);
} else {
break;
}
retryCount += 1;
}
}

module.exports = retryUntilDone;