zalando / zalando/postgres-operator

Feature: Restore cluster to existing pv's (with the same name with the same namespace)

Open
#1,900 3 comments 23 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

idea
Dominant language
Go
Stars
5.2k
Forks
1.1k
Avg merge
2d 16h
Merged PRs (30d)
3

Description

  • Type of issue? feature request
  • Where do you run it - cloud or metal? metal
  • Which image of the operator are you using? 1.8.0 version
  • Are you running Postgres Operator in production? yes

Hello everyone!
Could you add functionality to install a cluster with existing pv (the case when someone accidentally deleted the cluster but the pv disks remained). I made a script that can generate pvc from existing pv deleted cluster, which is then successfully mounted by the operator - I checked (it is important that the namespace, cluster name and TeamID match the old values)

#!/bin/bash
VOLUME_SIZE=$2
NAMESPACE=$3
if [[ -z $3 ]];then
  echo No args
  echo Use command for example:
  echo $0 10Gi namespace "pv_id_1 pv_id_2 pv_id_3"
  exit 1
fi
EGREP_STR=$(echo $2 | tr ' ' '|')
PVC=$(kubectl get pv|egrep $EGREP_STR)
if [[ -n $PVC ]];then
  while IFS= read -r line
  do
    PV_NAME=$(echo $line|awk '{print $1}')
    PVC_NAME=$(echo $line|awk '{print $6}'|cut -d '/' -f 2)
    kubectl -n $NAMESPACE patch pv  --type json -p '[{"op": "remove", "path": "/spec/claimRef"}]' $PV_NAME
cat <<EOF | kubectl -n $NAMESPACE apply -f -
---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
  name: ${PVC_NAME}
spec:
  accessModes:
    - ReadWriteOnce
  resources:
    requests:
      storage: ${VOLUME_SIZE}
  volumeName: ${PV_NAME}
EOF
  break
  done <<< "$PVC"
else
  echo "PVC var is empy"
  exit 1
fi

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided kubectl recovery script and reproduce its PV claimRef removal and PVC recreation flow using matching namespace, cluster name, and TeamID. Trace the operator entry points that create or reconcile the cluster's PVCs, then define tests for recreating a deleted cluster while reusing the existing PVs and verify that the PostgreSQL data is mounted successfully.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, kubernetes, postgresql, shell
Domain
databases, infrastructure
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.