Skip to content

Commit

Permalink
Update cleanupResources workflow to check for deletionProtection (#279)
Browse files Browse the repository at this point in the history
## Problem

Currently, the `cleanupResources` script
[fails](https://github.com/pinecone-io/pinecone-ts-client/actions/runs/10623637432/job/29452705669?pr=278)
to delete some indexes that spin up during our integration test suite
because some of these indexes have `deletionProtection` `enabled`.

## Solution

Check for `deletionProtection` being `enabled`; if it is, set it to
`disabled`.

## Type of Change

- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update
- [ ] Infrastructure change (CI configs, etc)
- [ ] Non-code change (docs, etc)
- [ ] None of the above: (explain here)

## Test Plan

CI passes

---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
  - https://app.asana.com/0/0/1208192096733434
  - https://app.asana.com/0/0/1208186698556887
  • Loading branch information
aulorbe authored Aug 30, 2024
1 parent 2930bcf commit eec04fb
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
1 change: 0 additions & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ jobs:
CI: true
PINECONE_API_KEY: ${{ secrets.PINECONE_API_KEY }}
run: npm run test:integration:cleanup

typescript-compilation-tests:
name: TS compile
runs-on: ubuntu-latest
Expand Down
37 changes: 25 additions & 12 deletions utils/cleanupResources.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
var dotenv = require('dotenv');
const dotenv = require('dotenv');

const pinecone = require('../dist');

dotenv.config();

for (const envVar of ['PINECONE_API_KEY']) {
Expand All @@ -8,23 +11,33 @@ for (const envVar of ['PINECONE_API_KEY']) {
console.log(`INFO Found environment variable ${envVar} in .env file`);
}
}

var pinecone = require('../dist');

(async () => {
const p = new pinecone.Pinecone();

const collectionList = await p.listCollections();
for (const collection of collectionList.collections) {
console.log(`Deleting collection ${collection.name}`);
await p.deleteCollection(collection.name);
if (collectionList.collections) {
for (const collection of collectionList.collections) {
console.log(`Deleting collection ${collection.name}`);
await p.deleteCollection(collection.name);
}
}

const response = await p.listIndexes();
for (const index of response.indexes) {
console.log(`Deleting index ${index.name}`);
await p.deleteIndex(index.name);
if (response.indexes) {
for (const index of response.indexes) {
if (index.deletionProtection === 'enabled') {
console.log(
'Changing deletionProtection status for index...',
index.name
);
await p.configureIndex(index.name, { deletionProtection: 'disabled' });
console.log(`Deleting index ${index.name}...`);
await p.deleteIndex(index.name);
} else {
console.log(`Deleting index ${index.name}`);
await p.deleteIndex(index.name);
}
}
process.exit();
}

process.exit();
})();
6 changes: 3 additions & 3 deletions utils/replInit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// and import top level exports of the built version of the library so it can be easily used for
// manual testing. It will typically be invoked via `npm run repl`.

var dotenv = require('dotenv');
const dotenv = require('dotenv');
dotenv.config();

const expectedVars = ['PINECONE_API_KEY'];
Expand All @@ -14,8 +14,8 @@ for (const envVar of expectedVars) {
}
}

var myrepl = require('repl').start();
var pinecone = require('../dist');
const myrepl = require('repl').start();
const pinecone = require('../dist');

// Automatically import all top-level exports from the built version of the library.
for (const [key, value] of Object.entries(pinecone)) {
Expand Down

0 comments on commit eec04fb

Please sign in to comment.