pg_dump icon indicating copy to clipboard operation
pg_dump copied to clipboard

Handle exit code of dump.sh to effective use in kubernetes (and more)

Open Dimama opened this issue 1 year ago • 2 comments

@Martlark hi Really appreciate your solution for database dump. Very handy and well documented

I use it to run as kubernetes cronjob (configuration simplified)

kind: CronJob
metadata:
  name: database-dump
  namespace: database-dump
spec:
  failedJobsHistoryLimit: 3
  successfulJobsHistoryLimit: 3
  schedule: "1 30 * * *"
  startingDeadlineSeconds: 600
  jobTemplate:
    spec:
      backoffLimit: 0
      template:
        metadata:
          name: database-dump
        spec:
          containers:
          - name: database-dump
            image: martlark/pg_dump:15.5
            command: ['./dump.sh']
            imagePullPolicy: Always
            env:
              - name: PGUSER
                value: user
              - name: POSTGRES_PASSWORD
                value: pass
              - name: POSTGRES_DB
                value: dbname
              - name: PGHOST
                value: host
              - name: S3_ACCESS_KEY
                value: secret_key
              - name: S3_SECRET_KEY
                value: access_key
              - name: S3_BUCKET_PATH
                value: bucket
              - name: S3_HOSTNAME
                value: s3_host
              - name: S3_HOST_BUCKET
                value: s3_host_bucket
              - name: S3_SYNC_OPTION
                value: --no-delete-removed
          restartPolicy: Never

It works great, but in case of some error inside dump.sh i got only error message and script return 0 exit code which interpreted by kubernetes as succeeded

I suggest to add handle exit code of main operations inside dump.sh and return error code in this cases as dump.sh result I believe this solution will help to increase effective number uses cases of your solution

If you like my suggestion, I can present my solution via Pull Request

Dimama avatar Apr 18 '24 11:04 Dimama

I've found a workaround to solve this problem in my case: set -e flag to bash

command: ['/bin/bash', '-e', 'dump.sh'] instead of command: ['./dump.sh']

Dimama avatar Apr 18 '24 11:04 Dimama

Thanks for the praise. Please add a pull request.

Best regards,

Andrew.


From: Дмитрий Мельников @.> Sent: Thursday, April 18, 2024 9:27:59 PM To: Martlark/pg_dump @.> Cc: Andrew Rowe @.>; Mention @.> Subject: Re: [Martlark/pg_dump] Handle exit code of dump.sh to effective use in kubernetes (and more) (Issue #20)

I've found a workaround to solve this problem in my case: set -e flag to bash

command: ['/bin/bash', '-e', 'dump.sh'] instead of command: ['./dump.sh']

— Reply to this email directly, view it on GitHubhttps://github.com/Martlark/pg_dump/issues/20#issuecomment-2063641246, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AA6JUB5FSXBUTUROHSMAPDDY56U37AVCNFSM6AAAAABGNBQLVCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANRTGY2DCMRUGY. You are receiving this because you were mentioned.Message ID: @.***>

Martlark avatar Apr 18 '24 11:04 Martlark