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

Function restoreOrphanPVCs

internal/controller/cluster_restore.go:330–357  ·  view source on GitHub ↗

restoreOrphanPVCs sets the owner metadata and re-actives the orphan pvcs

(
	ctx context.Context,
	c client.Client,
	cluster *apiv1.Cluster,
	pvcs []corev1.PersistentVolumeClaim,
)

Source from the content-addressed store, hash-verified

328
329// restoreOrphanPVCs sets the owner metadata and re-actives the orphan pvcs
330func restoreOrphanPVCs(
331 ctx context.Context,
332 c client.Client,
333 cluster *apiv1.Cluster,
334 pvcs []corev1.PersistentVolumeClaim,
335) error {
336 for i := range pvcs {
337 pvc := &pvcs[i]
338 if pvc.Annotations == nil {
339 pvc.Annotations = map[string]string{}
340 }
341
342 pvcOrig := pvc.DeepCopy()
343 cluster.SetInheritedDataAndOwnership(&pvc.ObjectMeta)
344 pvc.Annotations[utils.PVCStatusAnnotationName] = persistentvolumeclaim.StatusReady
345 // we clean hibernation metadata if it exists
346 delete(pvc.Annotations, utils.HibernateClusterManifestAnnotationName)
347 delete(pvc.Annotations, utils.HibernatePgControlDataAnnotationName)
348 delete(pvc.Annotations, utils.ClusterManifestAnnotationName)
349 delete(pvc.Annotations, utils.PgControldataAnnotationName)
350
351 if err := c.Patch(ctx, pvc, client.MergeFrom(pvcOrig)); err != nil {
352 return err
353 }
354 }
355
356 return nil
357}
358
359func ensureInitContainersAreCompleted(
360 ctx context.Context,

Callers 2

Calls 3

DeepCopyMethod · 0.45
PatchMethod · 0.45

Tested by

no test coverage detected