Skip to content

Commit 49aaf96

Browse files
authored
dbaas: valkey subcommands (#673)
# Description <!-- * Prefix: the title with the component name being changed. Add a short and self describing sentence to ease the review * Please add a few lines providing context and describing the change * Please self comment changes whenever applicable to help with the review process * Please keep the checklist as part of the PR. Tick what applies to this change. --> ## Checklist (For exoscale contributors) * [x] Changelog updated (under *Unreleased* block) * [ ] Testing ## Testing Locally, with pre-prod, and local build ```bash go build . mv cli exo ./exo dbaas type list ./exo dbaas type show valkey ./exo dbaas type show valkey --settings=valkey ./exo dbaas create valkey hobbyist-2 cli33 --valkey-settings '{"pubsub_client_output_buffer_limit": 35}' #create with settings ./exo dbaas show cli33 valkey ./exo dbaas show cli33 --settings valkey #check settings is as set ./exo dbaas update cli33 --valkey-settings '{ "io_threads": 1, "lfu_decay_time": 2, "lfu_log_factor": 12, "maxmemory_policy": "noeviction", "pubsub_client_output_buffer_limit": 57, "ssl": true, "timeout": 600 }' # update a bunch of settings ./exo dbaas show cli33 --settings valkey #check settings is as updated ./exo dbaas user create cli33 cli-user #create user ./exo dbaas user list cli33 #check user was created ./exo dbaas user show cli33 cli-user ./exo dbaas user reveal-secrets cli33 cli-user #check password ./exo dbaas user show cli33 cli-user ./exo dbaas user reset-credentials cli33 cli-user # reset password ./exo dbaas user reveal-secrets cli33 cli-user #check pasword again ./exo dbaas user delete cli33 cli-user #delete user ./exo dbaas user list cli33 #check user was deleted
1 parent 7137c48 commit 49aaf96

28 files changed

+1562
-137
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
- storage: bucket replication support #668
1212
- sks: move cluster creation to egoscale v3 + enable-kube-proxy flag
13+
- dbaas: added valkey
14+
- dbaas: remove redis create
1315

1416
## 1.83.1
1517

cmd/dbaas_create.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type dbaasServiceCreateCmd struct {
2323
HelpOpensearch bool `cli-usage:"show usage for flags specific to the opensearch type"`
2424
HelpMysql bool `cli-usage:"show usage for flags specific to the mysql type"`
2525
HelpPg bool `cli-usage:"show usage for flags specific to the pg type"`
26-
HelpRedis bool `cli-usage:"show usage for flags specific to the redis type"`
26+
HelpValkey bool `cli-usage:"show usage for flags specific to the valkey type"`
2727
HelpGrafana bool `cli-usage:"show usage for flags specific to the grafana type"`
2828

2929
MaintenanceDOW string `cli-flag:"maintenance-dow" cli-usage:"automated Database Service maintenance day-of-week"`
@@ -103,19 +103,19 @@ type dbaasServiceCreateCmd struct {
103103
PGMigrationMethod string `cli-flag:"pg-migration-method" cli-usage:"migration method to be used (\"dump\" or \"replication\")" cli-hidden:""`
104104
PGMigrationIgnoreDbs []string `cli-flag:"pg-migration-ignore-dbs" cli-usage:"list of databases which should be ignored during migration" cli-hidden:""`
105105

106-
// "redis" type specific flags
107-
RedisForkFrom string `cli-flag:"redis-fork-from" cli-usage:"name of a Database Service to fork from" cli-hidden:""`
108-
RedisIPFilter []string `cli-flag:"redis-ip-filter" cli-usage:"allow incoming connections from CIDR address block" cli-hidden:""`
109-
RedisRecoveryBackupName string `cli-flag:"redis-recovery-backup-name" cli-usage:"the name of the backup to restore when forking from a Database Service" cli-hidden:""`
110-
RedisSettings string `cli-flag:"redis-settings" cli-usage:"Redis configuration settings (JSON format)" cli-hidden:""`
111-
RedisMigrationHost string `cli-flag:"redis-migration-host" cli-usage:"hostname or IP address of the source server where to migrate data from" cli-hidden:""`
112-
RedisMigrationPort int64 `cli-flag:"redis-migration-port" cli-usage:"port number of the source server where to migrate data from" cli-hidden:""`
113-
RedisMigrationPassword string `cli-flag:"redis-migration-password" cli-usage:"password for authenticating to the source server" cli-hidden:""`
114-
RedisMigrationSSL bool `cli-flag:"redis-migration-ssl" cli-usage:"connect to the source server using SSL" cli-hidden:""`
115-
RedisMigrationUsername string `cli-flag:"redis-migration-username" cli-usage:"username for authenticating to the source server" cli-hidden:""`
116-
RedisMigrationDBName string `cli-flag:"redis-migration-dbname" cli-usage:"database name for bootstrapping the initial connection" cli-hidden:""`
117-
RedisMigrationMethod string `cli-flag:"redis-migration-method" cli-usage:"migration method to be used (\"dump\" or \"replication\")" cli-hidden:""`
118-
RedisMigrationIgnoreDbs []string `cli-flag:"redis-migration-ignore-dbs" cli-usage:"list of databases which should be ignored during migration" cli-hidden:""`
106+
// "valkey" type specific flags
107+
ValkeyForkFrom string `cli-flag:"valkey-fork-from" cli-usage:"name of a Database Service to fork from" cli-hidden:""`
108+
ValkeyIPFilter []string `cli-flag:"valkey-ip-filter" cli-usage:"allow incoming connections from CIDR address block" cli-hidden:""`
109+
ValkeyRecoveryBackupName string `cli-flag:"valkey-recovery-backup-name" cli-usage:"the name of the backup to restore when forking from a Database Service" cli-hidden:""`
110+
ValkeySettings string `cli-flag:"valkey-settings" cli-usage:"Valkey configuration settings (JSON format)" cli-hidden:""`
111+
ValkeyMigrationHost string `cli-flag:"valkey-migration-host" cli-usage:"hostname or IP address of the source server where to migrate data from" cli-hidden:""`
112+
ValkeyMigrationPort int64 `cli-flag:"valkey-migration-port" cli-usage:"port number of the source server where to migrate data from" cli-hidden:""`
113+
ValkeyMigrationPassword string `cli-flag:"valkey-migration-password" cli-usage:"password for authenticating to the source server" cli-hidden:""`
114+
ValkeyMigrationSSL bool `cli-flag:"valkey-migration-ssl" cli-usage:"connect to the source server using SSL" cli-hidden:""`
115+
ValkeyMigrationUsername string `cli-flag:"valkey-migration-username" cli-usage:"username for authenticating to the source server" cli-hidden:""`
116+
ValkeyMigrationDBName string `cli-flag:"valkey-migration-dbname" cli-usage:"database name for bootstrapping the initial connection" cli-hidden:""`
117+
ValkeyMigrationMethod string `cli-flag:"valkey-migration-method" cli-usage:"migration method to be used (\"dump\" or \"replication\")" cli-hidden:""`
118+
ValkeyMigrationIgnoreDbs []string `cli-flag:"valkey-migration-ignore-dbs" cli-usage:"list of databases which should be ignored during migration" cli-hidden:""`
119119
}
120120

121121
func (c *dbaasServiceCreateCmd) cmdAliases() []string { return gCreateAlias }
@@ -149,8 +149,8 @@ func (c *dbaasServiceCreateCmd) cmdPreRun(cmd *cobra.Command, args []string) err
149149
case cmd.Flags().Changed("help-pg"):
150150
cmdShowHelpFlags(cmd.Flags(), "pg-")
151151
os.Exit(0)
152-
case cmd.Flags().Changed("help-redis"):
153-
cmdShowHelpFlags(cmd.Flags(), "redis-")
152+
case cmd.Flags().Changed("help-valkey"):
153+
cmdShowHelpFlags(cmd.Flags(), "valkey-")
154154
os.Exit(0)
155155
}
156156

@@ -180,8 +180,8 @@ func (c *dbaasServiceCreateCmd) cmdRun(cmd *cobra.Command, args []string) error
180180
return c.createMysql(cmd, args)
181181
case "pg":
182182
return c.createPG(cmd, args)
183-
case "redis":
184-
return c.createRedis(cmd, args)
183+
case "valkey":
184+
return c.createValkey(cmd, args)
185185
default:
186186
return fmt.Errorf("unsupported service type %q", c.Type)
187187
}

