Skip to content

Commit

Permalink
[DBAAS] | Add API endpoint for applying cluster patches (#1579)
Browse files Browse the repository at this point in the history
* [DBAAS] | Add API endpoint for applying cluster patches

* Added Unit Tests

* changed function description

* install update is moved under `maintenance-window` command

* remove unused function

* corrected `integration` test

* Regenerate mocks.

* Update help copy.

---------

Co-authored-by: v.sharma <[email protected]>
Co-authored-by: Andrew Starr-Bochicchio <[email protected]>
  • Loading branch information
3 people authored Sep 17, 2024
1 parent 50ba3ca commit 6e273a4
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 7 deletions.
20 changes: 17 additions & 3 deletions commands/databases.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ func convertUTCtoISO8601(restoreFromTimestamp string) (string, error) {
// accepts UTC time format from user (to match db list output) and converts it to ISO8601 for api parity.
date, error := time.Parse("2006-01-02 15:04:05 +0000 UTC", restoreFromTimestamp)
if error != nil {
return "", fmt.Errorf("Invalid format for --restore-from-timestamp. Must be in UTC format: 2006-01-02 15:04:05 +0000 UTC")
return "", fmt.Errorf("invalid format for --restore-from-timestamp. Must be in UTC format: 2006-01-02 15:04:05 +0000 UTC")
}
dateFormatted := date.Format(time.RFC3339)

Expand Down Expand Up @@ -586,7 +586,9 @@ func databaseMaintenanceWindow() *Command {
Short: "Display commands for scheduling automatic maintenance on your database cluster",
Long: `The ` + "`" + `doctl databases maintenance-window` + "`" + ` commands allow you to schedule, and check the schedule of, maintenance windows for your databases.
Maintenance windows are hour-long blocks of time during which DigitalOcean performs automatic maintenance on databases every week. During this time, health checks, security updates, version upgrades, and more are performed.`,
Maintenance windows are hour-long blocks of time during which DigitalOcean performs automatic maintenance on databases every week. During this time, health checks, security updates, version upgrades, and more are performed.
To install an update outside of a maintenance window, use the ` + "`" + `doctl databases maintenance-window install` + "`" + ` command.`,
},
}

Expand Down Expand Up @@ -615,6 +617,9 @@ To see a list of your databases and their IDs, run `+"`"+`doctl databases list`+
"The hour when maintenance updates are applied, in UTC 24-hour format. Example: '16:00')", requiredOpt())
cmdDatabaseCreate.Example = `The following example updates the maintenance window for a database cluster with the ID ` + "`" + `ca9f591d-f38h-5555-a0ef-1c02d1d1e35` + "`" + `: doctl databases maintenance-window update ca9f591d-f38h-5555-a0ef-1c02d1d1e35 --day tuesday --hour 16:00`

cmdDatabaseInstallUpdate := CmdBuilder(cmd, RunDatabaseInstallUpdate, "install <database-cluster-id>", "Start installation of updates immediately", "Starts the installation of updates for the specified database cluster immediately outside of a maintenance window.", Writer, aliasOpt("i"))
cmdDatabaseInstallUpdate.Example = `The following example starts installation of updates for your databases with the ID ` + "`" + `ca9f591d-f38h-5555-a0ef-1c02d1d1e35` + "`" + `: doctl databases maintenance-window install ca9f591d-f38h-5555-a0ef-1c02d1d1e35`

return cmd
}

Expand Down Expand Up @@ -656,6 +661,15 @@ func RunDatabaseMaintenanceUpdate(c *CmdConfig) error {
return c.Databases().UpdateMaintenance(id, r)
}

// RunDatabaseInstallUpdate starts installation of updates
func RunDatabaseInstallUpdate(c *CmdConfig) error {
if len(c.Args) == 0 {
return doctl.NewMissingArgsErr(c.NS)
}
id := c.Args[0]
return c.Databases().InstallUpdate(id)
}

func buildDatabaseUpdateMaintenanceRequestFromArgs(c *CmdConfig) (*godo.DatabaseUpdateMaintenanceRequest, error) {
r := &godo.DatabaseUpdateMaintenanceRequest{}

Expand Down Expand Up @@ -829,7 +843,7 @@ func buildDatabaseCreateKafkaUserACls(c *CmdConfig) (kafkaACls []*godo.KafkaACL,
for _, acl := range acls {
pair := strings.SplitN(acl, ":", 2)
if len(pair) != 2 {
return nil, fmt.Errorf("Unexpected input value [%v], must be a topic:permission pair", pair)
return nil, fmt.Errorf("unexpected input value [%v], must be a topic:permission pair", pair)
}

kafkaACl := new(godo.KafkaACL)
Expand Down
21 changes: 21 additions & 0 deletions commands/databases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ func TestDatabaseMaintenanceWindowCommand(t *testing.T) {
assertCommandNames(t, cmd,
"update",
"get",
"install",
)
}

Expand Down Expand Up @@ -894,6 +895,26 @@ func TestDatabaseUpdateMaintenance(t *testing.T) {
})
}

func TestDatabaseInstallUpdate(t *testing.T) {

// Success
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
tm.databases.EXPECT().InstallUpdate(testDBCluster.ID).Return(nil)
config.Args = append(config.Args, testDBCluster.ID)
err := RunDatabaseInstallUpdate(config)
assert.NoError(t, err)
})

// Error
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
tm.databases.EXPECT().InstallUpdate(testDBCluster.ID).Return(errTest)
config.Args = append(config.Args, testDBCluster.ID)

err := RunDatabaseInstallUpdate(config)
assert.EqualError(t, err, errTest.Error())
})
}

