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

Merge pull request #290 from external-secrets/fix/res-leak

fix: resource leak
This commit is contained in:
paul-the-alien[bot] 2021-07-28 10:51:50 +00:00 committed by GitHub
commit e0c5f921e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

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
}