-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: use aws-sdk to increase aws support in eks pods
When running in EKS pod with a ServeAccount trusted by an IAM role, the application can get credentials directly from the SA to call AWS API.
- Loading branch information
1 parent
0d8026c
commit 646f752
Showing
13 changed files
with
1,331 additions
and
248 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,53 @@ | ||
import { | ||
HeadBucketCommand, | ||
CreateBucketCommand, | ||
DeleteBucketCommand, | ||
DeleteObjectsCommand, | ||
ListObjectsV2Command, | ||
} from '@aws-sdk/client-s3'; | ||
import config from '../../server/core/config'; | ||
import { minioClient } from '../../server/core/storage'; | ||
import { client } from '../../server/core/storage'; | ||
|
||
const { bucket } = config.storage; | ||
|
||
const emptyBucket = async (): Promise<void> => { | ||
const stream = await minioClient.listObjectsV2(bucket, '', true); | ||
|
||
return new Promise((resolve, reject) => { | ||
const objectNames = []; | ||
|
||
stream.on('data', object => { | ||
objectNames.push(object.name); | ||
}); | ||
|
||
stream.on('error', reject); | ||
|
||
stream.on('end', async () => { | ||
if (objectNames.length) { | ||
await minioClient.removeObjects(bucket, objectNames); | ||
} | ||
|
||
resolve(); | ||
}); | ||
}); | ||
const listObjectsResponse = await client.send(new ListObjectsV2Command({ Bucket: bucket })); | ||
|
||
const objectNames = listObjectsResponse.Contents.map(object => object.Key).filter(Boolean); | ||
|
||
if (objectNames.length) { | ||
await client.send( | ||
new DeleteObjectsCommand({ | ||
Bucket: bucket, | ||
Delete: { | ||
Objects: objectNames.map(objectName => ({ Key: objectName })), | ||
}, | ||
}) | ||
); | ||
} | ||
}; | ||
|
||
// eslint-disable-next-line import/prefer-default-export | ||
export const setupEmptyBucket = async (): Promise<void> => { | ||
const alreadyExist = await minioClient.bucketExists(bucket); | ||
const alreadyExist = await (async () => { | ||
try { | ||
// simply look for the head bucket | ||
await client.send(new HeadBucketCommand({ Bucket: bucket })); | ||
|
||
return true; | ||
} catch (error) { | ||
console.error(await error); | ||
|
||
// for testing purpose we can assume if an error happen the bucket does not exist | ||
return false; | ||
} | ||
})(); | ||
|
||
if (alreadyExist) { | ||
await emptyBucket(); | ||
await minioClient.removeBucket(bucket); | ||
const x = await client.send(new DeleteBucketCommand({ Bucket: bucket })); | ||
console.info(x); | ||
} | ||
|
||
await minioClient.makeBucket(bucket, config.storage.provider.region); | ||
await client.send(new CreateBucketCommand({ Bucket: bucket })); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.