From cf0ecf19f006505d795794d146d525bc347dcb71 Mon Sep 17 00:00:00 2001 From: Armando Ruocco Date: Tue, 5 Nov 2024 17:10:40 +0100 Subject: [PATCH] chore: safeguards Signed-off-by: Armando Ruocco --- internal/client/client.go | 55 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/internal/client/client.go b/internal/client/client.go index aed962c..3729ed4 100644 --- a/internal/client/client.go +++ b/internal/client/client.go @@ -107,3 +107,58 @@ func (e *ExtendedClient) RemoveSecret(key client.ObjectKey) { } } } + +func (e *ExtendedClient) Update( + ctx context.Context, + obj client.Object, + opts ...client.UpdateOption, +) error { + if e.isCacheDisabled() { + return e.Client.Update(ctx, obj, opts...) + } + + if _, ok := obj.(*corev1.Secret); !ok { + return e.Client.Update(ctx, obj, opts...) + } + + e.RemoveSecret(client.ObjectKeyFromObject(obj)) + + return e.Client.Update(ctx, obj, opts...) +} + +func (e *ExtendedClient) Delete( + ctx context.Context, + obj client.Object, + opts ...client.DeleteOption, +) error { + if e.isCacheDisabled() { + return e.Client.Delete(ctx, obj, opts...) + } + + if _, ok := obj.(*corev1.Secret); !ok { + return e.Client.Delete(ctx, obj, opts...) + } + + e.RemoveSecret(client.ObjectKeyFromObject(obj)) + + return e.Client.Delete(ctx, obj, opts...) +} + +func (e *ExtendedClient) Patch( + ctx context.Context, + obj client.Object, + patch client.Patch, + opts ...client.PatchOption, +) error { + if e.isCacheDisabled() { + return e.Client.Patch(ctx, obj, patch, opts...) + } + + if _, ok := obj.(*corev1.Secret); !ok { + return e.Client.Patch(ctx, obj, patch, opts...) + } + + e.RemoveSecret(client.ObjectKeyFromObject(obj)) + + return e.Client.Patch(ctx, obj, patch, opts...) +}