diff --git a/create/mysqldatabase.go b/create/mysqldatabase.go index 9108896..fa4c09b 100644 --- a/create/mysqldatabase.go +++ b/create/mysqldatabase.go @@ -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 { @@ -76,6 +77,7 @@ func (cmd *mysqlDatabaseCmd) newMySQLDatabase(namespace string) *storage.MySQLDa CharacterSet: storage.MySQLCharacterSet{ Name: cmd.CharacterSet, }, + BackupSchedule: cmd.BackupSchedule, }, }, } @@ -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 } diff --git a/create/postgresdatabase.go b/create/postgresdatabase.go index be699f5..026382f 100644 --- a/create/postgresdatabase.go +++ b/create/postgresdatabase.go @@ -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 { @@ -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, }, }, } @@ -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 } diff --git a/go.mod b/go.mod index 294911b..d18e1f3 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 90e0d70..63306aa 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/update/mysqldatabase.go b/update/mysqldatabase.go index db790a9..2001a5b 100644 --- a/update/mysqldatabase.go +++ b/update/mysqldatabase.go @@ -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 { @@ -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 + } } diff --git a/update/mysqldatabase_test.go b/update/mysqldatabase_test.go index 513f2a2..65dbad0 100644 --- a/update/mysqldatabase_test.go +++ b/update/mysqldatabase_test.go @@ -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) { @@ -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) { diff --git a/update/postgresdatabase.go b/update/postgresdatabase.go index 2451726..da8e916 100644 --- a/update/postgresdatabase.go +++ b/update/postgresdatabase.go @@ -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 { @@ -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 + } } diff --git a/update/postgresdatabase_test.go b/update/postgresdatabase_test.go index 42c2b51..14d2322 100644 --- a/update/postgresdatabase_test.go +++ b/update/postgresdatabase_test.go @@ -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) { @@ -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) {