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

fix(mysql): avoid missing param error and raise cli timeout for --wait #93

Merged
merged 6 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
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
15 changes: 11 additions & 4 deletions create/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type mySQLCmd struct {
TransactionIsolation storage.MySQLTransactionCharacteristic `placeholder:"${mysql_transaction_isolation}" help:"Configures the transaction_isolation variable."`
KeepDailyBackups *int `placeholder:"${mysql_backup_retention_days}" help:"Number of daily database backups to keep. Note that setting this to 0, backup will be disabled and existing dumps deleted immediately."`
Wait bool `default:"true" help:"Wait until MySQL instance is created."`
WaitTimeout time.Duration `default:"900s" help:"Duration to wait for MySQL getting ready. Only relevant if --wait is set."`
WaitTimeout time.Duration `default:"25m" help:"Duration to wait for MySQL getting ready. Only relevant if --wait is set."`
}

func (cmd *mySQLCmd) Run(ctx context.Context, client *api.Client) error {
Expand All @@ -44,7 +44,7 @@ func (cmd *mySQLCmd) Run(ctx context.Context, client *api.Client) error {
}
cmd.SSHKeys = append(cmd.SSHKeys, sshkeys...)

fmt.Println("Creating new mysql. This can take up to 15 minutes.")
fmt.Printf("Creating new mysql. This might take some time (waiting up to %s).\n", cmd.WaitTimeout)
mysql := cmd.newMySQL(client.Project)

c := newCreator(client, mysql, "mysql")
Expand Down Expand Up @@ -89,8 +89,8 @@ func (cmd *mySQLCmd) newMySQL(namespace string) *storage.MySQL {
ForProvider: storage.MySQLParameters{
Location: meta.LocationName(cmd.Location),
MachineType: cmd.MachineType,
AllowedCIDRs: cmd.AllowedCidrs,
SSHKeys: cmd.SSHKeys,
AllowedCIDRs: []storage.IPv4CIDR{}, // avoid missing parameter error
SSHKeys: []storage.SSHKey{}, // avoid missing parameter error
SQLMode: cmd.SQLMode,
CharacterSet: storage.MySQLCharacterSet{
Name: cmd.CharacterSetName,
Expand All @@ -104,6 +104,13 @@ func (cmd *mySQLCmd) newMySQL(namespace string) *storage.MySQL {
},
}

if cmd.AllowedCidrs != nil {
mySQL.Spec.ForProvider.AllowedCIDRs = cmd.AllowedCidrs
}
if cmd.SSHKeys != nil {
mySQL.Spec.ForProvider.SSHKeys = cmd.SSHKeys
}

return mySQL
}

Expand Down
8 changes: 8 additions & 0 deletions create/mysql_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ func TestMySQL(t *testing.T) {
return
}

// we set defaults for the slices
if tt.want.AllowedCIDRs == nil {
tt.want.AllowedCIDRs = []storage.IPv4CIDR{}
}
if tt.want.SSHKeys == nil {
tt.want.SSHKeys = []storage.SSHKey{}
}

if !reflect.DeepEqual(created.Spec.ForProvider, tt.want) {
t.Fatalf("expected mysql.Spec.ForProvider = %+v, got: %+v", created.Spec.ForProvider, tt.want)
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
github.com/mattn/go-isatty v0.0.20
github.com/moby/moby v26.0.0+incompatible
github.com/moby/term v0.5.0
github.com/ninech/apis v0.0.0-20240424152525-e2d75ea488d7
github.com/ninech/apis v0.0.0-20240425141154-83b10f0bd009
github.com/posener/complete v1.2.3
github.com/prometheus/common v0.52.2
github.com/stretchr/testify v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -582,8 +582,8 @@ github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRW
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/ninech/apis v0.0.0-20240424152525-e2d75ea488d7 h1:lRZGujpQRKfasUTsq4YXr0qxLMod+q/tboa9MrMa1C0=
github.com/ninech/apis v0.0.0-20240424152525-e2d75ea488d7/go.mod h1:6lFCwHqvcTFZvJ6zY0rxaPIoKc0CX9sHhtH/nyo/5is=
github.com/ninech/apis v0.0.0-20240425141154-83b10f0bd009 h1:tHwnlBv0wWMtNV4XfuoUV9UBD6vq68nZzvOhwIpZj0w=
github.com/ninech/apis v0.0.0-20240425141154-83b10f0bd009/go.mod h1:6lFCwHqvcTFZvJ6zY0rxaPIoKc0CX9sHhtH/nyo/5is=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/oklog/ulid v1.3.1 h1:EGfNDEx6MqHz8B3uNV6QAib1UR2Lm97sHi3ocA6ESJ4=
Expand Down