Skip to content

Commit

Permalink
Fix reconcile logic dependent on password (#285)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmablunar authored Mar 15, 2024
1 parent d237f3a commit c4cb5e5
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion api/v1alpha1/postgresqldatabase_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ type PostgreSQLDatabaseSpec struct {

// Password used with the User name to connect to the database
// +optional
Password ResourceVar `json:"password"`
Password *ResourceVar `json:"password"`

// IsShared indicates whether the database is shared between multiple
// PostgreSQLDatabase objects. The controller will not grant ownership of the
Expand Down
6 changes: 5 additions & 1 deletion api/v1alpha1/zz_generated.deepcopy.go

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

9 changes: 6 additions & 3 deletions controllers/postgresqldatabase_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,12 @@ func (r *PostgreSQLDatabaseReconciler) reconcile(ctx context.Context, reqLogger
}
status.user = user
reqLogger = reqLogger.WithValues("user", user)
password, err := kube.ResourceValue(r.Client, database.Spec.Password, request.Namespace)
if err != nil {
return status, fmt.Errorf("resolve password reference: %w", err)
password := ""
if database.Spec.Password != nil {
password, err = kube.ResourceValue(r.Client, *database.Spec.Password, request.Namespace)
if err != nil {
return status, fmt.Errorf("resolve password reference: %w", err)
}
}
isShared := database.Spec.IsShared

Expand Down
4 changes: 2 additions & 2 deletions controllers/postgresqldatabase_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func TestPostgreSQLDatabase_Reconcile_hostCredentialsResourceReference(t *testin
Spec: lunarwayv1alpha1.PostgreSQLDatabaseSpec{
Name: databaseName,
HostCredentials: hostCredentialsName,
Password: lunarwayv1alpha1.ResourceVar{
Password: &lunarwayv1alpha1.ResourceVar{
Value: "123456",
},
User: lunarwayv1alpha1.ResourceVar{
Expand Down Expand Up @@ -369,7 +369,7 @@ func TestPostgreSQLDatabase_Reconcile_unknownHostCredentialsResourceReference(t
Spec: lunarwayv1alpha1.PostgreSQLDatabaseSpec{
Name: databaseName,
HostCredentials: "unknown",
Password: lunarwayv1alpha1.ResourceVar{
Password: &lunarwayv1alpha1.ResourceVar{
Value: "123456",
},
User: lunarwayv1alpha1.ResourceVar{
Expand Down
12 changes: 6 additions & 6 deletions controllers/postgresqluser_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func TestReconcile_badConfigmapReference(t *testing.T) {
Host: lunarwayv1alpha1.ResourceVar{
Value: host,
},
Password: lunarwayv1alpha1.ResourceVar{
Password: &lunarwayv1alpha1.ResourceVar{
Value: "user_password",
},
User: lunarwayv1alpha1.ResourceVar{
Expand All @@ -102,7 +102,7 @@ func TestReconcile_badConfigmapReference(t *testing.T) {
},
},
},
Password: lunarwayv1alpha1.ResourceVar{
Password: &lunarwayv1alpha1.ResourceVar{
Value: "12346",
},
User: lunarwayv1alpha1.ResourceVar{
Expand Down Expand Up @@ -216,7 +216,7 @@ func TestReconcile_rolePrefix(t *testing.T) {
Host: lunarwayv1alpha1.ResourceVar{
Value: host,
},
Password: lunarwayv1alpha1.ResourceVar{
Password: &lunarwayv1alpha1.ResourceVar{
Value: database1Name,
},
User: lunarwayv1alpha1.ResourceVar{
Expand Down Expand Up @@ -335,7 +335,7 @@ func TestReconcile_dotInName(t *testing.T) {
Host: lunarwayv1alpha1.ResourceVar{
Value: host,
},
Password: lunarwayv1alpha1.ResourceVar{
Password: &lunarwayv1alpha1.ResourceVar{
Value: "user_password",
},
User: lunarwayv1alpha1.ResourceVar{
Expand Down Expand Up @@ -462,7 +462,7 @@ func TestReconcile_multipleDatabaseResources(t *testing.T) {
Host: lunarwayv1alpha1.ResourceVar{
Value: host,
},
Password: lunarwayv1alpha1.ResourceVar{
Password: &lunarwayv1alpha1.ResourceVar{
Value: "user_password",
},
User: lunarwayv1alpha1.ResourceVar{
Expand All @@ -483,7 +483,7 @@ func TestReconcile_multipleDatabaseResources(t *testing.T) {
Host: lunarwayv1alpha1.ResourceVar{
Value: host,
},
Password: lunarwayv1alpha1.ResourceVar{
Password: &lunarwayv1alpha1.ResourceVar{
Value: "user_password",
},
User: lunarwayv1alpha1.ResourceVar{
Expand Down

0 comments on commit c4cb5e5

Please sign in to comment.