MCPcopy Create free account
hub / github.com/cloudnative-pg/cloudnative-pg / getOrphanPVCs

Function getOrphanPVCs

internal/controller/cluster_restore.go:226–260  ·  view source on GitHub ↗
(
	ctx context.Context,
	c client.Client,
	cluster *apiv1.Cluster,
)

Source from the content-addressed store, hash-verified

224}
225
226func 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
262func ensureOrphanPodsAreDeleted(ctx context.Context, c client.Client, cluster *apiv1.Cluster) error {
263 contextLogger := log.FromContext(ctx).WithName("orphan_pod_cleaner")

Callers 2

Calls 3

WarningMethod · 0.80
WithValuesMethod · 0.45
ListMethod · 0.45

Tested by

no test coverage detected