Skip to content

Commit

Permalink
fix: rds and docdb snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
MacLikorne committed Nov 29, 2021
1 parent 0558f1d commit c2c2101
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 9 deletions.
4 changes: 2 additions & 2 deletions charts/pleco/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ name: pleco
description: Automatically removes Cloud managed services and Kubernetes resources based on tags with TTL
type: application
home: https://github.com/Qovery/pleco
version: 0.9.23
appVersion: 0.9.23
version: 0.9.24
appVersion: 0.9.24
icon: https://github.com/Qovery/pleco/raw/main/assets/pleco_logo.png
2 changes: 1 addition & 1 deletion charts/pleco/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ replicaCount: 1
image:
repository: qoveryrd/pleco
pullPolicy: IfNotPresent
plecoImageTag: "0.9.23"
plecoImageTag: "0.9.24"

cloudProvider: ""

Expand Down
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ func init() {
}

func GetCurrentVersion() string {
return "0.9.23" // ci-version-check
return "0.9.24" // ci-version-check
}
8 changes: 5 additions & 3 deletions pkg/aws/db_documentdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func DeleteExpiredDocumentDBClusters(sessions AWSSessions, options AwsOptions) {
}

func listClusterSnapshots(svc rds.RDS) []*rds.DBClusterSnapshot {
result, err := svc.DescribeDBClusterSnapshots(&rds.DescribeDBClusterSnapshotsInput{})
result, err := svc.DescribeDBClusterSnapshots(&rds.DescribeDBClusterSnapshotsInput{SnapshotType: aws.String("manual")})

if err != nil {
log.Errorf("Can't list RDS snapshots in region %s: %s", *svc.Config.Region, err.Error())
Expand All @@ -142,7 +142,7 @@ func getExpiredClusterSnapshots(svc rds.RDS) []*rds.DBClusterSnapshot {

if len(dbs) == 0 {
for _, snap := range snaps {
if snap.SnapshotCreateTime.Before(time.Now().UTC().Add(3 * time.Hour)) {
if snap.SnapshotCreateTime.Before(time.Now().UTC().Add(3 * time.Hour)) && common.CheckClusterSnapshot(snap) {
expiredSnaps = append(expiredSnaps, snap)
}
}
Expand All @@ -152,7 +152,9 @@ func getExpiredClusterSnapshots(svc rds.RDS) []*rds.DBClusterSnapshot {

snapsChecking := make(map[string]*rds.DBClusterSnapshot)
for _, snap := range snaps {
snapsChecking[*snap.DBClusterSnapshotIdentifier] = snap
if common.CheckClusterSnapshot(snap) {
snapsChecking[*snap.DBClusterSnapshotIdentifier] = snap
}
}

for _, db := range dbs {
Expand Down
7 changes: 5 additions & 2 deletions pkg/aws/db_rds.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func DeleteExpiredCompleteRDSParameterGroups(sessions AWSSessions, options AwsOp
}

func listSnapshots(svc rds.RDS) []*rds.DBSnapshot {
result, err := svc.DescribeDBSnapshots(&rds.DescribeDBSnapshotsInput{})
result, err := svc.DescribeDBSnapshots(&rds.DescribeDBSnapshotsInput{SnapshotType: aws.String("manual")})

if err != nil {
log.Errorf("Can't list RDS snapshots in region %s: %s", *svc.Config.Region, err.Error())
Expand All @@ -345,7 +345,7 @@ func getExpiredSnapshots(svc rds.RDS) []*rds.DBSnapshot {

if len(dbs) == 0 {
for _, snap := range snaps {
if snap.SnapshotCreateTime.Before(time.Now().UTC().Add(3 * time.Hour)) {
if snap.SnapshotCreateTime.Before(time.Now().UTC().Add(3 * time.Hour)) && common.CheckSnapshot(snap) {
expiredSnaps = append(expiredSnaps, snap)
}
}
Expand All @@ -355,6 +355,9 @@ func getExpiredSnapshots(svc rds.RDS) []*rds.DBSnapshot {

snapsChecking := make(map[string]*rds.DBSnapshot)
for _, snap := range snaps {
if common.CheckSnapshot(snap) {
snapsChecking[*snap.DBSnapshotIdentifier] = snap
}
snapsChecking[*snap.DBSnapshotIdentifier] = snap
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/common/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,11 @@ func stringDateToTimeDate(date string) time.Time {

return time.Date(int(year), time.Month(month), int(day), int(hour), int(minutes), int(seconds), 0, time.UTC)
}

func CheckSnapshot(snap *rds.DBSnapshot) bool {
return !strings.Contains(*snap.Status, "") && strings.Contains(*snap.DBSnapshotIdentifier, "default:")
}

func CheckClusterSnapshot(snap *rds.DBClusterSnapshot) bool {
return !strings.Contains(*snap.Status, "") && strings.Contains(*snap.DBClusterSnapshotIdentifier, "default:")
}

0 comments on commit c2c2101

Please sign in to comment.