Skip to content
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
10 changes: 7 additions & 3 deletions create/mysqldatabase.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ import (

type mysqlDatabaseCmd struct {
resourceCmd
Location meta.LocationName `placeholder:"${mysqldatabase_location_default}" help:"Where the MySQL database is created. Available locations are: ${mysqldatabase_location_options}"`
MysqlDatabaseVersion storage.MySQLVersion `placeholder:"${mysqldatabase_version_default}" help:"Version of the MySQL database. Available versions: ${mysqldatabase_versions}"`
CharacterSet string `placeholder:"${mysqldatabase_characterset_default}" help:"Character set for the MySQL database. Available character sets: ${mysqldatabase_characterset_options}"`
Location meta.LocationName `placeholder:"${mysqldatabase_location_default}" help:"Where the MySQL database is created. Available locations are: ${mysqldatabase_location_options}"`
MysqlDatabaseVersion storage.MySQLVersion `placeholder:"${mysqldatabase_version_default}" help:"Version of the MySQL database. Available versions: ${mysqldatabase_versions}"`
CharacterSet string `placeholder:"${mysqldatabase_characterset_default}" help:"Character set for the MySQL database. Available character sets: ${mysqldatabase_characterset_options}"`
BackupSchedule storage.DatabaseBackupScheduleCalendar `placeholder:"${mysqldatabase_backupschedule_default}" help:"Backup schedule for the MySQL database. Available schedules: ${mysqldatabase_backupschedule_options}"`
}

func (cmd *mysqlDatabaseCmd) Run(ctx context.Context, client *api.Client) error {
Expand Down Expand Up @@ -76,6 +77,7 @@ func (cmd *mysqlDatabaseCmd) newMySQLDatabase(namespace string) *storage.MySQLDa
CharacterSet: storage.MySQLCharacterSet{
Name: cmd.CharacterSet,
},
BackupSchedule: cmd.BackupSchedule,
},
},
}
Expand All @@ -93,6 +95,8 @@ func MySQLDatabaseKongVars() kong.Vars {
result["mysqldatabase_versions"] = strings.Join(stringSlice(storage.MySQLDatabaseVersions), ", ")
result["mysqldatabase_characterset_default"] = "utf8mb4"
result["mysqldatabase_characterset_options"] = strings.Join([]string{"utf8mb4"}, ", ")
result["mysqldatabase_backupschedule_default"] = string(storage.DatabaseBackupScheduleCalendarDaily)
result["mysqldatabase_backupschedule_options"] = strings.Join(stringSlice(storage.DatabaseBackupScheduleCalendars), ", ")

return result
}
12 changes: 8 additions & 4 deletions create/postgresdatabase.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import (

type postgresDatabaseCmd struct {
resourceCmd
Location meta.LocationName `placeholder:"${postgresdatabase_location_default}" help:"Where the PostgreSQL database is created. Available locations are: ${postgresdatabase_location_options}"`
PostgresDatabaseVersion storage.PostgresVersion `placeholder:"${postgresdatabase_version_default}" help:"Release version with which the PostgreSQL database is created. Available versions: ${postgresdatabase_versions}"`
Location meta.LocationName `placeholder:"${postgresdatabase_location_default}" help:"Where the PostgreSQL database is created. Available locations are: ${postgresdatabase_location_options}"`
PostgresDatabaseVersion storage.PostgresVersion `placeholder:"${postgresdatabase_version_default}" help:"Release version with which the PostgreSQL database is created. Available versions: ${postgresdatabase_versions}"`
BackupSchedule storage.DatabaseBackupScheduleCalendar `placeholder:"${postgresdatabase_backupschedule_default}" help:"Backup schedule for the PostgreSQL database. Available schedules: ${postgresdatabase_backupschedule_options}"`
}

func (cmd *postgresDatabaseCmd) Run(ctx context.Context, client *api.Client) error {
Expand Down Expand Up @@ -73,8 +74,9 @@ func (cmd *postgresDatabaseCmd) newPostgresDatabase(namespace string) *storage.P
},
},
ForProvider: storage.PostgresDatabaseParameters{
Location: cmd.Location,
Version: cmd.PostgresDatabaseVersion,
Location: cmd.Location,
Version: cmd.PostgresDatabaseVersion,
BackupSchedule: cmd.BackupSchedule,
},
},
}
Expand All @@ -90,6 +92,8 @@ func PostgresDatabaseKongVars() kong.Vars {
result["postgresdatabase_location_options"] = strings.Join(stringSlice(storage.PostgresDatabaseLocationOptions), ", ")
result["postgresdatabase_version_default"] = string(storage.PostgresDatabaseVersionDefault)
result["postgresdatabase_versions"] = strings.Join(stringSlice(storage.PostgresDatabaseVersions), ", ")
result["postgresdatabase_backupschedule_default"] = string(storage.DatabaseBackupScheduleCalendarDaily)
result["postgresdatabase_backupschedule_options"] = strings.Join(stringSlice(storage.DatabaseBackupScheduleCalendars), ", ")

return result
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ require (
github.com/mattn/go-isatty v0.0.20
github.com/moby/moby v28.5.2+incompatible
github.com/moby/term v0.5.2
github.com/ninech/apis v0.0.0-20260210054741-702ae597aaa7
github.com/ninech/apis v0.0.0-20260213065658-16dce8e85c76
github.com/posener/complete v1.2.3
github.com/prometheus/common v0.67.5
github.com/stretchr/testify v1.11.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,8 @@ github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus=
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
github.com/ninech/apis v0.0.0-20260210054741-702ae597aaa7 h1:ZJaUEa+dAHQttjKs2uW8Ok4BaqSjkKHF4oIK7jkTa9o=
github.com/ninech/apis v0.0.0-20260210054741-702ae597aaa7/go.mod h1:a70Lrp7lseFzv/fO3q/05xSW42GQPKMFd7WE7XrrEjU=
github.com/ninech/apis v0.0.0-20260213065658-16dce8e85c76 h1:wqGnRdVo0RMm1qkk2OAGWGmUJjBvg1yPSqxQrlVA6hA=
github.com/ninech/apis v0.0.0-20260213065658-16dce8e85c76/go.mod h1:a70Lrp7lseFzv/fO3q/05xSW42GQPKMFd7WE7XrrEjU=
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
7 changes: 5 additions & 2 deletions update/mysqldatabase.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

type mysqlDatabaseCmd struct {
resourceCmd
BackupSchedule *storage.DatabaseBackupScheduleCalendar `help:"Backup schedule for the MySQL database. Available schedules: ${mysqldatabase_backupschedule_options}"`
}

func (cmd *mysqlDatabaseCmd) Run(ctx context.Context, client *api.Client) error {
Expand All @@ -35,6 +36,8 @@ func (cmd *mysqlDatabaseCmd) Run(ctx context.Context, client *api.Client) error
return upd.Update(ctx)
}

func (cmd *mysqlDatabaseCmd) applyUpdates(_ *storage.MySQLDatabase) {
cmd.Warningf("there are no attributes for mysqldatabase which can be updated after creation. Applying update without any changes.")
func (cmd *mysqlDatabaseCmd) applyUpdates(db *storage.MySQLDatabase) {
if cmd.BackupSchedule != nil {
db.Spec.ForProvider.BackupSchedule = *cmd.BackupSchedule
}
}
7 changes: 7 additions & 0 deletions update/mysqldatabase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/ninech/nctl/api"
"github.com/ninech/nctl/internal/format"
"github.com/ninech/nctl/internal/test"
"k8s.io/utils/ptr"
)

func TestMySQLDatabase(t *testing.T) {
Expand All @@ -30,6 +31,12 @@ func TestMySQLDatabase(t *testing.T) {
update: mysqlDatabaseCmd{},
wantErr: false,
},
{
name: "update-backup-schedule",
create: storage.MySQLDatabaseParameters{BackupSchedule: storage.DatabaseBackupScheduleCalendarDaily},
update: mysqlDatabaseCmd{BackupSchedule: ptr.To(storage.DatabaseBackupScheduleCalendarDisabled)},
want: storage.MySQLDatabaseParameters{BackupSchedule: storage.DatabaseBackupScheduleCalendarDisabled},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
7 changes: 5 additions & 2 deletions update/postgresdatabase.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

type postgresDatabaseCmd struct {
resourceCmd
BackupSchedule *storage.DatabaseBackupScheduleCalendar `help:"Backup schedule for the PostgreSQL database. Available schedules: ${postgresdatabase_backupschedule_options}"`
}

func (cmd *postgresDatabaseCmd) Run(ctx context.Context, client *api.Client) error {
Expand All @@ -35,6 +36,8 @@ func (cmd *postgresDatabaseCmd) Run(ctx context.Context, client *api.Client) err
return upd.Update(ctx)
}

func (cmd *postgresDatabaseCmd) applyUpdates(_ *storage.PostgresDatabase) {
cmd.Warningf("there are no attributes for postgresdatabase which can be updated after creation. Applying update without any changes.")
func (cmd *postgresDatabaseCmd) applyUpdates(db *storage.PostgresDatabase) {
if cmd.BackupSchedule != nil {
db.Spec.ForProvider.BackupSchedule = *cmd.BackupSchedule
}
}
7 changes: 7 additions & 0 deletions update/postgresdatabase_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/ninech/nctl/api"
"github.com/ninech/nctl/internal/format"
"github.com/ninech/nctl/internal/test"
"k8s.io/utils/ptr"
)

func TestPostgresDatabase(t *testing.T) {
Expand All @@ -30,6 +31,12 @@ func TestPostgresDatabase(t *testing.T) {
update: postgresDatabaseCmd{},
wantErr: false,
},
{
name: "update-backup-schedule",
create: storage.PostgresDatabaseParameters{BackupSchedule: storage.DatabaseBackupScheduleCalendarDisabled},
update: postgresDatabaseCmd{BackupSchedule: ptr.To(storage.DatabaseBackupScheduleCalendarDaily)},
want: storage.PostgresDatabaseParameters{BackupSchedule: storage.DatabaseBackupScheduleCalendarDaily},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down