Skip to content

Commit

Permalink
statefulset: removing dangling resources from old postgres deployments
Browse files Browse the repository at this point in the history
  • Loading branch information
Shubhra Deshpande committed Oct 16, 2024
1 parent 39f7ddc commit dae241c
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion controllers/quay/quayregistry_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,16 @@ func (r *QuayRegistryReconciler) checkPostgresUpgradeStatus(
if job.Status.Succeeded == 1 {
log.Info(fmt.Sprintf("%s upgrade complete", jobName))
var oldPostgresDeploymentName string
var postgresDeploymentName string
if jobName == clairPostgresUpgradeJobName {
oldPostgresDeploymentName = fmt.Sprintf("%s-%s", quay.GetName(), "clair-postgres-old")
postgresDeploymentName = fmt.Sprintf("%s-%s", quay.GetName(), "clair-postgres")
} else {
oldPostgresDeploymentName = fmt.Sprintf("%s-%s", quay.GetName(), "quay-database-old")
postgresDeploymentName = fmt.Sprintf("%s-%s", quay.GetName(), "quay-database")
}
oldPostgresDeployment := &appsv1.Deployment{}
postgresDeployment := &appsv1.Deployment{}
if err := r.Client.Get(
ctx,
types.NamespacedName{
Expand All @@ -263,7 +267,20 @@ func (r *QuayRegistryReconciler) checkPostgresUpgradeStatus(
r.Log.Info(fmt.Sprintf("%s deployment not found, skipping", oldPostgresDeploymentName))
continue
}

if err := r.Client.Get(
ctx,
types.NamespacedName{
Name: postgresDeploymentName,
Namespace: quay.GetNamespace(),
},
postgresDeployment,
); err != nil {
r.Log.Info(fmt.Sprintf("%s deployment not found, skipping", postgresDeploymentName))
continue
}
if err := r.Client.Delete(ctx, postgresDeployment); err != nil {
r.Log.Error(err, fmt.Sprintf("%s deployment could not be deleted", postgresDeploymentName))
}
// Remove owner reference
obj, err := v1.RemoveOwnerReference(quay, oldPostgresDeployment)
if err != nil {
Expand Down

0 comments on commit dae241c

Please sign in to comment.