( ctx context.Context, c client.Client, cluster *apiv1.Cluster, )
| 224 | } |
| 225 | |
| 226 | func getOrphanPVCs( |
| 227 | ctx context.Context, |
| 228 | c client.Client, |
| 229 | cluster *apiv1.Cluster, |
| 230 | ) ([]corev1.PersistentVolumeClaim, error) { |
| 231 | contextLogger := log.FromContext(ctx).WithValues("step", "get_orphan_pvcs") |
| 232 | |
| 233 | var pvcList corev1.PersistentVolumeClaimList |
| 234 | if err := c.List( |
| 235 | ctx, |
| 236 | &pvcList, |
| 237 | client.InNamespace(cluster.Namespace), |
| 238 | client.MatchingLabels{utils.ClusterLabelName: cluster.Name}, |
| 239 | ); err != nil { |
| 240 | return nil, err |
| 241 | } |
| 242 | |
| 243 | orphanPVCs := make([]corev1.PersistentVolumeClaim, 0, len(pvcList.Items)) |
| 244 | for _, pvc := range pvcList.Items { |
| 245 | if len(pvc.OwnerReferences) != 0 { |
| 246 | contextLogger.Warning("skipping pvc because it has owner metadata", |
| 247 | "pvcName", pvc.Name) |
| 248 | continue |
| 249 | } |
| 250 | if _, ok := pvc.Annotations[utils.ClusterSerialAnnotationName]; !ok { |
| 251 | contextLogger.Warning("skipping pvc because it doesn't have serial annotation", |
| 252 | "pvcName", pvc.Name) |
| 253 | continue |
| 254 | } |
| 255 | |
| 256 | orphanPVCs = append(orphanPVCs, pvc) |
| 257 | } |
| 258 | |
| 259 | return orphanPVCs, nil |
| 260 | } |
| 261 | |
| 262 | func ensureOrphanPodsAreDeleted(ctx context.Context, c client.Client, cluster *apiv1.Cluster) error { |
| 263 | contextLogger := log.FromContext(ctx).WithName("orphan_pod_cleaner") |
no test coverage detected