Skip to content

Commit 6e273a4

Browse files
vsharma6855v.sharmaandrewsomething
authored
[DBAAS] | Add API endpoint for applying cluster patches (#1579)
* [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]>
1 parent 50ba3ca commit 6e273a4

File tree

11 files changed

+85
-7
lines changed

11 files changed

+85
-7
lines changed

commands/databases.go

+17-3
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ func convertUTCtoISO8601(restoreFromTimestamp string) (string, error) {
425425
// accepts UTC time format from user (to match db list output) and converts it to ISO8601 for api parity.
426426
date, error := time.Parse("2006-01-02 15:04:05 +0000 UTC", restoreFromTimestamp)
427427
if error != nil {
428-
return "", fmt.Errorf("Invalid format for --restore-from-timestamp. Must be in UTC format: 2006-01-02 15:04:05 +0000 UTC")
428+
return "", fmt.Errorf("invalid format for --restore-from-timestamp. Must be in UTC format: 2006-01-02 15:04:05 +0000 UTC")
429429
}
430430
dateFormatted := date.Format(time.RFC3339)
431431

@@ -586,7 +586,9 @@ func databaseMaintenanceWindow() *Command {
586586
Short: "Display commands for scheduling automatic maintenance on your database cluster",
587587
Long: `The ` + "`" + `doctl databases maintenance-window` + "`" + ` commands allow you to schedule, and check the schedule of, maintenance windows for your databases.
588588
589-
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.`,
589+
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.
590+
591+
To install an update outside of a maintenance window, use the ` + "`" + `doctl databases maintenance-window install` + "`" + ` command.`,
590592
},
591593
}
592594

@@ -615,6 +617,9 @@ To see a list of your databases and their IDs, run `+"`"+`doctl databases list`+
615617
"The hour when maintenance updates are applied, in UTC 24-hour format. Example: '16:00')", requiredOpt())
616618
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`
617619

620+
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"))
621+
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`
622+
618623
return cmd
619624
}
620625

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

664+
// RunDatabaseInstallUpdate starts installation of updates
665+
func RunDatabaseInstallUpdate(c *CmdConfig) error {
666+
if len(c.Args) == 0 {
667+
return doctl.NewMissingArgsErr(c.NS)
668+
}
669+
id := c.Args[0]
670+
return c.Databases().InstallUpdate(id)
671+
}
672+
659673
func buildDatabaseUpdateMaintenanceRequestFromArgs(c *CmdConfig) (*godo.DatabaseUpdateMaintenanceRequest, error) {
660674
r := &godo.DatabaseUpdateMaintenanceRequest{}
661675

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

835849
kafkaACl := new(godo.KafkaACL)

commands/databases_test.go

+21
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ func TestDatabaseMaintenanceWindowCommand(t *testing.T) {
279279
assertCommandNames(t, cmd,
280280
"update",
281281
"get",
282+
"install",
282283
)
283284
}
284285

@@ -894,6 +895,26 @@ func TestDatabaseUpdateMaintenance(t *testing.T) {
894895
})
895896
}
896897

898+
func TestDatabaseInstallUpdate(t *testing.T) {
899+
900+
// Success
901+
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
902+
tm.databases.EXPECT().InstallUpdate(testDBCluster.ID).Return(nil)
903+
config.Args = append(config.Args, testDBCluster.ID)
904+
err := RunDatabaseInstallUpdate(config)
905+
assert.NoError(t, err)
906+
})
907+
908+
// Error
909+
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {
910+
tm.databases.EXPECT().InstallUpdate(testDBCluster.ID).Return(errTest)
911+
config.Args = append(config.Args, testDBCluster.ID)
912+
913+
err := RunDatabaseInstallUpdate(config)
914+
assert.EqualError(t, err, errTest.Error())
915+
})
916+
}
917+
897918
func TestDatabasesUserGet(t *testing.T) {
898919
// Successful call
899920
withTestClient(t, func(config *CmdConfig, tm *tcMocks) {

do/databases.go

+7
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ type DatabasesService interface {
163163

164164
GetMaintenance(string) (*DatabaseMaintenanceWindow, error)
165165
UpdateMaintenance(string, *godo.DatabaseUpdateMaintenanceRequest) error
166+
InstallUpdate(string) error
166167

167168
GetUser(string, string) (*DatabaseUser, error)
168169
ListUsers(string) (DatabaseUsers, error)
@@ -336,6 +337,12 @@ func (ds *databasesService) UpdateMaintenance(databaseID string, req *godo.Datab
336337
return err
337338
}
338339

340+
func (ds *databasesService) InstallUpdate(databaseID string) error {
341+
_, err := ds.client.Databases.InstallUpdate(context.TODO(), databaseID)
342+
343+
return err
344+
}
345+
339346
func (ds *databasesService) ListBackups(databaseID string) (DatabaseBackups, error) {
340347
f := func(opt *godo.ListOptions) ([]any, *godo.Response, error) {
341348
list, resp, err := ds.client.Databases.ListBackups(context.TODO(), databaseID, opt)

do/mocks/DatabasesService.go

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.22
55
require (
66
github.com/blang/semver v3.5.1+incompatible
77
github.com/creack/pty v1.1.21
8-
github.com/digitalocean/godo v1.123.0
8+
github.com/digitalocean/godo v1.124.0
99
github.com/docker/cli v24.0.5+incompatible
1010
github.com/docker/docker v25.0.6+incompatible
1111
github.com/docker/docker-credential-helpers v0.7.0 // indirect

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
9393
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
9494
github.com/digitalocean/godo v1.123.0 h1:EowFmnVevXIKn9svPDTz0NK4+f+eE3v5easKD9hjc1k=
9595
github.com/digitalocean/godo v1.123.0/go.mod h1:WQVH83OHUy6gC4gXpEVQKtxTd4L5oCp+5OialidkPLY=
96+
github.com/digitalocean/godo v1.124.0 h1:qroI1QdtcgnXF/pefq9blZRbXqBw1Ry/aHh2pnu/328=
97+
github.com/digitalocean/godo v1.124.0/go.mod h1:WQVH83OHUy6gC4gXpEVQKtxTd4L5oCp+5OialidkPLY=
9698
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
9799
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
98100
github.com/docker/cli v24.0.5+incompatible h1:WeBimjvS0eKdH4Ygx+ihVq1Q++xg36M/rMi4aXAvodc=

integration/database_create_restore_from_cluster.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ var _ = suite("database/create/backup-restore", func(t *testing.T, when spec.G,
127127
})
128128

129129
const (
130-
restoreFromTimestampError = "Error: Invalid format for --restore-from-timestamp. Must be in UTC format: 2006-01-02 15:04:05 +0000 UTC"
130+
restoreFromTimestampError = "Error: invalid format for --restore-from-timestamp. Must be in UTC format: 2006-01-02 15:04:05 +0000 UTC"
131131
databasesCreateRestoreBackUpOutput = `
132132
Notice: Database created
133133
ID Name Engine Version Number of Nodes Region Status Size URI Created At Storage (MiB)

vendor/github.com/digitalocean/godo/CHANGELOG.md

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/digitalocean/godo/databases.go

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/digitalocean/godo/godo.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ github.com/creack/pty
6161
# github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
6262
## explicit
6363
github.com/davecgh/go-spew/spew
64-
# github.com/digitalocean/godo v1.123.0
64+
# github.com/digitalocean/godo v1.124.0
6565
## explicit; go 1.20
6666
github.com/digitalocean/godo
6767
github.com/digitalocean/godo/metrics

0 commit comments

Comments
 (0)