mirror of
https://github.com/cloudnative-pg/plugin-barman-cloud.git
synced 2026-07-08 18:52:20 +02:00
Compare commits
7 Commits
300ad0a294
...
4df942aab2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4df942aab2 | ||
|
|
0bb78879ce | ||
|
|
ef4b711137 | ||
|
|
baf7985d66 | ||
|
|
d244faa5b2 | ||
|
|
6a55a361a3 | ||
|
|
62b579101f |
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -44,7 +44,7 @@ jobs:
|
||||
- name: Install Dagger
|
||||
env:
|
||||
# renovate: datasource=github-tags depName=dagger/dagger versioning=semver
|
||||
DAGGER_VERSION: 0.20.8
|
||||
DAGGER_VERSION: 0.21.0
|
||||
run: |
|
||||
curl -L https://dl.dagger.io/dagger/install.sh | BIN_DIR=$HOME/.local/bin sh
|
||||
- name: Run CI task
|
||||
|
||||
2
.github/workflows/release-please.yml
vendored
2
.github/workflows/release-please.yml
vendored
@ -31,7 +31,7 @@ jobs:
|
||||
- name: Install Dagger
|
||||
env:
|
||||
# renovate: datasource=github-tags depName=dagger/dagger versioning=semver
|
||||
DAGGER_VERSION: 0.20.8
|
||||
DAGGER_VERSION: 0.21.0
|
||||
run: |
|
||||
curl -L https://dl.dagger.io/dagger/install.sh | BIN_DIR=$HOME/.local/bin sh
|
||||
- name: Create image and manifest
|
||||
|
||||
2
.github/workflows/release-publish.yml
vendored
2
.github/workflows/release-publish.yml
vendored
@ -21,7 +21,7 @@ jobs:
|
||||
- name: Install Dagger
|
||||
env:
|
||||
# renovate: datasource=github-tags depName=dagger/dagger versioning=semver
|
||||
DAGGER_VERSION: 0.20.8
|
||||
DAGGER_VERSION: 0.21.0
|
||||
run: |
|
||||
curl -L https://dl.dagger.io/dagger/install.sh | BIN_DIR=$HOME/.local/bin sh
|
||||
- name: Create image and manifest
|
||||
|
||||
12
Taskfile.yml
12
Taskfile.yml
@ -46,7 +46,7 @@ tasks:
|
||||
- wordlist-ordered
|
||||
env:
|
||||
# renovate: datasource=git-refs depName=spellcheck lookupName=https://github.com/cloudnative-pg/daggerverse currentValue=main
|
||||
DAGGER_SPELLCHECK_SHA: 537e0ddae55ad0344af8f4454de7f27baeee48fa
|
||||
DAGGER_SPELLCHECK_SHA: 21755df1a27febff19b28dbe6ae57116f6088bb0
|
||||
cmds:
|
||||
- >
|
||||
GITHUB_REF= dagger -s call -m github.com/cloudnative-pg/daggerverse/spellcheck@${DAGGER_SPELLCHECK_SHA}
|
||||
@ -60,7 +60,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: 537e0ddae55ad0344af8f4454de7f27baeee48fa
|
||||
DAGGER_COMMITLINT_SHA: 21755df1a27febff19b28dbe6ae57116f6088bb0
|
||||
cmds:
|
||||
- >
|
||||
GITHUB_REF= dagger -s call -m github.com/cloudnative-pg/daggerverse/commitlint@${DAGGER_COMMITLINT_SHA}
|
||||
@ -74,7 +74,7 @@ tasks:
|
||||
- wordlist-ordered
|
||||
env:
|
||||
# renovate: datasource=git-refs depName=uncommitted lookupName=https://github.com/cloudnative-pg/daggerverse currentValue=main
|
||||
DAGGER_UNCOMMITTED_SHA: 537e0ddae55ad0344af8f4454de7f27baeee48fa
|
||||
DAGGER_UNCOMMITTED_SHA: 21755df1a27febff19b28dbe6ae57116f6088bb0
|
||||
cmds:
|
||||
- GITHUB_REF= dagger -s call -m github.com/cloudnative-pg/daggerverse/uncommitted@${DAGGER_UNCOMMITTED_SHA} check-uncommitted --source . stdout
|
||||
sources:
|
||||
@ -86,7 +86,7 @@ tasks:
|
||||
- controller-gen
|
||||
env:
|
||||
# renovate: datasource=git-refs depName=crd-gen-refs lookupName=https://github.com/cloudnative-pg/daggerverse currentValue=main
|
||||
DAGGER_CRDGENREF_SHA: 537e0ddae55ad0344af8f4454de7f27baeee48fa
|
||||
DAGGER_CRDGENREF_SHA: 21755df1a27febff19b28dbe6ae57116f6088bb0
|
||||
# renovate: datasource=go depName=github.com/elastic/crd-ref-docs
|
||||
CRDREFDOCS_VERSION: v0.3.0
|
||||
cmds:
|
||||
@ -206,7 +206,7 @@ tasks:
|
||||
- start-build-network
|
||||
vars:
|
||||
# renovate: datasource=github-tags depName=dagger/dagger versioning=semver
|
||||
DAGGER_VERSION: 0.20.8
|
||||
DAGGER_VERSION: 0.21.0
|
||||
DAGGER_ENGINE_IMAGE: registry.dagger.io/engine:v{{ .DAGGER_VERSION }}
|
||||
cmds:
|
||||
- >
|
||||
@ -381,7 +381,7 @@ tasks:
|
||||
run: once
|
||||
env:
|
||||
# renovate: datasource=git-refs depName=controller-gen lookupName=https://github.com/cloudnative-pg/daggerverse currentValue=main
|
||||
DAGGER_CONTROLLER_GEN_SHA: 537e0ddae55ad0344af8f4454de7f27baeee48fa
|
||||
DAGGER_CONTROLLER_GEN_SHA: 21755df1a27febff19b28dbe6ae57116f6088bb0
|
||||
cmds:
|
||||
- >
|
||||
GITHUB_REF= dagger -s call -m github.com/cloudnative-pg/daggerverse/controller-gen@${DAGGER_CONTROLLER_GEN_SHA}
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
barman[azure,cloud,google,snappy,zstandard,lz4]==3.18.0
|
||||
barman[azure,cloud,google,snappy,zstandard,lz4]==3.19.1
|
||||
setuptools==82.0.1
|
||||
zipp>=3.19.1 # not directly required, pinned by Snyk to avoid a vulnerability
|
||||
|
||||
@ -18,9 +18,9 @@ azure-storage-blob==12.29.0 \
|
||||
--hash=sha256:2824ddd7ebc9056034ebc76b17971a38e9aa5835abb0d565b9700493f2a6c657 \
|
||||
--hash=sha256:ccf8a1bcd5e49df83ab85aab793b579e5ba2eeea2ad8900b2f62ca3a37dc391f
|
||||
# via barman
|
||||
barman==3.18.0 \
|
||||
--hash=sha256:8e752ac93d2f3a61e86b8374185209cae477a638ece7e6f540070f36d28d6997 \
|
||||
--hash=sha256:ff90c44dafa4107b7574142771cdc2611c4cf1af818d93d3e67440a0c81164b9
|
||||
barman==3.19.1 \
|
||||
--hash=sha256:0a6a9e1babf97687732d8b2a3eb79ea95d55246a5257b9433865cb6e755221c0 \
|
||||
--hash=sha256:2f71c4a1f1ba53f694cbdf838bb9906d8ba02b97d1fd3041196e8999bec7a1ee
|
||||
# via -r sidecar-requirements.in
|
||||
boto3==1.43.14 \
|
||||
--hash=sha256:574335744656cfed0b362a0a0467aaf2eb2bf15526edcd02d31d3c661f4b09e4 \
|
||||
@ -788,6 +788,4 @@ zstandard==0.25.0 \
|
||||
setuptools==82.0.1 \
|
||||
--hash=sha256:7d872682c5d01cfde07da7bccc7b65469d3dca203318515ada1de5eda35efbf9 \
|
||||
--hash=sha256:a59e362652f08dcd477c78bb6e7bd9d80a7995bc73ce773050228a348ce2e5bb
|
||||
# via
|
||||
# -r sidecar-requirements.in
|
||||
# barman
|
||||
# via -r sidecar-requirements.in
|
||||
|
||||
4
go.mod
4
go.mod
@ -9,7 +9,7 @@ require (
|
||||
github.com/cloudnative-pg/cloudnative-pg v1.29.1
|
||||
github.com/cloudnative-pg/cnpg-i v0.5.0
|
||||
github.com/cloudnative-pg/cnpg-i-machinery v0.4.2
|
||||
github.com/cloudnative-pg/machinery v0.4.0
|
||||
github.com/cloudnative-pg/machinery v0.5.0
|
||||
github.com/onsi/ginkgo/v2 v2.29.0
|
||||
github.com/onsi/gomega v1.41.0
|
||||
github.com/spf13/cobra v1.10.2
|
||||
@ -114,7 +114,7 @@ require (
|
||||
golang.org/x/net v0.53.0 // indirect
|
||||
golang.org/x/oauth2 v0.36.0 // indirect
|
||||
golang.org/x/sync v0.20.0 // indirect
|
||||
golang.org/x/sys v0.43.0 // indirect
|
||||
golang.org/x/sys v0.45.0 // indirect
|
||||
golang.org/x/term v0.42.0 // indirect
|
||||
golang.org/x/text v0.36.0 // indirect
|
||||
golang.org/x/time v0.15.0 // indirect
|
||||
|
||||
8
go.sum
8
go.sum
@ -28,8 +28,8 @@ github.com/cloudnative-pg/cnpg-i v0.5.0 h1:/TOzpNT6cwNgrpftTtrnLKdoHgMwd+88vZgXj
|
||||
github.com/cloudnative-pg/cnpg-i v0.5.0/go.mod h1:7Gh4+UzhBpGhr4DreB1GN9wGYfvxwXCXZUyVt3zE/3I=
|
||||
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/machinery v0.4.0 h1:3sfqrBptH4QQSVB4g10Z+7aiQRnh4g+6AsqsK0ibKaQ=
|
||||
github.com/cloudnative-pg/machinery v0.4.0/go.mod h1:OIwaTYAnLv8PmBmBvEf0BvMK2JBX6J+naTMg9UgV1FQ=
|
||||
github.com/cloudnative-pg/machinery v0.5.0 h1:hhTnkzn+AiN3NmbjCQ6RXj5rfqV3K6arzq6kdXAzcnQ=
|
||||
github.com/cloudnative-pg/machinery v0.5.0/go.mod h1:uuFjqBUjWn0a9uvAk1ixTSzPM0PrjaS+QiKLOIBqLm4=
|
||||
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.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
@ -275,8 +275,8 @@ golang.org/x/oauth2 v0.36.0 h1:peZ/1z27fi9hUOFCAZaHyrpWG5lwe0RJEEEeH0ThlIs=
|
||||
golang.org/x/oauth2 v0.36.0/go.mod h1:YDBUJMTkDnJS+A4BP4eZBjCqtokkg1hODuPjwiGPO7Q=
|
||||
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
|
||||
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
||||
golang.org/x/sys v0.43.0 h1:Rlag2XtaFTxp19wS8MXlJwTvoh8ArU6ezoyFsMyCTNI=
|
||||
golang.org/x/sys v0.43.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||
golang.org/x/sys v0.45.0 h1:dO4czNzziLiiXplLQgBCEpCvXQ3dnkn0SdaZSYdQ+FY=
|
||||
golang.org/x/sys v0.45.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||
golang.org/x/term v0.42.0 h1:UiKe+zDFmJobeJ5ggPwOshJIVt6/Ft0rcfrXZDLWAWY=
|
||||
golang.org/x/term v0.42.0/go.mod h1:Dq/D+snpsbazcBG5+F9Q1n2rXV8Ma+71xEjTRufARgY=
|
||||
golang.org/x/text v0.36.0 h1:JfKh3XmcRPqZPKevfXVpI1wXPTqbkE5f7JA92a55Yxg=
|
||||
|
||||
@ -36,6 +36,9 @@ import (
|
||||
// DefaultTTLSeconds is the default TTL in seconds of cache entries
|
||||
const DefaultTTLSeconds = 10
|
||||
|
||||
// DefaultCleanupIntervalSeconds is the default interval in seconds for cache cleanup
|
||||
const DefaultCleanupIntervalSeconds = 30
|
||||
|
||||
type cachedEntry struct {
|
||||
entry client.Object
|
||||
fetchUnixTime int64
|
||||
@ -51,16 +54,28 @@ type ExtendedClient struct {
|
||||
client.Client
|
||||
cachedObjects []cachedEntry
|
||||
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(
|
||||
ctx context.Context,
|
||||
baseClient client.Client,
|
||||
) client.Client {
|
||||
return &ExtendedClient{
|
||||
ec := &ExtendedClient{
|
||||
Client: baseClient,
|
||||
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 {
|
||||
@ -208,3 +223,55 @@ func (e *ExtendedClient) Patch(
|
||||
|
||||
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
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
@ -59,6 +60,7 @@ var _ = Describe("ExtendedClient Get", func() {
|
||||
extendedClient *ExtendedClient
|
||||
secretInClient *corev1.Secret
|
||||
objectStore *barmancloudv1.ObjectStore
|
||||
cancelCtx context.CancelFunc
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
@ -79,7 +81,14 @@ var _ = Describe("ExtendedClient Get", func() {
|
||||
baseClient := fake.NewClientBuilder().
|
||||
WithScheme(scheme).
|
||||
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) {
|
||||
@ -164,3 +173,141 @@ var _ = Describe("ExtendedClient Get", func() {
|
||||
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
|
||||
}
|
||||
|
||||
customCacheClient := extendedclient.NewExtendedClient(mgr.GetClient())
|
||||
customCacheClient := extendedclient.NewExtendedClient(ctx, mgr.GetClient())
|
||||
|
||||
if err := mgr.Add(&CNPGI{
|
||||
Client: customCacheClient,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user