Skip to content

Commit

Permalink
Converting databaseNames field into a pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
akshmish committed Jul 14, 2023
1 parent ca00e83 commit 959ac74
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha1/database_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type Instance struct {
// Name(s) of the database(s) to be provisiond inside the database instance
// default [ "database_one", "database_two", "database_three" ]
// +optional
DatabaseNames []string `json:"databaseNames"`
DatabaseNames *[]string `json:"databaseNames"`
// Name of the secret holding the credentials for the database instance (password and ssh key)
CredentialSecret *string `json:"credentialSecret"`
// Size of the database instance, minimum 10 (GBs)
Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha1/database_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ var _ webhook.Defaulter = &Database{}

func instanceSpecDefaulterForCreate(r *Database) {

if len(r.Spec.Instance.DatabaseNames) == 0 {
r.Spec.Instance.DatabaseNames = api.DefaultDatabaseNames
if len(*r.Spec.Instance.DatabaseNames) == 0 {
r.Spec.Instance.DatabaseNames = &api.DefaultDatabaseNames
}

if r.Spec.Instance.TimeZone == nil {
Expand Down
8 changes: 6 additions & 2 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion controller_adapters/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (d *Database) GetDBInstanceType() string {
}

func (d *Database) GetDBInstanceDatabaseNames() string {
return strings.Join(d.Spec.Instance.DatabaseNames, ",")
return strings.Join(*d.Spec.Instance.DatabaseNames, ",")
}

func (d *Database) GetDBInstanceTimeZone() string {
Expand Down
2 changes: 1 addition & 1 deletion controllers/database_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ var _ = Describe("Database controller", func() {
},
Instance: ndbv1alpha1.Instance{
DatabaseInstanceName: &DatabaseName,
DatabaseNames: []string{"database_1"},
DatabaseNames: &[]string{"database_1"},
CredentialSecret: &instanceSecretName,
Size: &databaseSize,
TimeZone: &timezoneUTC,
Expand Down

0 comments on commit 959ac74

Please sign in to comment.