Skip to content

Commit c4cb5e5

Browse files
authored
Fix reconcile logic dependent on password (#285)
1 parent d237f3a commit c4cb5e5

5 files changed

Lines changed: 20 additions & 13 deletions

File tree

api/v1alpha1/postgresqldatabase_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type PostgreSQLDatabaseSpec struct {
3838

3939
// Password used with the User name to connect to the database
4040
// +optional
41-
Password ResourceVar `json:"password"`
41+
Password *ResourceVar `json:"password"`
4242

4343
// IsShared indicates whether the database is shared between multiple
4444
// PostgreSQLDatabase objects. The controller will not grant ownership of the

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controllers/postgresqldatabase_controller.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,12 @@ func (r *PostgreSQLDatabaseReconciler) reconcile(ctx context.Context, reqLogger
121121
}
122122
status.user = user
123123
reqLogger = reqLogger.WithValues("user", user)
124-
password, err := kube.ResourceValue(r.Client, database.Spec.Password, request.Namespace)
125-
if err != nil {
126-
return status, fmt.Errorf("resolve password reference: %w", err)
124+
password := ""
125+
if database.Spec.Password != nil {
126+
password, err = kube.ResourceValue(r.Client, *database.Spec.Password, request.Namespace)
127+
if err != nil {
128+
return status, fmt.Errorf("resolve password reference: %w", err)
129+
}
127130
}
128131
isShared := database.Spec.IsShared
129132

controllers/postgresqldatabase_controller_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func TestPostgreSQLDatabase_Reconcile_hostCredentialsResourceReference(t *testin
207207
Spec: lunarwayv1alpha1.PostgreSQLDatabaseSpec{
208208
Name: databaseName,
209209
HostCredentials: hostCredentialsName,
210-
Password: lunarwayv1alpha1.ResourceVar{
210+
Password: &lunarwayv1alpha1.ResourceVar{
211211
Value: "123456",
212212
},
213213
User: lunarwayv1alpha1.ResourceVar{
@@ -369,7 +369,7 @@ func TestPostgreSQLDatabase_Reconcile_unknownHostCredentialsResourceReference(t
369369
Spec: lunarwayv1alpha1.PostgreSQLDatabaseSpec{
370370
Name: databaseName,
371371
HostCredentials: "unknown",
372-
Password: lunarwayv1alpha1.ResourceVar{
372+
Password: &lunarwayv1alpha1.ResourceVar{
373373
Value: "123456",
374374
},
375375
User: lunarwayv1alpha1.ResourceVar{

controllers/postgresqluser_controller_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ func TestReconcile_badConfigmapReference(t *testing.T) {
7878
Host: lunarwayv1alpha1.ResourceVar{
7979
Value: host,
8080
},
81-
Password: lunarwayv1alpha1.ResourceVar{
81+
Password: &lunarwayv1alpha1.ResourceVar{
8282
Value: "user_password",
8383
},
8484
User: lunarwayv1alpha1.ResourceVar{
@@ -102,7 +102,7 @@ func TestReconcile_badConfigmapReference(t *testing.T) {
102102
},
103103
},
104104
},
105-
Password: lunarwayv1alpha1.ResourceVar{
105+
Password: &lunarwayv1alpha1.ResourceVar{
106106
Value: "12346",
107107
},
108108
User: lunarwayv1alpha1.ResourceVar{
@@ -216,7 +216,7 @@ func TestReconcile_rolePrefix(t *testing.T) {
216216
Host: lunarwayv1alpha1.ResourceVar{
217217
Value: host,
218218
},
219-
Password: lunarwayv1alpha1.ResourceVar{
219+
Password: &lunarwayv1alpha1.ResourceVar{
220220
Value: database1Name,
221221
},
222222
User: lunarwayv1alpha1.ResourceVar{
@@ -335,7 +335,7 @@ func TestReconcile_dotInName(t *testing.T) {
335335
Host: lunarwayv1alpha1.ResourceVar{
336336
Value: host,
337337
},
338-
Password: lunarwayv1alpha1.ResourceVar{
338+
Password: &lunarwayv1alpha1.ResourceVar{
339339
Value: "user_password",
340340
},
341341
User: lunarwayv1alpha1.ResourceVar{
@@ -462,7 +462,7 @@ func TestReconcile_multipleDatabaseResources(t *testing.T) {
462462
Host: lunarwayv1alpha1.ResourceVar{
463463
Value: host,
464464
},
465-
Password: lunarwayv1alpha1.ResourceVar{
465+
Password: &lunarwayv1alpha1.ResourceVar{
466466
Value: "user_password",
467467
},
468468
User: lunarwayv1alpha1.ResourceVar{
@@ -483,7 +483,7 @@ func TestReconcile_multipleDatabaseResources(t *testing.T) {
483483
Host: lunarwayv1alpha1.ResourceVar{
484484
Value: host,
485485
},
486-
Password: lunarwayv1alpha1.ResourceVar{
486+
Password: &lunarwayv1alpha1.ResourceVar{
487487
Value: "user_password",
488488
},
489489
User: lunarwayv1alpha1.ResourceVar{

0 commit comments

Comments
 (0)