Skip to content

Commit

Permalink
fix: remove unnecessary get secret in provisioner (#1020)
Browse files Browse the repository at this point in the history
Signed-off-by: Xuhui zhang <[email protected]>
  • Loading branch information
zxh326 authored Jul 5, 2024
1 parent 53a87aa commit d3926a4
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions pkg/driver/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,6 @@ func (j *provisionerService) Provision(ctx context.Context, options provisioncon
}
klog.V(6).Infof("Provisioner Resolved MountOptions: %v", mountOptions)

secret, err := j.K8sClient.GetSecret(ctx, scParams[config.ProvisionerSecretName], scParams[config.ProvisionerSecretNamespace])
if err != nil {
klog.Errorf("[PVCReconciler]: Get Secret error: %v", err)
j.metrics.provisionErrors.Inc()
return nil, provisioncontroller.ProvisioningFinished, errors.New("unable to provision new pv: " + err.Error())
}
// set volume context
volCtx := make(map[string]string)
volCtx["subPath"] = subPath
Expand Down Expand Up @@ -188,6 +182,13 @@ func (j *provisionerService) Provision(ctx context.Context, options provisioncon
}

if pv.Spec.PersistentVolumeReclaimPolicy == corev1.PersistentVolumeReclaimDelete && options.StorageClass.Parameters["secretFinalizer"] == "true" {
secret, err := j.K8sClient.GetSecret(ctx, scParams[config.ProvisionerSecretName], scParams[config.ProvisionerSecretNamespace])
if err != nil {
klog.Errorf("[PVCReconciler]: Get Secret error: %v", err)
j.metrics.provisionErrors.Inc()
return nil, provisioncontroller.ProvisioningFinished, errors.New("unable to provision new pv: " + err.Error())
}

klog.V(6).Infof("Provisioner: Add Finalizer on %s/%s", secret.Namespace, secret.Name)
err = resource.AddSecretFinalizer(ctx, j.K8sClient, secret, config.Finalizer)
if err != nil {
Expand Down

0 comments on commit d3926a4

Please sign in to comment.