From 4febe900c0b2116d328b9fcff68f50efe4d5d8a7 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 17 Apr 2025 14:40:02 +0200 Subject: [PATCH 01/13] chore(deps): update all cloudnative-pg daggerverse dependencies to ba86584 (#112) Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Signed-off-by: Fouad Semaan --- Taskfile.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index f3fea28b..48b63007 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -5,7 +5,7 @@ tasks: desc: Run controller-gen env: # renovate: datasource=git-refs depName=controller-gen lookupName=https://github.com/cloudnative-pg/daggerverse currentValue=main - DAGGER_CONTROLLER_GEN_SHA: 6dd81e0cdd946d5dde24f044f66f1ed8111758cf + DAGGER_CONTROLLER_GEN_SHA: ba865842d907910c469d016c3ecfa009e4c66915 cmds: - > GITHUB_REF= dagger -s call -m github.com/cloudnative-pg/daggerverse/controller-gen@${DAGGER_CONTROLLER_GEN_SHA} @@ -20,7 +20,7 @@ tasks: desc: Run spellcheck env: # renovate: datasource=git-refs depName=spellcheck lookupName=https://github.com/cloudnative-pg/daggerverse currentValue=main - DAGGER_SPELLCHECK_SHA: 6dd81e0cdd946d5dde24f044f66f1ed8111758cf + DAGGER_SPELLCHECK_SHA: ba865842d907910c469d016c3ecfa009e4c66915 cmds: - > GITHUB_REF= dagger -s call -m github.com/cloudnative-pg/daggerverse/spellcheck@${DAGGER_SPELLCHECK_SHA} @@ -48,7 +48,7 @@ tasks: desc: Check for conventional commits env: # renovate: datasource=git-refs depName=commitlint lookupName=https://github.com/cloudnative-pg/daggerverse currentValue=main - DAGGER_COMMITLINT_SHA: 6dd81e0cdd946d5dde24f044f66f1ed8111758cf + DAGGER_COMMITLINT_SHA: ba865842d907910c469d016c3ecfa009e4c66915 cmds: - GITHUB_REF= dagger -s call -m github.com/cloudnative-pg/daggerverse/commitlint@${DAGGER_COMMITLINT_SHA} lint --source . --args "--from=origin/main" stdout @@ -58,7 +58,7 @@ tasks: - controller-gen env: # renovate: datasource=git-refs depName=uncommitted lookupName=https://github.com/cloudnative-pg/daggerverse currentValue=main - DAGGER_UNCOMMITTED_SHA: 6dd81e0cdd946d5dde24f044f66f1ed8111758cf + DAGGER_UNCOMMITTED_SHA: ba865842d907910c469d016c3ecfa009e4c66915 cmds: - > GITHUB_REF= dagger -s call -m github.com/cloudnative-pg/daggerverse/uncommitted@${DAGGER_UNCOMMITTED_SHA} From 43a1ed26d95591cb8ea28b2e4b2fc3f222a7b3be Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 17 Apr 2025 15:52:03 +0200 Subject: [PATCH 02/13] fix(deps): update all non-major go dependencies (#109) | datasource | package | from | to | | ---------- | ------------------------- | ------- | ------- | | go | github.com/onsi/ginkgo/v2 | v2.23.3 | v2.23.4 | | go | github.com/onsi/gomega | v1.36.3 | v1.37.0 | Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Signed-off-by: Fouad Semaan --- go.mod | 11 ++++++----- go.sum | 24 ++++++++++++++---------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index a3f50997..111f05d2 100644 --- a/go.mod +++ b/go.mod @@ -6,8 +6,8 @@ toolchain go1.24.2 require ( github.com/cloudnative-pg/machinery v0.2.0 - github.com/onsi/ginkgo/v2 v2.23.3 - github.com/onsi/gomega v1.36.3 + github.com/onsi/ginkgo/v2 v2.23.4 + github.com/onsi/gomega v1.37.0 k8s.io/api v0.32.3 k8s.io/apimachinery v0.32.3 sigs.k8s.io/controller-runtime v0.20.4 @@ -33,7 +33,7 @@ require ( github.com/google/gnostic-models v0.6.8 // indirect github.com/google/go-cmp v0.7.0 // indirect github.com/google/gofuzz v1.2.0 // indirect - github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect + github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 // indirect github.com/google/uuid v1.6.0 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/json-iterator/go v1.1.12 // indirect @@ -51,16 +51,17 @@ require ( github.com/spf13/pflag v1.0.6 // indirect github.com/thoas/go-funk v0.9.3 // indirect github.com/x448/float16 v0.8.4 // indirect + go.uber.org/automaxprocs v1.6.0 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.27.0 // indirect golang.org/x/net v0.37.0 // indirect golang.org/x/oauth2 v0.23.0 // indirect golang.org/x/sync v0.12.0 // indirect - golang.org/x/sys v0.31.0 // indirect + golang.org/x/sys v0.32.0 // indirect golang.org/x/term v0.30.0 // indirect golang.org/x/text v0.23.0 // indirect golang.org/x/time v0.7.0 // indirect - golang.org/x/tools v0.30.0 // indirect + golang.org/x/tools v0.31.0 // indirect gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect google.golang.org/protobuf v1.36.5 // indirect gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect diff --git a/go.sum b/go.sum index ca3b8325..24b4e0a2 100644 --- a/go.sum +++ b/go.sum @@ -44,8 +44,8 @@ github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= -github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad h1:a6HEuzUHeKH6hwfN/ZoQgRgVIWFJljSWa/zetS2WTvg= -github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144= +github.com/google/pprof v0.0.0-20250403155104-27863c87afa6 h1:BHT72Gu3keYf3ZEu2J0b1vyeLSOYI8bm5wbJM/8yDe8= +github.com/google/pprof v0.0.0-20250403155104-27863c87afa6/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= @@ -73,15 +73,17 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= -github.com/onsi/ginkgo/v2 v2.23.3 h1:edHxnszytJ4lD9D5Jjc4tiDkPBZ3siDeJJkUZJJVkp0= -github.com/onsi/ginkgo/v2 v2.23.3/go.mod h1:zXTP6xIp3U8aVuXN8ENK9IXRaTjFnpVB9mGmaSRvxnM= -github.com/onsi/gomega v1.36.3 h1:hID7cr8t3Wp26+cYnfcjR6HpJ00fdogN6dqZ1t6IylU= -github.com/onsi/gomega v1.36.3/go.mod h1:8D9+Txp43QWKhM24yyOBEdpkzN8FvJyAwecBgsU4KU0= +github.com/onsi/ginkgo/v2 v2.23.4 h1:ktYTpKJAVZnDT4VjxSbiBenUjmlL/5QkBEocaWXiQus= +github.com/onsi/ginkgo/v2 v2.23.4/go.mod h1:Bt66ApGPBFzHyR+JO10Zbt0Gsp4uWxu5mIOTusL46e8= +github.com/onsi/gomega v1.37.0 h1:CdEG8g0S133B4OswTDC/5XPSzE1OeP29QOioj2PID2Y= +github.com/onsi/gomega v1.37.0/go.mod h1:8D9+Txp43QWKhM24yyOBEdpkzN8FvJyAwecBgsU4KU0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/prashantv/gostub v1.1.0 h1:BTyx3RfQjRHnUWaGF9oQos79AlQ5k8WNktv7VGvVH4g= +github.com/prashantv/gostub v1.1.0/go.mod h1:A5zLQHz7ieHGG7is6LLXLz7I8+3LZzsrV0P1IAHhP5U= github.com/prometheus/client_golang v1.20.3 h1:oPksm4K8B+Vt35tUhw6GbSNSgVlVSBH0qELP/7u83l4= github.com/prometheus/client_golang v1.20.3/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p8ais2e9E= @@ -105,6 +107,8 @@ github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= +go.uber.org/automaxprocs v1.6.0 h1:O3y2/QNTOdbF+e/dpXNNW7Rx2hZ4sTIPyybbxyNqTUs= +go.uber.org/automaxprocs v1.6.0/go.mod h1:ifeIMSnPZuznNm6jmdzmU3/bfk01Fe2fotchwEFJ8r8= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0= @@ -132,8 +136,8 @@ golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= -golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= +golang.org/x/sys v0.32.0 h1:s77OFDvIQeibCmezSnk/q6iAfkdiQaJi4VzroCFrN20= +golang.org/x/sys v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/term v0.30.0 h1:PQ39fJZ+mfadBm0y5WlL4vlM7Sx1Hgf13sMIY2+QS9Y= golang.org/x/term v0.30.0/go.mod h1:NYYFdzHoI5wRh/h5tDMdMqCqPJZEuNqVR5xJLd/n67g= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -146,8 +150,8 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.30.0 h1:BgcpHewrV5AUp2G9MebG4XPFI1E2W41zU1SaqVA9vJY= -golang.org/x/tools v0.30.0/go.mod h1:c347cR/OJfw5TI+GfX7RUPNMdDRRbjvYTS0jPyvsVtY= +golang.org/x/tools v0.31.0 h1:0EedkvKDbh+qistFTd0Bcwe/YLh4vHwWEkiI0toFIBU= +golang.org/x/tools v0.31.0/go.mod h1:naFTU+Cev749tSJRXJlna0T3WxKvb1kWEx15xA4SdmQ= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= From f2fedaf8e541a6e945e5dcee60841f4bfe1d584e Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 17 Apr 2025 17:40:27 +0200 Subject: [PATCH 03/13] chore(deps): update golangci-lint digest to ceffda4 (#104) Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Signed-off-by: Fouad Semaan --- Taskfile.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Taskfile.yml b/Taskfile.yml index 48b63007..d4a4dab1 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -32,7 +32,7 @@ tasks: desc: Run golangci-lint env: # renovate: datasource=git-refs depName=golangci-lint lookupName=https://github.com/sagikazarmark/daggerverse currentValue=main - DAGGER_GOLANGCI_LINT_SHA: b228768ec6429e7abbef0db40fdb898ca1b836d8 + DAGGER_GOLANGCI_LINT_SHA: ceffda4aebd349a24fc00e591b4ed9b801535b65 # renovate: datasource=docker depName=golangci/golangci-lint versioning=semver GOLANGCI_LINT_VERSION: v2.1.2 cmds: From 7afa902947106086ff83845ccb9051bc6baad6d4 Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 17 Apr 2025 19:54:05 +0000 Subject: [PATCH 04/13] chore(deps): update go digest to ceffda4 (#102) Signed-off-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Signed-off-by: Fouad Semaan --- Taskfile.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Taskfile.yml b/Taskfile.yml index d4a4dab1..2cd01d52 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -74,7 +74,7 @@ tasks: # renovate: datasource=docker depName=golang versioning=semver GOLANG_IMAGE_VERSION: 1.24.2 # renovate: datasource=git-refs depName=go lookupName=https://github.com/sagikazarmark/daggerverse currentValue=main - DAGGER_GO_SHA: d086950194ebe9b64876833b881e66cc58b6ec27 + DAGGER_GO_SHA: ceffda4aebd349a24fc00e591b4ed9b801535b65 cmds: - > GITHUB_REF= dagger -s call -m github.com/sagikazarmark/daggerverse/go@${DAGGER_GO_SHA} From b87a9a63345172fef45dc2ddaa954af565b468a3 Mon Sep 17 00:00:00 2001 From: MichaluxPL <68371308+MichaluxPL@users.noreply.github.com> Date: Tue, 22 Apr 2025 10:14:17 +0200 Subject: [PATCH 05/13] chore: remove stale GatherWALFilesToArchive function (#111) Signed-off-by: MichaluxPL <68371308+MichaluxPL@users.noreply.github.com> Signed-off-by: Leonardo Cecchi Co-authored-by: Leonardo Cecchi Signed-off-by: Fouad Semaan --- pkg/archiver/command.go | 85 ----------------------------------------- 1 file changed, 85 deletions(-) diff --git a/pkg/archiver/command.go b/pkg/archiver/command.go index a757f97a..d77aa7f1 100644 --- a/pkg/archiver/command.go +++ b/pkg/archiver/command.go @@ -18,98 +18,13 @@ package archiver import ( "context" - "errors" "fmt" - "math" - "os" - "path" - "path/filepath" - "strings" - - "github.com/cloudnative-pg/machinery/pkg/log" barmanApi "github.com/cloudnative-pg/barman-cloud/pkg/api" barmanCommand "github.com/cloudnative-pg/barman-cloud/pkg/command" "github.com/cloudnative-pg/barman-cloud/pkg/utils" ) -// GatherWALFilesToArchive reads from the archived status the list of WAL files -// that can be archived in parallel way. -// `requestedWALFile` is the name of the file whose archiving was requested by -// PostgreSQL, and that file is always the first of the list and is always included. -// `parallel` is the maximum number of WALs that we can archive in parallel -func (archiver *WALArchiver) GatherWALFilesToArchive( - ctx context.Context, - requestedWALFile string, - parallel int, -) (walList []string) { - contextLog := log.FromContext(ctx) - pgWalDirectory := path.Join(os.Getenv("PGDATA"), "pg_wal") - archiveStatusPath := path.Join(pgWalDirectory, "archive_status") - noMoreWALFilesNeeded := errors.New("no more files needed") - - // allocate parallel + 1 only if it does not overflow. Cap otherwise - var walListLength int - if parallel < math.MaxInt-1 { - walListLength = parallel + 1 - } else { - walListLength = math.MaxInt - 1 - } - // slightly more optimized, but equivalent to: - // walList = []string{requestedWALFile} - walList = make([]string, 1, walListLength) - walList[0] = requestedWALFile - - err := filepath.WalkDir(archiveStatusPath, func(path string, d os.DirEntry, err error) error { - // If err is set, it means the current path is a directory and the readdir raised an error - // The only available option here is to skip the path and log the error. - if err != nil { - contextLog.Error(err, "failed reading path", "path", path) - return filepath.SkipDir - } - - if len(walList) >= parallel { - return noMoreWALFilesNeeded - } - - // We don't process directories beside the archive status path - if d.IsDir() { - // We want to proceed exploring the archive status folder - if path == archiveStatusPath { - return nil - } - - return filepath.SkipDir - } - - // We only process ready files - if !strings.HasSuffix(path, ".ready") { - return nil - } - - walFileName := strings.TrimSuffix(filepath.Base(path), ".ready") - - // We are already archiving the requested WAL file, - // and we need to avoid archiving it twice. - // requestedWALFile is usually "pg_wal/wal_file_name" and - // we compare it with the path we read - if strings.HasSuffix(requestedWALFile, walFileName) { - return nil - } - - walList = append(walList, filepath.Join("pg_wal", walFileName)) - return nil - }) - - // In this point err must be nil or noMoreWALFilesNeeded, if it is something different - // there is a programming error - if err != nil && err != noMoreWALFilesNeeded { - contextLog.Error(err, "unexpected error while reading the list of WAL files to archive") - } - - return walList -} - // BarmanCloudWalArchiveOptions calculates the set of options to be // used with barman-cloud-wal-archive func (archiver *WALArchiver) BarmanCloudWalArchiveOptions( From d23d82fc84745e87ffa0968c9c12f5d430a3a592 Mon Sep 17 00:00:00 2001 From: Francesco Canovai Date: Tue, 22 Apr 2025 09:51:52 +0100 Subject: [PATCH 06/13] refactor: clarify logging for parallel WAL archiving (#113) Differentiate between the WAL archived and the ones pre-archived by the parallel workers. Signed-off-by: Francesco Canovai Signed-off-by: Armando Ruocco Co-authored-by: Armando Ruocco Signed-off-by: Fouad Semaan --- pkg/walarchive/cmd.go | 51 +++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/pkg/walarchive/cmd.go b/pkg/walarchive/cmd.go index f3be5f3e..da539323 100644 --- a/pkg/walarchive/cmd.go +++ b/pkg/walarchive/cmd.go @@ -109,34 +109,43 @@ func (archiver *BarmanArchiver) ArchiveList( for idx := range walNames { waitGroup.Add(1) go func(walIndex int) { - walStatus := &result[walIndex] - walStatus.WalName = walNames[walIndex] - walStatus.StartTime = time.Now() - walStatus.Err = archiver.Archive(ctx, walNames[walIndex], options) - walStatus.EndTime = time.Now() - if walStatus.Err == nil && walIndex != 0 { - walStatus.Err = archiver.Touch(walNames[walIndex]) + defer waitGroup.Done() + + result[walIndex] = WALArchiverResult{ + WalName: walNames[walIndex], + StartTime: time.Now(), + Err: archiver.Archive(ctx, walNames[walIndex], options), + EndTime: time.Now(), } + walStatus := &result[walIndex] + + walContextLog := contextLog.WithValues( + "walName", walStatus.WalName, + "startTime", walStatus.StartTime, + "endTime", walStatus.EndTime, + "elapsedWalTime", walStatus.EndTime.Sub(walStatus.StartTime), + ) - elapsedWalTime := walStatus.EndTime.Sub(walStatus.StartTime) if walStatus.Err != nil { - contextLog.Warning( + walContextLog.Warning( "Failed archiving WAL: PostgreSQL will retry", - "walName", walStatus.WalName, - "startTime", walStatus.StartTime, - "endTime", walStatus.EndTime, - "elapsedWalTime", elapsedWalTime, "error", walStatus.Err) - } else { - contextLog.Info( - "Archived WAL file", - "walName", walStatus.WalName, - "startTime", walStatus.StartTime, - "endTime", walStatus.EndTime, - "elapsedWalTime", elapsedWalTime) + return + } + + if walIndex == 0 { + walContextLog.Info("Archived WAL file") + return + } + + if err := archiver.Touch(walNames[walIndex]); err != nil { + walContextLog.Warning( + "WAL file pre-archived, but it could not be added to the spool. PostgreSQL will retry", + "error", err) + return } - waitGroup.Done() + walContextLog.Info("Pre-archived WAL file (parallel)") }(idx) } From eb4860bcb45bcb09eeb791c00dd9595630514c06 Mon Sep 17 00:00:00 2001 From: Fouad Semaan Date: Thu, 17 Apr 2025 15:57:53 -0400 Subject: [PATCH 07/13] Add env var option to use Azure Default Azure Credentials Signed-off-by: Fouad Semaan --- pkg/command/commandbuilder.go | 31 ++++++++++++++++++++-------- pkg/command/commandbuilder_test.go | 33 +++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 11 deletions(-) diff --git a/pkg/command/commandbuilder.go b/pkg/command/commandbuilder.go index 71e717ee..a68bf4c2 100644 --- a/pkg/command/commandbuilder.go +++ b/pkg/command/commandbuilder.go @@ -18,6 +18,8 @@ package command import ( "context" + "os" + "strconv" barmanApi "github.com/cloudnative-pg/barman-cloud/pkg/api" ) @@ -117,16 +119,29 @@ type contextKey string // contextKeyUseDefaultAzureCredentials contains a bool indicating if the default azure credentials should be used const contextKeyUseDefaultAzureCredentials contextKey = "useDefaultAzureCredentials" +// Env variable overrides any value set in ctx value contextKeyUseDefaultAzureCredentials +const barmanUseDefaultAzureCredentials string = "BARMAN_USE_DEFAULT_AZURE_CREDENTIALS" + func useDefaultAzureCredentials(ctx context.Context) bool { - v := ctx.Value(contextKeyUseDefaultAzureCredentials) - if v == nil { - return false - } - result, ok := v.(bool) - if !ok { - return false + val := os.Getenv(barmanUseDefaultAzureCredentials) + if len(val) == 0 { + v := ctx.Value(contextKeyUseDefaultAzureCredentials) + if v == nil { + return false + } + result, ok := v.(bool) + if !ok { + return false + } + return result + } else { + v, err := strconv.ParseBool(val) + if err != nil { + return false + } + return v } - return result + } // ContextWithDefaultAzureCredentials create a context that contains the contextKeyUseDefaultAzureCredentials flag. diff --git a/pkg/command/commandbuilder_test.go b/pkg/command/commandbuilder_test.go index 9f7e16e4..38b4f8c6 100644 --- a/pkg/command/commandbuilder_test.go +++ b/pkg/command/commandbuilder_test.go @@ -18,6 +18,7 @@ package command import ( "context" + "os" "strings" barmanApi "github.com/cloudnative-pg/barman-cloud/pkg/api" @@ -64,17 +65,43 @@ var _ = Describe("useDefaultAzureCredentials", func() { Expect(useDefaultAzureCredentials(ctx)).To(BeFalse()) }) - It("should be false if ctx contains an invalid value", func(ctx SpecContext) { + It("should be false if ctx contains an invalid value and not overwritten by env", func(ctx SpecContext) { newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, "invalidValue") Expect(useDefaultAzureCredentials(newCtx)).To(BeFalse()) }) - It("should be false if ctx contains false value", func(ctx SpecContext) { + It("should be false if ctx contains false value and not overwritten by env", func(ctx SpecContext) { newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, false) Expect(useDefaultAzureCredentials(newCtx)).To(BeFalse()) }) - It("should be true only if ctx contains true value", func(ctx SpecContext) { + It("should be true only if ctx contains true value and not overwritten by env", func(ctx SpecContext) { + newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, true) + Expect(useDefaultAzureCredentials(newCtx)).To(BeTrue()) + }) + + // Env var should override the ctx value + + It("should be true if env var set to true even if ctx contains false value", func(ctx SpecContext) { + os.Setenv(barmanUseDefaultAzureCredentials, "true") + newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, false) + Expect(useDefaultAzureCredentials(newCtx)).To(BeTrue()) + }) + + It("should be false if env var set to false even if ctx contains true value", func(ctx SpecContext) { + os.Setenv(barmanUseDefaultAzureCredentials, "false") + newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, true) + Expect(useDefaultAzureCredentials(newCtx)).To(BeFalse()) + }) + + It("should be false if env var is empty if ctx contains false value", func(ctx SpecContext) { + os.Setenv(barmanUseDefaultAzureCredentials, "") + newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, false) + Expect(useDefaultAzureCredentials(newCtx)).To(BeFalse()) + }) + + It("should be true if env var is empty if ctx contains true value", func(ctx SpecContext) { + os.Setenv(barmanUseDefaultAzureCredentials, "") newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, true) Expect(useDefaultAzureCredentials(newCtx)).To(BeTrue()) }) From 64daca9d3789e8d6293bc51a967467fe4b8068c6 Mon Sep 17 00:00:00 2001 From: Fouad Semaan Date: Tue, 22 Apr 2025 14:14:29 -0400 Subject: [PATCH 08/13] Add invalid value use case for env var Signed-off-by: Fouad Semaan --- pkg/command/commandbuilder_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/command/commandbuilder_test.go b/pkg/command/commandbuilder_test.go index 38b4f8c6..a2009325 100644 --- a/pkg/command/commandbuilder_test.go +++ b/pkg/command/commandbuilder_test.go @@ -105,4 +105,10 @@ var _ = Describe("useDefaultAzureCredentials", func() { newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, true) Expect(useDefaultAzureCredentials(newCtx)).To(BeTrue()) }) + + It("should be false if env var set with invalid value", func(ctx SpecContext) { + os.Setenv(barmanUseDefaultAzureCredentials, "invalidValue") + newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, true) + Expect(useDefaultAzureCredentials(newCtx)).To(BeFalse()) + }) }) From 90dcc6597db633b55deaf43de9cf873ae7e12201 Mon Sep 17 00:00:00 2001 From: Fouad Semaan Date: Thu, 17 Apr 2025 15:57:53 -0400 Subject: [PATCH 09/13] Add env var option to use Azure Default Azure Credentials Signed-off-by: Fouad Semaan --- pkg/command/commandbuilder_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pkg/command/commandbuilder_test.go b/pkg/command/commandbuilder_test.go index a2009325..47022e6c 100644 --- a/pkg/command/commandbuilder_test.go +++ b/pkg/command/commandbuilder_test.go @@ -106,6 +106,32 @@ var _ = Describe("useDefaultAzureCredentials", func() { Expect(useDefaultAzureCredentials(newCtx)).To(BeTrue()) }) + // Env var should override the ctx value + + It("should be true if env var set to true even if ctx contains false value", func(ctx SpecContext) { + os.Setenv(barmanUseDefaultAzureCredentials, "true") + newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, false) + Expect(useDefaultAzureCredentials(newCtx)).To(BeTrue()) + }) + + It("should be false if env var set to false even if ctx contains true value", func(ctx SpecContext) { + os.Setenv(barmanUseDefaultAzureCredentials, "false") + newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, true) + Expect(useDefaultAzureCredentials(newCtx)).To(BeFalse()) + }) + + It("should be false if env var is empty if ctx contains false value", func(ctx SpecContext) { + os.Setenv(barmanUseDefaultAzureCredentials, "") + newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, false) + Expect(useDefaultAzureCredentials(newCtx)).To(BeFalse()) + }) + + It("should be true if env var is empty if ctx contains true value", func(ctx SpecContext) { + os.Setenv(barmanUseDefaultAzureCredentials, "") + newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, true) + Expect(useDefaultAzureCredentials(newCtx)).To(BeTrue()) + }) + It("should be false if env var set with invalid value", func(ctx SpecContext) { os.Setenv(barmanUseDefaultAzureCredentials, "invalidValue") newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, true) From 1f3601b8a63ce3d5bcfeabd199756e37f48d91f7 Mon Sep 17 00:00:00 2001 From: Fouad Semaan Date: Thu, 17 Apr 2025 15:57:53 -0400 Subject: [PATCH 10/13] Add env var option to use Azure Default Azure Credentials Signed-off-by: Fouad Semaan --- pkg/command/commandbuilder.go | 31 ++++++++++++++++++++-------- pkg/command/commandbuilder_test.go | 33 +++++++++++++++++++++++++++--- 2 files changed, 53 insertions(+), 11 deletions(-) diff --git a/pkg/command/commandbuilder.go b/pkg/command/commandbuilder.go index 71e717ee..a68bf4c2 100644 --- a/pkg/command/commandbuilder.go +++ b/pkg/command/commandbuilder.go @@ -18,6 +18,8 @@ package command import ( "context" + "os" + "strconv" barmanApi "github.com/cloudnative-pg/barman-cloud/pkg/api" ) @@ -117,16 +119,29 @@ type contextKey string // contextKeyUseDefaultAzureCredentials contains a bool indicating if the default azure credentials should be used const contextKeyUseDefaultAzureCredentials contextKey = "useDefaultAzureCredentials" +// Env variable overrides any value set in ctx value contextKeyUseDefaultAzureCredentials +const barmanUseDefaultAzureCredentials string = "BARMAN_USE_DEFAULT_AZURE_CREDENTIALS" + func useDefaultAzureCredentials(ctx context.Context) bool { - v := ctx.Value(contextKeyUseDefaultAzureCredentials) - if v == nil { - return false - } - result, ok := v.(bool) - if !ok { - return false + val := os.Getenv(barmanUseDefaultAzureCredentials) + if len(val) == 0 { + v := ctx.Value(contextKeyUseDefaultAzureCredentials) + if v == nil { + return false + } + result, ok := v.(bool) + if !ok { + return false + } + return result + } else { + v, err := strconv.ParseBool(val) + if err != nil { + return false + } + return v } - return result + } // ContextWithDefaultAzureCredentials create a context that contains the contextKeyUseDefaultAzureCredentials flag. diff --git a/pkg/command/commandbuilder_test.go b/pkg/command/commandbuilder_test.go index 9f7e16e4..38b4f8c6 100644 --- a/pkg/command/commandbuilder_test.go +++ b/pkg/command/commandbuilder_test.go @@ -18,6 +18,7 @@ package command import ( "context" + "os" "strings" barmanApi "github.com/cloudnative-pg/barman-cloud/pkg/api" @@ -64,17 +65,43 @@ var _ = Describe("useDefaultAzureCredentials", func() { Expect(useDefaultAzureCredentials(ctx)).To(BeFalse()) }) - It("should be false if ctx contains an invalid value", func(ctx SpecContext) { + It("should be false if ctx contains an invalid value and not overwritten by env", func(ctx SpecContext) { newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, "invalidValue") Expect(useDefaultAzureCredentials(newCtx)).To(BeFalse()) }) - It("should be false if ctx contains false value", func(ctx SpecContext) { + It("should be false if ctx contains false value and not overwritten by env", func(ctx SpecContext) { newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, false) Expect(useDefaultAzureCredentials(newCtx)).To(BeFalse()) }) - It("should be true only if ctx contains true value", func(ctx SpecContext) { + It("should be true only if ctx contains true value and not overwritten by env", func(ctx SpecContext) { + newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, true) + Expect(useDefaultAzureCredentials(newCtx)).To(BeTrue()) + }) + + // Env var should override the ctx value + + It("should be true if env var set to true even if ctx contains false value", func(ctx SpecContext) { + os.Setenv(barmanUseDefaultAzureCredentials, "true") + newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, false) + Expect(useDefaultAzureCredentials(newCtx)).To(BeTrue()) + }) + + It("should be false if env var set to false even if ctx contains true value", func(ctx SpecContext) { + os.Setenv(barmanUseDefaultAzureCredentials, "false") + newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, true) + Expect(useDefaultAzureCredentials(newCtx)).To(BeFalse()) + }) + + It("should be false if env var is empty if ctx contains false value", func(ctx SpecContext) { + os.Setenv(barmanUseDefaultAzureCredentials, "") + newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, false) + Expect(useDefaultAzureCredentials(newCtx)).To(BeFalse()) + }) + + It("should be true if env var is empty if ctx contains true value", func(ctx SpecContext) { + os.Setenv(barmanUseDefaultAzureCredentials, "") newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, true) Expect(useDefaultAzureCredentials(newCtx)).To(BeTrue()) }) From c4254906d20a8476240d84de0cad96bf19d4262a Mon Sep 17 00:00:00 2001 From: Fouad Semaan Date: Tue, 22 Apr 2025 14:14:29 -0400 Subject: [PATCH 11/13] Add invalid value use case for env var Signed-off-by: Fouad Semaan --- pkg/command/commandbuilder_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pkg/command/commandbuilder_test.go b/pkg/command/commandbuilder_test.go index 38b4f8c6..a2009325 100644 --- a/pkg/command/commandbuilder_test.go +++ b/pkg/command/commandbuilder_test.go @@ -105,4 +105,10 @@ var _ = Describe("useDefaultAzureCredentials", func() { newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, true) Expect(useDefaultAzureCredentials(newCtx)).To(BeTrue()) }) + + It("should be false if env var set with invalid value", func(ctx SpecContext) { + os.Setenv(barmanUseDefaultAzureCredentials, "invalidValue") + newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, true) + Expect(useDefaultAzureCredentials(newCtx)).To(BeFalse()) + }) }) From ae72a054d589ad91369f617652b42f243eb699e9 Mon Sep 17 00:00:00 2001 From: Fouad Semaan Date: Thu, 17 Apr 2025 15:57:53 -0400 Subject: [PATCH 12/13] Add env var option to use Azure Default Azure Credentials Signed-off-by: Fouad Semaan --- pkg/command/commandbuilder_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pkg/command/commandbuilder_test.go b/pkg/command/commandbuilder_test.go index a2009325..47022e6c 100644 --- a/pkg/command/commandbuilder_test.go +++ b/pkg/command/commandbuilder_test.go @@ -106,6 +106,32 @@ var _ = Describe("useDefaultAzureCredentials", func() { Expect(useDefaultAzureCredentials(newCtx)).To(BeTrue()) }) + // Env var should override the ctx value + + It("should be true if env var set to true even if ctx contains false value", func(ctx SpecContext) { + os.Setenv(barmanUseDefaultAzureCredentials, "true") + newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, false) + Expect(useDefaultAzureCredentials(newCtx)).To(BeTrue()) + }) + + It("should be false if env var set to false even if ctx contains true value", func(ctx SpecContext) { + os.Setenv(barmanUseDefaultAzureCredentials, "false") + newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, true) + Expect(useDefaultAzureCredentials(newCtx)).To(BeFalse()) + }) + + It("should be false if env var is empty if ctx contains false value", func(ctx SpecContext) { + os.Setenv(barmanUseDefaultAzureCredentials, "") + newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, false) + Expect(useDefaultAzureCredentials(newCtx)).To(BeFalse()) + }) + + It("should be true if env var is empty if ctx contains true value", func(ctx SpecContext) { + os.Setenv(barmanUseDefaultAzureCredentials, "") + newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, true) + Expect(useDefaultAzureCredentials(newCtx)).To(BeTrue()) + }) + It("should be false if env var set with invalid value", func(ctx SpecContext) { os.Setenv(barmanUseDefaultAzureCredentials, "invalidValue") newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, true) From 6fafd999a1547567263a550e0df430b5f09f1b1c Mon Sep 17 00:00:00 2001 From: Fouad Semaan Date: Tue, 22 Apr 2025 14:29:24 -0400 Subject: [PATCH 13/13] Add invalid value use case for env var Signed-off-by: Fouad Semaan --- pkg/command/commandbuilder_test.go | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/pkg/command/commandbuilder_test.go b/pkg/command/commandbuilder_test.go index 47022e6c..a2009325 100644 --- a/pkg/command/commandbuilder_test.go +++ b/pkg/command/commandbuilder_test.go @@ -106,32 +106,6 @@ var _ = Describe("useDefaultAzureCredentials", func() { Expect(useDefaultAzureCredentials(newCtx)).To(BeTrue()) }) - // Env var should override the ctx value - - It("should be true if env var set to true even if ctx contains false value", func(ctx SpecContext) { - os.Setenv(barmanUseDefaultAzureCredentials, "true") - newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, false) - Expect(useDefaultAzureCredentials(newCtx)).To(BeTrue()) - }) - - It("should be false if env var set to false even if ctx contains true value", func(ctx SpecContext) { - os.Setenv(barmanUseDefaultAzureCredentials, "false") - newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, true) - Expect(useDefaultAzureCredentials(newCtx)).To(BeFalse()) - }) - - It("should be false if env var is empty if ctx contains false value", func(ctx SpecContext) { - os.Setenv(barmanUseDefaultAzureCredentials, "") - newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, false) - Expect(useDefaultAzureCredentials(newCtx)).To(BeFalse()) - }) - - It("should be true if env var is empty if ctx contains true value", func(ctx SpecContext) { - os.Setenv(barmanUseDefaultAzureCredentials, "") - newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, true) - Expect(useDefaultAzureCredentials(newCtx)).To(BeTrue()) - }) - It("should be false if env var set with invalid value", func(ctx SpecContext) { os.Setenv(barmanUseDefaultAzureCredentials, "invalidValue") newCtx := context.WithValue(ctx, contextKeyUseDefaultAzureCredentials, true)