mirror of
https://github.com/cloudnative-pg/plugin-barman-cloud.git
synced 2026-01-12 13:43:10 +01:00
chore: remove secret
Signed-off-by: Armando Ruocco <armando.ruocco@enterprisedb.com>
This commit is contained in:
parent
1f6f8b951f
commit
38f50aabfe
@ -14,7 +14,8 @@ type cachedSecret struct {
|
|||||||
fetchUnixTime int64
|
fetchUnixTime int64
|
||||||
}
|
}
|
||||||
|
|
||||||
type extendedClient struct {
|
// ExtendedClient is an extended client that is capable of caching multiple secrets without relying on 'list and watch'
|
||||||
|
type ExtendedClient struct {
|
||||||
client.Client
|
client.Client
|
||||||
cachedSecrets []*cachedSecret
|
cachedSecrets []*cachedSecret
|
||||||
// add a mux to lock the operations on the cache
|
// add a mux to lock the operations on the cache
|
||||||
@ -23,12 +24,12 @@ type extendedClient struct {
|
|||||||
|
|
||||||
// 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
|
||||||
func NewExtendedClient(baseClient client.Client) client.Client {
|
func NewExtendedClient(baseClient client.Client) client.Client {
|
||||||
return &extendedClient{
|
return &ExtendedClient{
|
||||||
Client: baseClient,
|
Client: baseClient,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *extendedClient) Get(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error {
|
func (e *ExtendedClient) Get(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error {
|
||||||
if _, ok := obj.(*corev1.Secret); !ok {
|
if _, ok := obj.(*corev1.Secret); !ok {
|
||||||
return e.Client.Get(ctx, key, obj, opts...)
|
return e.Client.Get(ctx, key, obj, opts...)
|
||||||
}
|
}
|
||||||
@ -69,3 +70,16 @@ func (e *extendedClient) Get(ctx context.Context, key client.ObjectKey, obj clie
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RemoveSecret ensures that a secret is not present in the cache
|
||||||
|
func (e *ExtendedClient) RemoveSecret(key client.ObjectKey) {
|
||||||
|
e.mux.Lock()
|
||||||
|
defer e.mux.Unlock()
|
||||||
|
|
||||||
|
for i, cache := range e.cachedSecrets {
|
||||||
|
if cache.secret.Namespace == key.Namespace && cache.secret.Name == key.Name {
|
||||||
|
e.cachedSecrets = append(e.cachedSecrets[:i], e.cachedSecrets[i+1:]...)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user