mongodb / mongodb-kubernetes-operator

MongoDB Community Kubernetes Operator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Statefulset: volumeClaimTemplates doesn't match volumeName annotation

jtorrex opened this issue · comments

What did you do to encounter the bug?
Steps to reproduce the behavior:

  1. Edit the statefulSet section on a MongoDBCommunity manifest
  2. Add the annotation volumeName on the statefulSet.spec section
...
  statefulSet:
    spec:
      volumeClaimTemplates:
      - metadata:
          name: data-volume #data-volume-mongodb-0
        spec:
          accessModes: ["ReadWriteOnce"]
          storageClassName: "gp3"
          resources:
            requests:
              storage: 10Gi
          volumeName: pv-data-mongodb
      - metadata:
          name: logs-volume #logs-volume-mongodb-0
        spec:
          accessModes: ["ReadWriteOnce"]
          storageClassName: "gp3"
          resources:
            requests:
              storage: 2Gi
          volumeName: pv-logs-mongodb
....

  1. Deploy the MongoDBCommunity
  2. List the PVC created from the StatefulSet
kubectl get pvc -n mongo
NAME                            STATUS   VOLUME                    CAPACITY   ACCESS MODES   STORAGECLASS   VOLUMEATTRIBUTESCLASS   AGE
data-volume-mongodb-0   Bound    pv-data-mongodb   10Gi       RWO            gp3            <unset>                 3h40m
logs-volume-mongodb-0   Bound    pv-logs-mongodb   2Gi        RWO            gp3            <unset>                 3h40m
  1. volumeName annotation is missing on the created PVC and points to another volume ID
kubectl get pvc -n mongo data-volume-mongodb-0  -o yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  annotations:
    pv.kubernetes.io/bind-completed: "yes"
    pv.kubernetes.io/bound-by-controller: "yes"
  creationTimestamp: "2024-05-08T10:52:47Z"
  finalizers:
  - kubernetes.io/pvc-protection
  labels:
    app: mongo-mongodb-svc
  name: data-volume-example-mongodb-0
  namespace: mongo
  resourceVersion: "10896712"
  uid: b520a41c-2cd5-494b-aac7-e25644f174d1
spec:
  accessModes:
  - ReadWriteOnce
  resources:
    requests:
      storage: 10Gi
  storageClassName: gp3
  volumeMode: Filesystem
  volumeName: pvc-e8b6ce3c-4c37-490e-8425-2591214424b8
status:
  accessModes:
  - ReadWriteOnce
  capacity:
    storage: 10Gi
  phase: Bound

What did you expect?

I expected that the annotation (volumeName) defined in the MongoDB statefulSet.spec will be populated to the newly created PersistentVolumeClaims.

What happened instead?

The PersistentVolumeClaim creates a new volume and isn't binded to the volumeName defined in the manifest.

Operator Information

  • Operator Version: quay.io/mongodb/mongodb-kubernetes-operator:0.7.9
  • MongoDB Image used: 6.0.5

Kubernetes Cluster Information

  • Distribution: EKS
  • Version: v1.29.3-eks-ae9a62a
  • Image Registry location (quay, or an internal registry): quay

Additional context
The idea was to mount a pre-existing PersistentVolume that I had, so following the official Kubernetes documentation, it can be bound to a PVC defining their name in the Spec section: https://kubernetes.io/docs/concepts/storage/persistent-volumes/#binding

This issue is being marked stale because it has been open for 60 days with no activity. Please comment if this issue is still affecting you. If there is no change, this issue will be closed in 30 days.