zalando / zalando/postgres-operator

Sidecar ports and env settings are not parsed and created in statefulset.

Open
#1,245 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

  • Which image of the operator are you using? e.g. registry.opensource.zalan.do/acid/postgres-operator:v1.5.0
  • Where do you run it - cloud or metal? Kubernetes or OpenShift? [ GCP GKE ]
  • Are you running Postgres Operator in production? [ no ]
  • Type of issue? [ Bug report ]

Hi,
I am trying to deploy my first database using your postgres-operator. I am creating a simple postgresql object with postgres_exporter as a sidecar for monitoring purposes.

kind: postgresql
metadata:
  name: acid-minimal-cluster
spec:
  teamId: "ACID"
  volume:
    size: 1Gi
  numberOfInstances: 2
  users:
    # database owner
    zalando:
    - superuser
    - createdb
  databases:
    foo: zalando
  postgresql:
    version: "10"
  sidecars:
    - name: postgres-exporter
      image: wrouesnel/postgres_exporter
      ports:
        - containerPort: 9187

It comes from minimal example that can be found here: https://postgres-operator.readthedocs.io/en/refactoring-sidecars/user/
After applying this resource, a statefulset is created, but it has some values missing:

        - name: POD_NAME
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: metadata.name
        - name: POD_NAMESPACE
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: metadata.namespace
        - name: POSTGRES_USER
          value: postgres
        - name: POSTGRES_PASSWORD
          valueFrom:
            secretKeyRef:
              key: password
              name: postgres.acid-minimal-cluster.credentials.postgresql.acid.zalan.do
        image: wrouesnel/postgres_exporter
        imagePullPolicy: IfNotPresent
        name: postgres-exporter
        ports:
        - containerPort: 0
          protocol: TCP
        resources:
          limits:
            cpu: "1"
            memory: 500Mi
          requests:
            cpu: 100m
            memory: 100Mi
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /home/postgres/pgdata
          name: pgdata

Same happens with variables, they are created as empty entries - {} and I cannot get my sidecar working. As a result, the statefulset is failing to create pods:
Warning FailedCreate 38s (x17 over 6m6s) statefulset-controller create Pod acid-minimal-cluster-0 in StatefulSet acid-minimal-cluster failed error: Pod "acid-minimal-cluster-0" is invalid: spec.containers[1].ports[0].containerPort: Required value

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 refactoring-sidecars minimal example in the linked documentation and trace how the PostgreSQL resource's sidecars are parsed into the generated StatefulSet. Reproduce the example, then verify that sidecar ports and environment variables are retained and that the resulting Pod passes Kubernetes validation.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, kubernetes, postgresql
Domain
databases, infrastructure
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.