cmd/dbaas_create_redis.go

Lines changed: 0 additions & 113 deletions
This file was deleted.

cmd/dbaas_create_valkey.go

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package cmd
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"strings"
7+
8+
"github.com/spf13/cobra"
9+
10+
"github.com/exoscale/cli/pkg/globalstate"
11+
utils "github.com/exoscale/cli/utils"
12+
v3 "github.com/exoscale/egoscale/v3"
13+
)
14+
15+
func (c *dbaasServiceCreateCmd) createValkey(_ *cobra.Command, _ []string) error {
16+
var err error
17+
18+
ctx := gContext
19+
20+
client, err := switchClientZoneV3(ctx, globalstate.EgoscaleV3Client, v3.ZoneName(c.Zone))
21+
22+
if err != nil {
23+
return fmt.Errorf("unable to create client: %w", err)
24+
}
25+
26+
databaseService := v3.CreateDBAASServiceValkeyRequest{
27+
Plan: c.Plan,
28+
TerminationProtection: &c.TerminationProtection,
29+
}
30+
31+
if c.ValkeyForkFrom != "" {
32+
databaseService.ForkFromService = v3.DBAASServiceName(c.ValkeyForkFrom)
33+
if c.ValkeyRecoveryBackupName != "" {
34+
databaseService.RecoveryBackupName = c.ValkeyRecoveryBackupName
35+
}
36+
}
37+
38+
if len(c.ValkeyIPFilter) > 0 {
39+
databaseService.IPFilter = c.ValkeyIPFilter
40+
}
41+
42+
if c.MaintenanceDOW != "" && c.MaintenanceTime != "" {
43+
databaseService.Maintenance = &v3.CreateDBAASServiceValkeyRequestMaintenance{
44+
Dow: v3.CreateDBAASServiceValkeyRequestMaintenanceDow(c.MaintenanceDOW),
45+
Time: c.MaintenanceTime,
46+
}
47+
}
48+
49+
if c.ValkeySettings != "" {
50+
var settings map[string]interface{}
51+
52+
if err := json.Unmarshal([]byte(c.ValkeySettings), &settings); err != nil {
53+
return err
54+
}
55+
56+
ssl := utils.GetSettingBool(settings, "ssl")
57+
databaseService.ValkeySettings = &v3.JSONSchemaValkey{
58+
AclChannelsDefault: v3.JSONSchemaValkeyAclChannelsDefault(utils.GetSettingString(settings, "acl_channels_default")),
59+
IoThreads: utils.GetSettingFloat64(settings, "io_threads"),
60+
LfuDecayTime: utils.GetSettingFloat64(settings, "lfu_decay_time"),
61+
LfuLogFactor: utils.GetSettingFloat64(settings, "lfu_log_factor"),
62+
MaxmemoryPolicy: v3.JSONSchemaValkeyMaxmemoryPolicy(utils.GetSettingString(settings, "maxmemory_policy")),
63+
NotifyKeyspaceEvents: utils.GetSettingString(settings, "notify_keyspace_events"),
64+
NumberOfDatabases: utils.GetSettingFloat64(settings, "number_of_databases"),
65+
Persistence: v3.JSONSchemaValkeyPersistence(utils.GetSettingString(settings, "persistence")),
66+
PubsubClientOutputBufferLimit: utils.GetSettingFloat64(settings, "pubsub_client_output_buffer_limit"),
67+
SSL: &ssl,
68+
Timeout: utils.GetSettingFloat64(settings, "timeout"),
69+
}
70+
}
71+
72+
if c.ValkeyMigrationHost != "" {
73+
databaseService.Migration = &v3.CreateDBAASServiceValkeyRequestMigration{
74+
Host: c.ValkeyMigrationHost,
75+
Port: c.ValkeyMigrationPort,
76+
Password: c.ValkeyMigrationPassword,
77+
Username: c.ValkeyMigrationUsername,
78+
Dbname: c.ValkeyMigrationDBName,
79+
}
80+
if c.ValkeyMigrationSSL {
81+
databaseService.Migration.SSL = &c.ValkeyMigrationSSL
82+
}
83+
if c.ValkeyMigrationMethod != "" {
84+
databaseService.Migration.Method = v3.EnumMigrationMethod(c.ValkeyMigrationMethod)
85+
}
86+
if len(c.ValkeyMigrationIgnoreDbs) > 0 {
87+
databaseService.Migration.IgnoreDbs = strings.Join(c.ValkeyMigrationIgnoreDbs, ",")
88+
}
89+
}
90+
91+
op, err := client.CreateDBAASServiceValkey(ctx, c.Name, databaseService)
92+
93+
if err != nil {
94+
return err
95+
}
96+
97+
decorateAsyncOperation(fmt.Sprintf("Creating DBaaS Datadog external Endpoint %q", c.Name), func() {
98+
op, err = client.Wait(ctx, op, v3.OperationStateSuccess)
99+
})
100+
101+
if err != nil {
102+
return err
103+
}
104+
105+
serviceName := op.Reference.ID.String()
106+
107+
if !globalstate.Quiet {
108+
return c.outputFunc((&dbaasServiceShowCmd{
109+
Name: serviceName,
110+
Zone: c.Zone,
111+
}).showDatabaseServiceValkey(ctx))
112+
}
113+
114+
return nil
115+
}

