diff --git a/api/v1alpha1/database_types.go b/api/v1alpha1/database_types.go index ac0c329f..c86aed43 100644 --- a/api/v1alpha1/database_types.go +++ b/api/v1alpha1/database_types.go @@ -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) diff --git a/api/v1alpha1/database_webhook.go b/api/v1alpha1/database_webhook.go index 105d880e..d9c4fa97 100644 --- a/api/v1alpha1/database_webhook.go +++ b/api/v1alpha1/database_webhook.go @@ -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 { diff --git a/api/v1alpha1/zz_generated.deepcopy.go b/api/v1alpha1/zz_generated.deepcopy.go index 9d33e330..7a8a2fb8 100644 --- a/api/v1alpha1/zz_generated.deepcopy.go +++ b/api/v1alpha1/zz_generated.deepcopy.go @@ -141,8 +141,12 @@ func (in *Instance) DeepCopyInto(out *Instance) { } if in.DatabaseNames != nil { in, out := &in.DatabaseNames, &out.DatabaseNames - *out = make([]string, len(*in)) - copy(*out, *in) + *out = new([]string) + if **in != nil { + in, out := *in, *out + *out = make([]string, len(*in)) + copy(*out, *in) + } } if in.CredentialSecret != nil { in, out := &in.CredentialSecret, &out.CredentialSecret diff --git a/controller_adapters/database.go b/controller_adapters/database.go index a9aa69ba..7957220a 100644 --- a/controller_adapters/database.go +++ b/controller_adapters/database.go @@ -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 { diff --git a/controllers/database_controller_test.go b/controllers/database_controller_test.go index 72ec4576..1868f33a 100644 --- a/controllers/database_controller_test.go +++ b/controllers/database_controller_test.go @@ -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,