Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pagination for cleanup snapshots #247

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 42 additions & 4 deletions vars/washeryCleanSnapshots.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,52 @@ def call(body) {
}
}

@NonCPS
def getAllDBSnapshots(client, request) {
def allSnapshots = []
def marker = null

while (true) {
request.setMarker(marker)
def snapshotsResult = client.describeDBSnapshots(request)
def snapshots = snapshotsResult.getDBSnapshots()

allSnapshots.addAll(snapshots)

marker = snapshotsResult.getMarker()
if (marker == null) {
break
}
}

return allSnapshots
}

@NonCPS
def getAllDBClusterSnapshots(client, request) {
def allSnapshots = []
def marker = null

while (true) {
request.setMarker(marker)
def snapshotsResult = client.describeDBClusterSnapshots(request)
def snapshots = snapshotsResult.getDBClusterSnapshots()
allSnapshots.addAll(snapshots)
marker = snapshotsResult.getMarker()
if (marker == null) {
break
}
}

return allSnapshots
}

@NonCPS
def cleanInstanceWasherySnapshots(client, snapshotRetainCount, dryRun){
//RDS Instance
def request = new DescribeDBSnapshotsRequest()
.withSnapshotType("manual")
def snapshotsResult = client.describeDBSnapshots(request)
def snapshots = snapshotsResult.getDBSnapshots()
def snapshots = getAllDBSnapshots(client, request)
def washerySnapshots = []

//Retrieve snapshots prefixed with `washery-scrubbed`
Expand Down Expand Up @@ -87,8 +126,7 @@ def cleanClusterWasherySnapshots(client, snapshotRetainCount, dryRun){
//RDS Cluster
def request = new DescribeDBClusterSnapshotsRequest()
.withSnapshotType("manual")
def snapshotsResult = client.describeDBClusterSnapshots(request)
def snapshots = snapshotsResult.getDBClusterSnapshots()
def snapshots = getAllDBClusterSnapshots(client, request)
def washerySnapshots = []

//Retrieve snapshots prefixed with `washery-scrubbed`
Expand Down