cmd/dbaas_show.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ type dbServiceShowOutput struct {
7575
Mysql *dbServiceMysqlShowOutput `json:"mysql,omitempty"`
7676
PG *dbServicePGShowOutput `json:"pg,omitempty"`
7777
Redis *dbServiceRedisShowOutput `json:"redis,omitempty"`
78+
Valkey *dbServiceValkeyShowOutput `json:"valkey,omitempty"`
7879
Opensearch *dbServiceOpensearchShowOutput `json:"opensearch,omitempty"`
7980
}
8081

@@ -118,6 +119,8 @@ func (o *dbServiceShowOutput) ToTable() {
118119
formatDatabaseServicePGTable(t, o.PG)
119120
case o.Redis != nil:
120121
formatDatabaseServiceRedisTable(t, o.Redis)
122+
case o.Valkey != nil:
123+
formatDatabaseServiceValkeyTable(t, o.Valkey)
121124
}
122125
}
123126

@@ -214,6 +217,8 @@ func (c *dbaasServiceShowCmd) cmdRun(_ *cobra.Command, _ []string) error {
214217
return c.outputFunc(c.showDatabaseServicePG(ctx))
215218
case "redis":
216219
return c.outputFunc(c.showDatabaseServiceRedis(ctx))
220+
case "valkey":
221+
return c.outputFunc(c.showDatabaseServiceValkey(ctx))
217222
default:
218223
return fmt.Errorf("unsupported service type %q", dbType)
219224
}

0 commit comments

Comments
 (0)