func TestDatabasesUserGet(t *testing.T) {
// Successful call
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
Expand Down
7 changes: 7 additions & 0 deletions do/databases.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ type DatabasesService interface {

GetMaintenance(string) (*DatabaseMaintenanceWindow, error)
UpdateMaintenance(string, *godo.DatabaseUpdateMaintenanceRequest) error
InstallUpdate(string) error

GetUser(string, string) (*DatabaseUser, error)
ListUsers(string) (DatabaseUsers, error)
Expand Down Expand Up @@ -336,6 +337,12 @@ func (ds *databasesService) UpdateMaintenance(databaseID string, req *godo.Datab
return err
}

func (ds *databasesService) InstallUpdate(databaseID string) error {
_, err := ds.client.Databases.InstallUpdate(context.TODO(), databaseID)

return err
}

func (ds *databasesService) ListBackups(databaseID string) (DatabaseBackups, error) {
f := func(opt *godo.ListOptions) ([]any, *godo.Response, error) {
list, resp, err := ds.client.Databases.ListBackups(context.TODO(), databaseID, opt)
Expand Down
14 changes: 14 additions & 0 deletions do/mocks/DatabasesService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.22
require (
github.com/blang/semver v3.5.1+incompatible
github.com/creack/pty v1.1.21
github.com/digitalocean/godo v1.123.0
github.com/digitalocean/godo v1.124.0
github.com/docker/cli v24.0.5+incompatible
github.com/docker/docker v25.0.6+incompatible
github.com/docker/docker-credential-helpers v0.7.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/digitalocean/godo v1.123.0 h1:EowFmnVevXIKn9svPDTz0NK4+f+eE3v5easKD9hjc1k=
github.com/digitalocean/godo v1.123.0/go.mod h1:WQVH83OHUy6gC4gXpEVQKtxTd4L5oCp+5OialidkPLY=
github.com/digitalocean/godo v1.124.0 h1:qroI1QdtcgnXF/pefq9blZRbXqBw1Ry/aHh2pnu/328=
github.com/digitalocean/godo v1.124.0/go.mod h1:WQVH83OHUy6gC4gXpEVQKtxTd4L5oCp+5OialidkPLY=
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
github.com/docker/cli v24.0.5+incompatible h1:WeBimjvS0eKdH4Ygx+ihVq1Q++xg36M/rMi4aXAvodc=
Expand Down
2 changes: 1 addition & 1 deletion integration/database_create_restore_from_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ var _ = suite("database/create/backup-restore", func(t *testing.T, when spec.G,
})

const (
restoreFromTimestampError = "Error: Invalid format for --restore-from-timestamp. Must be in UTC format: 2006-01-02 15:04:05 +0000 UTC"
restoreFromTimestampError = "Error: invalid format for --restore-from-timestamp. Must be in UTC format: 2006-01-02 15:04:05 +0000 UTC"
databasesCreateRestoreBackUpOutput = `
Notice: Database created
ID Name Engine Version Number of Nodes Region Status Size URI Created At Storage (MiB)
Expand Down
4 changes: 4 additions & 0 deletions vendor/github.com/digitalocean/godo/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions vendor/github.com/digitalocean/godo/databases.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/github.com/digitalocean/godo/godo.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ github.com/creack/pty
# github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
## explicit
github.com/davecgh/go-spew/spew
# github.com/digitalocean/godo v1.123.0
# github.com/digitalocean/godo v1.124.0
## explicit; go 1.20
github.com/digitalocean/godo
github.com/digitalocean/godo/metrics
Expand Down

0 comments on commit 6e273a4

Please sign in to comment.