Skip to content

Commit

Permalink
Add DBSnapshot size information to CreateRDSSnapshot function output (#…
Browse files Browse the repository at this point in the history
…1108)

* Add allocatedStorage info to output artifact for CreateRDSSnapshot func

* Add size in decimal format

* Add GiB unit to storage size
Add allocatedStorage as output artifact in RDS potgres snapshot blueprint
Update docs for CreateRDSSnapshot function

* Remove Unnecessary log

* Add allocatedStorage as output artifact in RDS aurora snapshot blueprint

* Update pkg/function/create_rds_snapshot.go

Co-authored-by: Prasad Ghangal <prasad.ghangal@gmail.com>

* Format go files

Co-authored-by: Prasad Ghangal <prasad.ghangal@gmail.com>
  • Loading branch information
akankshakumari393 and PrasadG193 committed Oct 7, 2021
1 parent 738d500 commit 54de77f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
2 changes: 2 additions & 0 deletions docs/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,7 @@ Outputs:
`snapshotID`,`string`, ID of the RDS snapshot that has been created
`instanceID`, `string`, ID of the RDS instance
`securityGroupID`, `[]string`, AWS Security Group IDs associated with the RDS instance
`allocatedStorage`, `string`, Specifies the allocated storage size in gibibytes (GiB)

Example:

Expand All @@ -974,6 +975,7 @@ Example:
snapshotID: "{{ .Phases.createSnapshot.Output.snapshotID }}"
instanceID: "{{ .Phases.createSnapshot.Output.instanceID }}"
securityGroupID: "{{ .Phases.createSnapshot.Output.securityGroupID }}"
allocatedStorage: "{{ .Phases.createSnapshot.Output.allocatedStorage }}"
backupID: "{{ .Phases.exportSnapshot.Output.backupID }}"
configMapNames:
- dbconfig
Expand Down
2 changes: 2 additions & 0 deletions docs/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ defaultProfile
Dockerfile
Elasticsearch
gcs
gibibytes
GiB
helm
kanctl
Kando
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ actions:
snapshotID: "{{ .Phases.createSnapshot.Output.snapshotID }}"
instanceID: "{{ .Phases.createSnapshot.Output.instanceID }}"
securityGroupID: "{{ .Phases.createSnapshot.Output.securityGroupID }}"
allocatedStorage: "{{ .Phases.createSnapshot.Output.allocatedStorage }}"
phases:
- func: CreateRDSSnapshot
name: createSnapshot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ actions:
snapshotID: "{{ .Phases.createSnapshot.Output.snapshotID }}"
instanceID: "{{ .Phases.createSnapshot.Output.instanceID }}"
securityGroupID: "{{ .Phases.createSnapshot.Output.securityGroupID }}"
allocatedStorage: "{{ .Phases.createSnapshot.Output.allocatedStorage }}"
phases:
- func: CreateRDSSnapshot
name: createSnapshot
Expand Down
17 changes: 13 additions & 4 deletions pkg/function/create_rds_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package function
import (
"context"
"fmt"
"strconv"

"github.com/ghodss/yaml"
"github.com/pkg/errors"
Expand Down Expand Up @@ -48,6 +49,8 @@ const (
CreateRDSSnapshotSnapshotID = "snapshotID"
// CreateRDSSnapshotSecurityGroupID to set securityGroupIDs in output artifact
CreateRDSSnapshotSecurityGroupID = "securityGroupID"
// Allocated Storage Amount
CreateRDSSnapshotAllocatedStorage = "allocatedStorage"
// DBEngineAurora has db engine aurora for MySQL 5.6-compatible
DBEngineAurora RDSDBEngine = "aurora"
// DBEngineAuroraMySQL has db engine for MySQL 5.7-compatible Aurora
Expand All @@ -63,6 +66,7 @@ func (*createRDSSnapshotFunc) Name() string {
}

func createRDSSnapshot(ctx context.Context, instanceID string, dbEngine RDSDBEngine, profile *param.Profile) (map[string]interface{}, error) {
var allocatedStorage int64
// Validate profile
if err := ValidateProfile(profile); err != nil {
return nil, errors.Wrap(err, "Profile Validation failed")
Expand All @@ -85,7 +89,8 @@ func createRDSSnapshot(ctx context.Context, instanceID string, dbEngine RDSDBEng

log.Print("Creating RDS snapshot", field.M{"SnapshotID": snapshotID})
if !isAuroraCluster(string(dbEngine)) {
if _, err := rdsCli.CreateDBSnapshot(ctx, instanceID, snapshotID); err != nil {
dbSnapshotOutput, err := rdsCli.CreateDBSnapshot(ctx, instanceID, snapshotID)
if err != nil {
return nil, errors.Wrap(err, "Failed to create snapshot")
}

Expand All @@ -94,6 +99,9 @@ func createRDSSnapshot(ctx context.Context, instanceID string, dbEngine RDSDBEng
if err := rdsCli.WaitUntilDBSnapshotAvailable(ctx, snapshotID); err != nil {
return nil, errors.Wrap(err, "Error while waiting snapshot to be available")
}
if dbSnapshotOutput.DBSnapshot != nil && dbSnapshotOutput.DBSnapshot.AllocatedStorage != nil {
allocatedStorage = *(dbSnapshotOutput.DBSnapshot.AllocatedStorage)
}
} else {
if _, err := rdsCli.CreateDBClusterSnapshot(ctx, instanceID, snapshotID); err != nil {
return nil, errors.Wrap(err, "Failed to create cluster snapshot")
Expand Down Expand Up @@ -124,9 +132,10 @@ func createRDSSnapshot(ctx context.Context, instanceID string, dbEngine RDSDBEng
}

output := map[string]interface{}{
CreateRDSSnapshotSnapshotID: snapshotID,
CreateRDSSnapshotInstanceIDArg: instanceID,
CreateRDSSnapshotSecurityGroupID: string(sgIDYaml),
CreateRDSSnapshotSnapshotID: snapshotID,
CreateRDSSnapshotInstanceIDArg: instanceID,
CreateRDSSnapshotSecurityGroupID: string(sgIDYaml),
CreateRDSSnapshotAllocatedStorage: strconv.FormatInt(allocatedStorage, 10) + "GiB",
}
return output, nil
}
Expand Down

0 comments on commit 54de77f

Please sign in to comment.