MCPcopy
hub / github.com/cortexlabs/cortex / setLifecycleRulesOnClusterUp

Function setLifecycleRulesOnClusterUp

cli/cmd/cluster.go:1291–1333  ·  view source on GitHub ↗
(awsClient *awslib.Client, bucket, newClusterUID string)

Source from the content-addressed store, hash-verified

1289}
1290
1291func setLifecycleRulesOnClusterUp(awsClient *awslib.Client, bucket, newClusterUID string) error {
1292 err := awsClient.DeleteLifecycleRules(bucket)
1293 if err != nil {
1294 return err
1295 }
1296
1297 clusterUIDs, err := awsClient.ListS3TopLevelDirs(bucket)
1298 if err != nil {
1299 return err
1300 }
1301
1302 if len(clusterUIDs)+1 > consts.MaxBucketLifecycleRules {
1303 return ErrorClusterUIDsLimitInBucket(bucket)
1304 }
1305
1306 expirationDate := libtime.GetCurrentUTCDate().Add(-24 * time.Hour)
1307 rules := []s3.LifecycleRule{}
1308 for _, clusterUID := range clusterUIDs {
1309 rules = append(rules, s3.LifecycleRule{
1310 Expiration: &s3.LifecycleExpiration{
1311 Date: &expirationDate,
1312 },
1313 ID: pointer.String("cluster-remove-" + clusterUID),
1314 Filter: &s3.LifecycleRuleFilter{
1315 Prefix: pointer.String(s.EnsureSuffix(clusterUID, "/")),
1316 },
1317 Status: pointer.String("Enabled"),
1318 })
1319 }
1320
1321 rules = append(rules, s3.LifecycleRule{
1322 Expiration: &s3.LifecycleExpiration{
1323 Days: pointer.Int64(consts.AsyncWorkloadsExpirationDays),
1324 },
1325 ID: pointer.String("async-workloads-expiry-policy"),
1326 Filter: &s3.LifecycleRuleFilter{
1327 Prefix: pointer.String(s.EnsureSuffix(filepath.Join(newClusterUID, "workloads"), "/")),
1328 },
1329 Status: pointer.String("Enabled"),
1330 })
1331
1332 return awsClient.SetLifecycleRules(bucket, rules)
1333}
1334
1335func setLifecycleRulesOnClusterDown(awsClient *awslib.Client, bucket string) error {
1336 err := awsClient.DeleteLifecycleRules(bucket)

Callers 1

cluster.goFile · 0.85

Calls 7

StringFunction · 0.92
Int64Function · 0.92
DeleteLifecycleRulesMethod · 0.80
ListS3TopLevelDirsMethod · 0.80
SetLifecycleRulesMethod · 0.80
AddMethod · 0.45

Tested by

no test coverage detected