mirror of
https://github.com/cloudnative-pg/plugin-barman-cloud.git
synced 2026-09-04 22:22:21 +02:00
Compare commits
5 Commits
b23e1c2cba
...
9ec4c7b912
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9ec4c7b912 | ||
|
|
31b25538bf | ||
|
|
1bb6bab640 | ||
|
|
6a55a361a3 | ||
|
|
62b579101f |
@ -63,6 +63,9 @@ RUN python3 -m venv /venv && \
|
|||||||
# already present in the distroless base image.
|
# already present in the distroless base image.
|
||||||
# Distroless package list from: https://github.com/GoogleContainerTools/distroless/blob/main/base/config.bzl
|
# Distroless package list from: https://github.com/GoogleContainerTools/distroless/blob/main/base/config.bzl
|
||||||
# and https://github.com/GoogleContainerTools/distroless/blob/main/python3/config.bzl
|
# and https://github.com/GoogleContainerTools/distroless/blob/main/python3/config.bzl
|
||||||
|
# libselinux1/libpcre2-8-0 are pulled in transitively by python3.13-venv's apt metadata,
|
||||||
|
# but the actual distroless base does not ship them, so they are excluded from the
|
||||||
|
# "already present" set below to force them to be bundled (tar needs them at runtime).
|
||||||
RUN mkdir -p /dependencies /build/downloads && \
|
RUN mkdir -p /dependencies /build/downloads && \
|
||||||
cd /build/downloads && \
|
cd /build/downloads && \
|
||||||
DISTROLESS_PACKAGES="libc6 libssl3t64 libzstd1 zlib1g libgcc-s1 libstdc++6 \
|
DISTROLESS_PACKAGES="libc6 libssl3t64 libzstd1 zlib1g libgcc-s1 libstdc++6 \
|
||||||
@ -73,10 +76,11 @@ RUN mkdir -p /dependencies /build/downloads && \
|
|||||||
libpython3.13-stdlib python3.13-minimal python3.13-venv" && \
|
libpython3.13-stdlib python3.13-minimal python3.13-venv" && \
|
||||||
apt-cache depends --recurse --no-recommends --no-suggests \
|
apt-cache depends --recurse --no-recommends --no-suggests \
|
||||||
--no-conflicts --no-breaks --no-replaces --no-enhances \
|
--no-conflicts --no-breaks --no-replaces --no-enhances \
|
||||||
$DISTROLESS_PACKAGES 2>/dev/null | grep "^\w" | sort -u > /tmp/distroless.txt && \
|
$DISTROLESS_PACKAGES 2>/dev/null | grep "^\w" | sort -u | \
|
||||||
|
grep -v -x -E 'libselinux1|libpcre2-8-0' > /tmp/distroless.txt && \
|
||||||
apt-cache depends --recurse --no-recommends --no-suggests \
|
apt-cache depends --recurse --no-recommends --no-suggests \
|
||||||
--no-conflicts --no-breaks --no-replaces --no-enhances \
|
--no-conflicts --no-breaks --no-replaces --no-enhances \
|
||||||
libpq5 liblz4-1 libsnappy1v5 2>/dev/null | grep "^\w" | sort -u | \
|
libpq5 liblz4-1 libsnappy1v5 tar 2>/dev/null | grep "^\w" | sort -u | \
|
||||||
grep -v -F -x -f /tmp/distroless.txt > /tmp/packages.txt && \
|
grep -v -F -x -f /tmp/distroless.txt > /tmp/packages.txt && \
|
||||||
apt-get download $(cat /tmp/packages.txt) && \
|
apt-get download $(cat /tmp/packages.txt) && \
|
||||||
for deb in *.deb; do \
|
for deb in *.deb; do \
|
||||||
@ -102,6 +106,7 @@ LABEL summary="$SUMMARY" \
|
|||||||
|
|
||||||
COPY --from=pythonbuilder /venv /venv
|
COPY --from=pythonbuilder /venv /venv
|
||||||
COPY --from=pythonbuilder /dependencies/usr/lib /usr/lib
|
COPY --from=pythonbuilder /dependencies/usr/lib /usr/lib
|
||||||
|
COPY --from=pythonbuilder /dependencies/usr/bin/tar /usr/bin/tar
|
||||||
COPY --from=gobuilder /workspace/manager /manager
|
COPY --from=gobuilder /workspace/manager /manager
|
||||||
|
|
||||||
# Compile all Python bytecode as root to avoid runtime compilation
|
# Compile all Python bytecode as root to avoid runtime compilation
|
||||||
|
|||||||
@ -1,2 +1,2 @@
|
|||||||
barman[azure,cloud,google,snappy,zstandard,lz4]==3.19.1
|
barman[azure,cloud,google,snappy,zstandard,lz4]==3.20.0
|
||||||
zipp>=3.19.1 # not directly required, pinned by Snyk to avoid a vulnerability
|
zipp>=3.19.1 # not directly required, pinned by Snyk to avoid a vulnerability
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
# This file is autogenerated by pip-compile with Python 3.13
|
# This file is autogenerated by pip-compile with Python 3.13
|
||||||
# by the following command:
|
# by the following command:
|
||||||
#
|
#
|
||||||
# pip-compile --allow-unsafe --generate-hashes --no-index --output-file=sidecar-requirements.txt --strip-extras sidecar-requirements.in
|
# pip-compile --allow-unsafe --generate-hashes --output-file=sidecar-requirements.txt --strip-extras sidecar-requirements.in
|
||||||
#
|
#
|
||||||
azure-core==1.41.0 \
|
azure-core==1.41.0 \
|
||||||
--hash=sha256:522b4011e8180b1a3dcd2024396a4e7fe9ac37fb8597db47163d230b5efe892d \
|
--hash=sha256:522b4011e8180b1a3dcd2024396a4e7fe9ac37fb8597db47163d230b5efe892d \
|
||||||
@ -18,9 +18,9 @@ azure-storage-blob==12.30.0 \
|
|||||||
--hash=sha256:2cd74d4d5731e5eb6b8d5c5056ee115a5e88f8fdf22517b739836fda685018be \
|
--hash=sha256:2cd74d4d5731e5eb6b8d5c5056ee115a5e88f8fdf22517b739836fda685018be \
|
||||||
--hash=sha256:d415ac50b67a8da6b3ae7e9f1014b1b55cd7aafa0b8d4ca9b380568dc7360423
|
--hash=sha256:d415ac50b67a8da6b3ae7e9f1014b1b55cd7aafa0b8d4ca9b380568dc7360423
|
||||||
# via barman
|
# via barman
|
||||||
barman==3.19.1 \
|
barman==3.20.0 \
|
||||||
--hash=sha256:0a6a9e1babf97687732d8b2a3eb79ea95d55246a5257b9433865cb6e755221c0 \
|
--hash=sha256:02dd8936e62c1829c78597eefedfcab0aa820f5618da2871f38b5bc684891a54 \
|
||||||
--hash=sha256:2f71c4a1f1ba53f694cbdf838bb9906d8ba02b97d1fd3041196e8999bec7a1ee
|
--hash=sha256:1aa92df452f39c357d6547fd0abd3885a8c243ea95002e6fc0b7f66f8e8c24d5
|
||||||
# via -r sidecar-requirements.in
|
# via -r sidecar-requirements.in
|
||||||
boto3==1.43.81 \
|
boto3==1.43.81 \
|
||||||
--hash=sha256:62ecf695088e06f37500d6cc49a240dc1331379bd5ae992d185fef212038ca29 \
|
--hash=sha256:62ecf695088e06f37500d6cc49a240dc1331379bd5ae992d185fef212038ca29 \
|
||||||
|
|||||||
8
go.mod
8
go.mod
@ -5,13 +5,13 @@ go 1.26.4
|
|||||||
require (
|
require (
|
||||||
github.com/cert-manager/cert-manager v1.21.1
|
github.com/cert-manager/cert-manager v1.21.1
|
||||||
github.com/cloudnative-pg/api v1.30.0
|
github.com/cloudnative-pg/api v1.30.0
|
||||||
github.com/cloudnative-pg/barman-cloud v0.5.2-0.20260806065336-5aa56cd49543
|
github.com/cloudnative-pg/barman-cloud v0.6.0
|
||||||
github.com/cloudnative-pg/cloudnative-pg v1.30.0
|
github.com/cloudnative-pg/cloudnative-pg v1.30.0
|
||||||
github.com/cloudnative-pg/cnpg-i v0.6.0
|
github.com/cloudnative-pg/cnpg-i v0.6.0
|
||||||
github.com/cloudnative-pg/cnpg-i-machinery v0.4.2
|
github.com/cloudnative-pg/cnpg-i-machinery v0.4.2
|
||||||
github.com/cloudnative-pg/machinery v0.5.0
|
github.com/cloudnative-pg/machinery v0.6.0
|
||||||
github.com/onsi/ginkgo/v2 v2.32.1
|
github.com/onsi/ginkgo/v2 v2.32.1
|
||||||
github.com/onsi/gomega v1.42.1
|
github.com/onsi/gomega v1.43.0
|
||||||
github.com/spf13/cobra v1.10.2
|
github.com/spf13/cobra v1.10.2
|
||||||
github.com/spf13/viper v1.21.0
|
github.com/spf13/viper v1.21.0
|
||||||
google.golang.org/grpc v1.83.2
|
google.golang.org/grpc v1.83.2
|
||||||
@ -42,7 +42,7 @@ require (
|
|||||||
github.com/fsnotify/fsnotify v1.9.0 // indirect
|
github.com/fsnotify/fsnotify v1.9.0 // indirect
|
||||||
github.com/fxamacker/cbor/v2 v2.9.2 // indirect
|
github.com/fxamacker/cbor/v2 v2.9.2 // indirect
|
||||||
github.com/go-errors/errors v1.5.1 // indirect
|
github.com/go-errors/errors v1.5.1 // indirect
|
||||||
github.com/go-logr/logr v1.4.3 // indirect
|
github.com/go-logr/logr v1.4.4 // indirect
|
||||||
github.com/go-logr/stdr v1.2.2 // indirect
|
github.com/go-logr/stdr v1.2.2 // indirect
|
||||||
github.com/go-logr/zapr v1.3.0 // indirect
|
github.com/go-logr/zapr v1.3.0 // indirect
|
||||||
github.com/go-openapi/jsonpointer v1.0.0 // indirect
|
github.com/go-openapi/jsonpointer v1.0.0 // indirect
|
||||||
|
|||||||
16
go.sum
16
go.sum
@ -20,16 +20,16 @@ github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UF
|
|||||||
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
github.com/cloudnative-pg/api v1.30.0 h1:L8hnvV/tPEQA1xYEi41FUBFA7FUNVGju8+SlgFlDDjI=
|
github.com/cloudnative-pg/api v1.30.0 h1:L8hnvV/tPEQA1xYEi41FUBFA7FUNVGju8+SlgFlDDjI=
|
||||||
github.com/cloudnative-pg/api v1.30.0/go.mod h1:XrKBbOWObL33si0FNuwX4uHNf5JShiZyOUqd6LxbJQo=
|
github.com/cloudnative-pg/api v1.30.0/go.mod h1:XrKBbOWObL33si0FNuwX4uHNf5JShiZyOUqd6LxbJQo=
|
||||||
github.com/cloudnative-pg/barman-cloud v0.5.2-0.20260806065336-5aa56cd49543 h1:QNddaYyvyw14Ky/oxeI3cBiMMg7h6J0LI8VLCaxTUCY=
|
github.com/cloudnative-pg/barman-cloud v0.6.0 h1:OtBFmCDyVUAcgFa++FIoCCJwPfd5TtqK3PH6DGPcpkA=
|
||||||
github.com/cloudnative-pg/barman-cloud v0.5.2-0.20260806065336-5aa56cd49543/go.mod h1:ZQLkdpk44FW5/BGWzABTOEcV9qPbwC+rbdscg2I8mBI=
|
github.com/cloudnative-pg/barman-cloud v0.6.0/go.mod h1:eqSPRGz/s8M0Mea8mkqiVQUTkoSquAhvJF49feh+Ks4=
|
||||||
github.com/cloudnative-pg/cloudnative-pg v1.30.0 h1:fnhVq44xXx97MNiuvJsPrX1vSjYbgdyBK5MSGfdHdp0=
|
github.com/cloudnative-pg/cloudnative-pg v1.30.0 h1:fnhVq44xXx97MNiuvJsPrX1vSjYbgdyBK5MSGfdHdp0=
|
||||||
github.com/cloudnative-pg/cloudnative-pg v1.30.0/go.mod h1:QkolwBOWZ+GvAiJt6KpDSymwkpf0K19/p4Q6MQlTM8U=
|
github.com/cloudnative-pg/cloudnative-pg v1.30.0/go.mod h1:QkolwBOWZ+GvAiJt6KpDSymwkpf0K19/p4Q6MQlTM8U=
|
||||||
github.com/cloudnative-pg/cnpg-i v0.6.0 h1:LA//DLkFOLIjU0ASOpFkydZhGir9IAIDfgSsTTX9IpU=
|
github.com/cloudnative-pg/cnpg-i v0.6.0 h1:LA//DLkFOLIjU0ASOpFkydZhGir9IAIDfgSsTTX9IpU=
|
||||||
github.com/cloudnative-pg/cnpg-i v0.6.0/go.mod h1:4kcpLAj+feMTnh0TVadXRASdVnEhBytNSm/BvktLgmI=
|
github.com/cloudnative-pg/cnpg-i v0.6.0/go.mod h1:4kcpLAj+feMTnh0TVadXRASdVnEhBytNSm/BvktLgmI=
|
||||||
github.com/cloudnative-pg/cnpg-i-machinery v0.4.2 h1:0reS9MtyLYINHXQ/MfxJ9jp39hhBf8e3Qdj+T5Nsq6I=
|
github.com/cloudnative-pg/cnpg-i-machinery v0.4.2 h1:0reS9MtyLYINHXQ/MfxJ9jp39hhBf8e3Qdj+T5Nsq6I=
|
||||||
github.com/cloudnative-pg/cnpg-i-machinery v0.4.2/go.mod h1:gvrKabgxXq0zGthXGucemDdsxakLEQDMxn43M4HLW30=
|
github.com/cloudnative-pg/cnpg-i-machinery v0.4.2/go.mod h1:gvrKabgxXq0zGthXGucemDdsxakLEQDMxn43M4HLW30=
|
||||||
github.com/cloudnative-pg/machinery v0.5.0 h1:hhTnkzn+AiN3NmbjCQ6RXj5rfqV3K6arzq6kdXAzcnQ=
|
github.com/cloudnative-pg/machinery v0.6.0 h1:faHxS1AK75XkzppOcAKdOexKmzX7iGK6jX2b9itssb4=
|
||||||
github.com/cloudnative-pg/machinery v0.5.0/go.mod h1:uuFjqBUjWn0a9uvAk1ixTSzPM0PrjaS+QiKLOIBqLm4=
|
github.com/cloudnative-pg/machinery v0.6.0/go.mod h1:wyw9E/0uYGAixp9+0PLsJ6qHiEiFKDkeXb9O2dRi2w0=
|
||||||
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
@ -60,8 +60,8 @@ github.com/go-errors/errors v1.5.1/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3Bop
|
|||||||
github.com/go-faker/faker/v4 v4.4.1 h1:LY1jDgjVkBZWIhATCt+gkl0x9i/7wC61gZx73GTFb+Q=
|
github.com/go-faker/faker/v4 v4.4.1 h1:LY1jDgjVkBZWIhATCt+gkl0x9i/7wC61gZx73GTFb+Q=
|
||||||
github.com/go-faker/faker/v4 v4.4.1/go.mod h1:HRLrjis+tYsbFtIHufEPTAIzcZiRu0rS9EYl2Ccwme4=
|
github.com/go-faker/faker/v4 v4.4.1/go.mod h1:HRLrjis+tYsbFtIHufEPTAIzcZiRu0rS9EYl2Ccwme4=
|
||||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||||
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
|
github.com/go-logr/logr v1.4.4 h1:tG4xh9yMsRCAiodLVTxyrkzSZ9+o0L1Kg/+cPVcbP/8=
|
||||||
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
github.com/go-logr/logr v1.4.4/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||||
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
|
||||||
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
|
||||||
github.com/go-logr/zapr v1.3.0 h1:XGdV8XW8zdwFiwOA2Dryh1gj2KRQyOOoNmBy4EplIcQ=
|
github.com/go-logr/zapr v1.3.0 h1:XGdV8XW8zdwFiwOA2Dryh1gj2KRQyOOoNmBy4EplIcQ=
|
||||||
@ -163,8 +163,8 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq
|
|||||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
|
||||||
github.com/onsi/ginkgo/v2 v2.32.1 h1:6tlvcDm/3sE8lGJbZ4+d4mO3RLy24/tQWOFzVSQNIfw=
|
github.com/onsi/ginkgo/v2 v2.32.1 h1:6tlvcDm/3sE8lGJbZ4+d4mO3RLy24/tQWOFzVSQNIfw=
|
||||||
github.com/onsi/ginkgo/v2 v2.32.1/go.mod h1:+aXOY+vzZ5mu2iI2HpTZUPmM//oQfsNFX6gU9kNcA44=
|
github.com/onsi/ginkgo/v2 v2.32.1/go.mod h1:+aXOY+vzZ5mu2iI2HpTZUPmM//oQfsNFX6gU9kNcA44=
|
||||||
github.com/onsi/gomega v1.42.1 h1:iN1rCUX+44NZ1Dc97MPoeFYbFR0vh8zxoxMFwKdyZ6I=
|
github.com/onsi/gomega v1.43.0 h1:VlG/1FxqNxhSO+lq/OHBNaaqwiBK/mO8JbVkX9Y+FeU=
|
||||||
github.com/onsi/gomega v1.42.1/go.mod h1:REff/hsDsodHoKlWsP2mAPhu1+5/6hVYNf9rIEBpeSg=
|
github.com/onsi/gomega v1.43.0/go.mod h1:REff/hsDsodHoKlWsP2mAPhu1+5/6hVYNf9rIEBpeSg=
|
||||||
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
|
github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
|
||||||
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
|
github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
|
||||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
|
|||||||
@ -36,6 +36,9 @@ import (
|
|||||||
// DefaultTTLSeconds is the default TTL in seconds of cache entries
|
// DefaultTTLSeconds is the default TTL in seconds of cache entries
|
||||||
const DefaultTTLSeconds = 10
|
const DefaultTTLSeconds = 10
|
||||||
|
|
||||||
|
// DefaultCleanupIntervalSeconds is the default interval in seconds for cache cleanup
|
||||||
|
const DefaultCleanupIntervalSeconds = 30
|
||||||
|
|
||||||
type cachedEntry struct {
|
type cachedEntry struct {
|
||||||
entry client.Object
|
entry client.Object
|
||||||
fetchUnixTime int64
|
fetchUnixTime int64
|
||||||
@ -49,18 +52,30 @@ func (e *cachedEntry) isExpired() bool {
|
|||||||
// ExtendedClient is an extended client that is capable of caching multiple secrets without relying on informers
|
// ExtendedClient is an extended client that is capable of caching multiple secrets without relying on informers
|
||||||
type ExtendedClient struct {
|
type ExtendedClient struct {
|
||||||
client.Client
|
client.Client
|
||||||
cachedObjects []cachedEntry
|
cachedObjects []cachedEntry
|
||||||
mux *sync.Mutex
|
mux *sync.Mutex
|
||||||
|
cleanupInterval time.Duration
|
||||||
|
cleanupDone chan struct{} // Signals when cleanup routine exits
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewExtendedClient returns an extended client capable of caching secrets on the 'Get' operation
|
// NewExtendedClient returns an extended client capable of caching secrets on the 'Get' operation.
|
||||||
|
// It starts a background goroutine that periodically cleans up expired cache entries.
|
||||||
|
// The cleanup routine will stop when the provided context is cancelled.
|
||||||
func NewExtendedClient(
|
func NewExtendedClient(
|
||||||
|
ctx context.Context,
|
||||||
baseClient client.Client,
|
baseClient client.Client,
|
||||||
) client.Client {
|
) client.Client {
|
||||||
return &ExtendedClient{
|
ec := &ExtendedClient{
|
||||||
Client: baseClient,
|
Client: baseClient,
|
||||||
mux: &sync.Mutex{},
|
mux: &sync.Mutex{},
|
||||||
|
cleanupInterval: DefaultCleanupIntervalSeconds * time.Second,
|
||||||
|
cleanupDone: make(chan struct{}),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Start the background cleanup routine
|
||||||
|
go ec.startCleanupRoutine(ctx)
|
||||||
|
|
||||||
|
return ec
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *ExtendedClient) isObjectCached(obj client.Object) bool {
|
func (e *ExtendedClient) isObjectCached(obj client.Object) bool {
|
||||||
@ -208,3 +223,55 @@ func (e *ExtendedClient) Patch(
|
|||||||
|
|
||||||
return e.Client.Patch(ctx, obj, patch, opts...)
|
return e.Client.Patch(ctx, obj, patch, opts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// startCleanupRoutine periodically removes expired entries from the cache.
|
||||||
|
// It runs until the context is cancelled.
|
||||||
|
func (e *ExtendedClient) startCleanupRoutine(ctx context.Context) {
|
||||||
|
defer close(e.cleanupDone)
|
||||||
|
contextLogger := log.FromContext(ctx).WithName("extended_client_cleanup")
|
||||||
|
ticker := time.NewTicker(e.cleanupInterval)
|
||||||
|
defer ticker.Stop()
|
||||||
|
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
contextLogger.Debug("stopping cache cleanup routine")
|
||||||
|
return
|
||||||
|
case <-ticker.C:
|
||||||
|
// Check context before cleanup to avoid unnecessary work during shutdown
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
e.cleanupExpiredEntries(ctx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// cleanupExpiredEntries removes all expired entries from the cache.
|
||||||
|
func (e *ExtendedClient) cleanupExpiredEntries(ctx context.Context) {
|
||||||
|
contextLogger := log.FromContext(ctx).WithName("extended_client_cleanup")
|
||||||
|
|
||||||
|
e.mux.Lock()
|
||||||
|
defer e.mux.Unlock()
|
||||||
|
|
||||||
|
initialCount := len(e.cachedObjects)
|
||||||
|
if initialCount == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new slice with only non-expired entries
|
||||||
|
validEntries := make([]cachedEntry, 0, initialCount)
|
||||||
|
for _, entry := range e.cachedObjects {
|
||||||
|
if !entry.isExpired() {
|
||||||
|
validEntries = append(validEntries, entry)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
removedCount := initialCount - len(validEntries)
|
||||||
|
if removedCount > 0 {
|
||||||
|
e.cachedObjects = validEntries
|
||||||
|
contextLogger.Debug("cleaned up expired cache entries",
|
||||||
|
"removedCount", removedCount,
|
||||||
|
"remainingCount", len(validEntries))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -20,6 +20,7 @@ SPDX-License-Identifier: Apache-2.0
|
|||||||
package client
|
package client
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
@ -59,6 +60,7 @@ var _ = Describe("ExtendedClient Get", func() {
|
|||||||
extendedClient *ExtendedClient
|
extendedClient *ExtendedClient
|
||||||
secretInClient *corev1.Secret
|
secretInClient *corev1.Secret
|
||||||
objectStore *barmancloudv1.ObjectStore
|
objectStore *barmancloudv1.ObjectStore
|
||||||
|
cancelCtx context.CancelFunc
|
||||||
)
|
)
|
||||||
|
|
||||||
BeforeEach(func() {
|
BeforeEach(func() {
|
||||||
@ -79,7 +81,14 @@ var _ = Describe("ExtendedClient Get", func() {
|
|||||||
baseClient := fake.NewClientBuilder().
|
baseClient := fake.NewClientBuilder().
|
||||||
WithScheme(scheme).
|
WithScheme(scheme).
|
||||||
WithObjects(secretInClient, objectStore).Build()
|
WithObjects(secretInClient, objectStore).Build()
|
||||||
extendedClient = NewExtendedClient(baseClient).(*ExtendedClient)
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
cancelCtx = cancel
|
||||||
|
extendedClient = NewExtendedClient(ctx, baseClient).(*ExtendedClient)
|
||||||
|
})
|
||||||
|
|
||||||
|
AfterEach(func() {
|
||||||
|
// Cancel the context to stop the cleanup routine
|
||||||
|
cancelCtx()
|
||||||
})
|
})
|
||||||
|
|
||||||
It("returns secret from cache if not expired", func(ctx SpecContext) {
|
It("returns secret from cache if not expired", func(ctx SpecContext) {
|
||||||
@ -164,3 +173,141 @@ var _ = Describe("ExtendedClient Get", func() {
|
|||||||
Expect(objectStore.GetResourceVersion()).To(Equal("from cache"))
|
Expect(objectStore.GetResourceVersion()).To(Equal("from cache"))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
var _ = Describe("ExtendedClient Cache Cleanup", func() {
|
||||||
|
var (
|
||||||
|
extendedClient *ExtendedClient
|
||||||
|
cancelCtx context.CancelFunc
|
||||||
|
)
|
||||||
|
|
||||||
|
BeforeEach(func() {
|
||||||
|
baseClient := fake.NewClientBuilder().
|
||||||
|
WithScheme(scheme).
|
||||||
|
Build()
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
cancelCtx = cancel
|
||||||
|
extendedClient = NewExtendedClient(ctx, baseClient).(*ExtendedClient)
|
||||||
|
})
|
||||||
|
|
||||||
|
AfterEach(func() {
|
||||||
|
cancelCtx()
|
||||||
|
})
|
||||||
|
|
||||||
|
It("cleans up expired entries", func(ctx SpecContext) {
|
||||||
|
// Add some expired entries
|
||||||
|
expiredSecret1 := &corev1.Secret{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Namespace: "default",
|
||||||
|
Name: "expired-secret-1",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
expiredSecret2 := &corev1.Secret{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Namespace: "default",
|
||||||
|
Name: "expired-secret-2",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
validSecret := &corev1.Secret{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Namespace: "default",
|
||||||
|
Name: "valid-secret",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add expired entries (2 minutes ago)
|
||||||
|
addToCache(extendedClient, expiredSecret1, time.Now().Add(-2*time.Minute).Unix())
|
||||||
|
addToCache(extendedClient, expiredSecret2, time.Now().Add(-2*time.Minute).Unix())
|
||||||
|
// Add valid entry (just now)
|
||||||
|
addToCache(extendedClient, validSecret, time.Now().Unix())
|
||||||
|
|
||||||
|
Expect(extendedClient.cachedObjects).To(HaveLen(3))
|
||||||
|
|
||||||
|
// Trigger cleanup
|
||||||
|
extendedClient.cleanupExpiredEntries(ctx)
|
||||||
|
|
||||||
|
// Only the valid entry should remain
|
||||||
|
Expect(extendedClient.cachedObjects).To(HaveLen(1))
|
||||||
|
Expect(extendedClient.cachedObjects[0].entry.GetName()).To(Equal("valid-secret"))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("does nothing when all entries are valid", func(ctx SpecContext) {
|
||||||
|
validSecret1 := &corev1.Secret{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Namespace: "default",
|
||||||
|
Name: "valid-secret-1",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
validSecret2 := &corev1.Secret{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Namespace: "default",
|
||||||
|
Name: "valid-secret-2",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
addToCache(extendedClient, validSecret1, time.Now().Unix())
|
||||||
|
addToCache(extendedClient, validSecret2, time.Now().Unix())
|
||||||
|
|
||||||
|
Expect(extendedClient.cachedObjects).To(HaveLen(2))
|
||||||
|
|
||||||
|
// Trigger cleanup
|
||||||
|
extendedClient.cleanupExpiredEntries(ctx)
|
||||||
|
|
||||||
|
// Both entries should remain
|
||||||
|
Expect(extendedClient.cachedObjects).To(HaveLen(2))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("does nothing when cache is empty", func(ctx SpecContext) {
|
||||||
|
Expect(extendedClient.cachedObjects).To(BeEmpty())
|
||||||
|
|
||||||
|
// Trigger cleanup
|
||||||
|
extendedClient.cleanupExpiredEntries(ctx)
|
||||||
|
|
||||||
|
Expect(extendedClient.cachedObjects).To(BeEmpty())
|
||||||
|
})
|
||||||
|
|
||||||
|
It("removes all entries when all are expired", func(ctx SpecContext) {
|
||||||
|
expiredSecret1 := &corev1.Secret{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Namespace: "default",
|
||||||
|
Name: "expired-secret-1",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
expiredSecret2 := &corev1.Secret{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Namespace: "default",
|
||||||
|
Name: "expired-secret-2",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
addToCache(extendedClient, expiredSecret1, time.Now().Add(-2*time.Minute).Unix())
|
||||||
|
addToCache(extendedClient, expiredSecret2, time.Now().Add(-2*time.Minute).Unix())
|
||||||
|
|
||||||
|
Expect(extendedClient.cachedObjects).To(HaveLen(2))
|
||||||
|
|
||||||
|
// Trigger cleanup
|
||||||
|
extendedClient.cleanupExpiredEntries(ctx)
|
||||||
|
|
||||||
|
Expect(extendedClient.cachedObjects).To(BeEmpty())
|
||||||
|
})
|
||||||
|
|
||||||
|
It("stops cleanup routine when context is cancelled", func() {
|
||||||
|
// Create a new client with a short cleanup interval for testing
|
||||||
|
baseClient := fake.NewClientBuilder().
|
||||||
|
WithScheme(scheme).
|
||||||
|
Build()
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
ec := NewExtendedClient(ctx, baseClient).(*ExtendedClient)
|
||||||
|
ec.cleanupInterval = 10 * time.Millisecond
|
||||||
|
|
||||||
|
// Cancel the context immediately
|
||||||
|
cancel()
|
||||||
|
|
||||||
|
// Verify the cleanup routine actually stops by waiting for the done channel
|
||||||
|
select {
|
||||||
|
case <-ec.cleanupDone:
|
||||||
|
// Success: cleanup routine exited as expected
|
||||||
|
case <-time.After(1 * time.Second):
|
||||||
|
Fail("cleanup routine did not stop within timeout")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|||||||
@ -80,7 +80,7 @@ func Start(ctx context.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
customCacheClient := extendedclient.NewExtendedClient(mgr.GetClient())
|
customCacheClient := extendedclient.NewExtendedClient(ctx, mgr.GetClient())
|
||||||
|
|
||||||
if err := mgr.Add(&CNPGI{
|
if err := mgr.Add(&CNPGI{
|
||||||
Client: customCacheClient,
|
Client: customCacheClient,
|
||||||
|
|||||||
@ -56,6 +56,12 @@ var _ = Describe("Backup and restore", func() {
|
|||||||
ctx SpecContext,
|
ctx SpecContext,
|
||||||
factory testCaseFactory,
|
factory testCaseFactory,
|
||||||
) {
|
) {
|
||||||
|
switch factory.(type) {
|
||||||
|
case *gcsBackupPluginBackupPluginRestore, *gcsBackupPluginBackupInTreeRestore,
|
||||||
|
*gcsBackupPluginInTreeBackupPluginRestore:
|
||||||
|
Skip("GCS e2e tests are disabled until https://github.com/EnterpriseDB/barman/issues/1218 is fixed")
|
||||||
|
}
|
||||||
|
|
||||||
testResources := factory.createBackupRestoreTestResources(namespace.Name)
|
testResources := factory.createBackupRestoreTestResources(namespace.Name)
|
||||||
|
|
||||||
By("starting the ObjectStore deployment")
|
By("starting the ObjectStore deployment")
|
||||||
|
|||||||
@ -57,6 +57,11 @@ var _ = Describe("Replica cluster", func() {
|
|||||||
ctx SpecContext,
|
ctx SpecContext,
|
||||||
factory testCaseFactory,
|
factory testCaseFactory,
|
||||||
) {
|
) {
|
||||||
|
switch factory.(type) {
|
||||||
|
case gcsReplicaClusterFactory:
|
||||||
|
Skip("GCS e2e tests are disabled until https://github.com/EnterpriseDB/barman/issues/1218 is fixed")
|
||||||
|
}
|
||||||
|
|
||||||
testResources := factory.createReplicaClusterTestResources(namespace.Name)
|
testResources := factory.createReplicaClusterTestResources(namespace.Name)
|
||||||
|
|
||||||
By("starting the ObjectStore deployments")
|
By("starting the ObjectStore deployments")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user