From eec04fb88f514733cfee7a1aa887a92abb56a894 Mon Sep 17 00:00:00 2001 From: Audrey Sage Lorberfeld Date: Fri, 30 Aug 2024 16:30:00 -0700 Subject: [PATCH] Update cleanupResources workflow to check for deletionProtection (#279) ## 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 --- .github/workflows/testing.yml | 1 - utils/cleanupResources.ts | 37 +++++++++++++++++++++++------------ utils/replInit.ts | 6 +++--- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index cbb38f1f..1de747e2 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -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 diff --git a/utils/cleanupResources.ts b/utils/cleanupResources.ts index a76a9f4b..a419c1a0 100644 --- a/utils/cleanupResources.ts +++ b/utils/cleanupResources.ts @@ -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']) { @@ -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(); })(); diff --git a/utils/replInit.ts b/utils/replInit.ts index 350b1e40..169ebf0f 100644 --- a/utils/replInit.ts +++ b/utils/replInit.ts @@ -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']; @@ -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)) {