@@ -80,6 +80,7 @@ func (r *PostgreSQLReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error)
80
80
return r .updateAndReturn (& ctx , & postgresql , & log )
81
81
}
82
82
83
+ // - garbage collection
83
84
// if host is changed, drop credentials for old host. Keep database & data for now, until we figure out what we'll do with it
84
85
// TODO refactor to have a general garbage collector mechanism, instead of code throughout controller
85
86
if postgresql .Spec .Host != postgresql .Status .DatabaseStatus .Host {
@@ -109,6 +110,7 @@ func (r *PostgreSQLReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error)
109
110
return r .updateAndReturn (& ctx , & postgresql , & log )
110
111
}
111
112
113
+ // - garbage collection
112
114
// TODO for now, disallow database renaming
113
115
if postgresql .Spec .DatabaseName != postgresql .Status .DatabaseStatus .Name && postgresql .Status .DatabaseStatus .Name != "" {
114
116
postgresql .Status .DatabaseStatus .SetDatabaseStatus (infrav1beta1 .Unavailable , "Cannot change the name of the database." , "" , postgresql .Spec .Host )
@@ -126,6 +128,7 @@ func (r *PostgreSQLReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error)
126
128
}
127
129
postgresql .Status .DatabaseStatus .SetDatabaseStatus (infrav1beta1 .Available , "Database up." , postgresql .Spec .DatabaseName , postgresql .Spec .Host )
128
130
131
+ // - garbage collection
129
132
// Delete all credentials if they exist, and are no longer required by spec
130
133
if postgresql .Spec .Credentials == nil {
131
134
postgresql .Status .CredentialsStatus .ForEach (func (status * infrav1beta1.CredentialStatus ) {
@@ -157,6 +160,7 @@ func (r *PostgreSQLReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error)
157
160
}
158
161
}
159
162
163
+ // - garbage collection
160
164
// remove all statuses for credentials that are no longer required by spec, and delete users in database
161
165
postgresql .RemoveUnneededCredentialsStatus ().ForEach (func (status * infrav1beta1.CredentialStatus ) {
162
166
_ = postgreSQLServer .DropUser (status .Username , postgresql .Status .DatabaseStatus .Name )
0 commit comments