1
0
Fork 0
mirror of https://github.com/external-secrets/external-secrets.git synced 2024-12-14 11:57:59 +00:00

fix: resource leak

This commit is contained in:
Moritz Johner 2021-07-28 09:45:25 +02:00
parent d537517cb8
commit 8e61b49c82

View file

@ -54,6 +54,7 @@ const (
errStoreRef = "could not get store reference"
errStoreProvider = "could not get store provider"
errStoreClient = "could not get provider client"
errCloseStoreClient = "could not close provider client"
errSetCtrlReference = "could not set ExternalSecret controller reference: %w"
errFetchTplFrom = "error fetching templateFrom data: %w"
errGetSecretData = "could not get secret data from provider: %w"
@ -63,7 +64,6 @@ const (
errPolicyMergeMutate = "unable to mutate secret %s: %w"
errPolicyMergePatch = "unable to patch secret %s: %w"
errGetSecretKey = "key %q from ExternalSecret %q: %w"
errClientClose = "error closing the connection: %w"
errTplCMMissingKey = "error in configmap %s: missing key %s"
errTplSecMissingKey = "error in secret %s: missing key %s"
)
@ -138,6 +138,13 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
return ctrl.Result{RequeueAfter: requeueAfter}, nil
}
defer func() {
err = secretClient.Close()
if err != nil {
log.Error(err, errCloseStoreClient)
}
}()
refreshInt := time.Hour
if externalSecret.Spec.RefreshInterval != nil {
refreshInt = externalSecret.Spec.RefreshInterval.Duration
@ -376,11 +383,6 @@ func (r *Reconciler) getProviderSecretData(ctx context.Context, providerClient p
providerData[secretRef.SecretKey] = secretData
}
err := providerClient.Close()
if err != nil {
return nil, fmt.Errorf(errClientClose, err)
}
return providerData, nil
}