2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2020-01-08 12:47:07 +00:00
|
|
|
package allocrunner
|
|
|
|
|
|
|
|
import (
|
2020-02-11 13:45:16 +00:00
|
|
|
"context"
|
|
|
|
"fmt"
|
2022-02-24 15:39:07 +00:00
|
|
|
"strings"
|
2022-01-28 13:30:31 +00:00
|
|
|
"sync"
|
|
|
|
"time"
|
2020-02-11 13:45:16 +00:00
|
|
|
|
2020-01-08 12:47:07 +00:00
|
|
|
hclog "github.com/hashicorp/go-hclog"
|
2020-08-06 18:51:46 +00:00
|
|
|
multierror "github.com/hashicorp/go-multierror"
|
2023-04-10 22:15:33 +00:00
|
|
|
"github.com/hashicorp/nomad/client/dynamicplugins"
|
2020-02-11 13:45:16 +00:00
|
|
|
"github.com/hashicorp/nomad/client/pluginmanager/csimanager"
|
2023-04-03 15:03:36 +00:00
|
|
|
cstructs "github.com/hashicorp/nomad/client/structs"
|
2022-02-22 18:43:06 +00:00
|
|
|
"github.com/hashicorp/nomad/helper"
|
2020-01-08 12:47:07 +00:00
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
2020-05-21 13:18:02 +00:00
|
|
|
"github.com/hashicorp/nomad/plugins/drivers"
|
2020-01-08 12:47:07 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// csiHook will wait for remote csi volumes to be attached to the host before
|
|
|
|
// continuing.
|
|
|
|
//
|
|
|
|
// It is a noop for allocs that do not depend on CSI Volumes.
|
|
|
|
type csiHook struct {
|
2022-04-05 17:05:10 +00:00
|
|
|
alloc *structs.Allocation
|
|
|
|
logger hclog.Logger
|
|
|
|
csimanager csimanager.Manager
|
|
|
|
|
|
|
|
// interfaces implemented by the allocRunner
|
2022-01-07 20:23:47 +00:00
|
|
|
rpcClient RPCer
|
|
|
|
taskCapabilityGetter taskCapabilityGetter
|
2023-04-03 15:03:36 +00:00
|
|
|
hookResources *cstructs.AllocHookResources
|
2022-01-07 20:23:47 +00:00
|
|
|
|
2022-04-05 17:05:10 +00:00
|
|
|
nodeSecret string
|
2022-01-28 13:30:31 +00:00
|
|
|
volumeRequests map[string]*volumeAndRequest
|
2022-02-24 15:39:07 +00:00
|
|
|
minBackoffInterval time.Duration
|
2022-01-28 13:30:31 +00:00
|
|
|
maxBackoffInterval time.Duration
|
|
|
|
maxBackoffDuration time.Duration
|
2022-04-05 17:05:10 +00:00
|
|
|
|
|
|
|
shutdownCtx context.Context
|
|
|
|
shutdownCancelFn context.CancelFunc
|
2020-01-08 12:47:07 +00:00
|
|
|
}
|
|
|
|
|
2022-01-07 20:23:47 +00:00
|
|
|
// implemented by allocrunner
|
|
|
|
type taskCapabilityGetter interface {
|
|
|
|
GetTaskDriverCapabilities(string) (*drivers.Capabilities, error)
|
|
|
|
}
|
|
|
|
|
2023-04-03 15:03:36 +00:00
|
|
|
func newCSIHook(alloc *structs.Allocation, logger hclog.Logger, csi csimanager.Manager, rpcClient RPCer, taskCapabilityGetter taskCapabilityGetter, hookResources *cstructs.AllocHookResources, nodeSecret string) *csiHook {
|
2022-04-05 17:05:10 +00:00
|
|
|
|
|
|
|
shutdownCtx, shutdownCancelFn := context.WithCancel(context.Background())
|
|
|
|
|
2022-01-07 20:23:47 +00:00
|
|
|
return &csiHook{
|
|
|
|
alloc: alloc,
|
|
|
|
logger: logger.Named("csi_hook"),
|
|
|
|
csimanager: csi,
|
|
|
|
rpcClient: rpcClient,
|
|
|
|
taskCapabilityGetter: taskCapabilityGetter,
|
2023-04-03 15:03:36 +00:00
|
|
|
hookResources: hookResources,
|
2022-01-07 20:23:47 +00:00
|
|
|
nodeSecret: nodeSecret,
|
|
|
|
volumeRequests: map[string]*volumeAndRequest{},
|
2022-02-24 15:39:07 +00:00
|
|
|
minBackoffInterval: time.Second,
|
2022-01-28 13:30:31 +00:00
|
|
|
maxBackoffInterval: time.Minute,
|
|
|
|
maxBackoffDuration: time.Hour * 24,
|
2022-04-05 17:05:10 +00:00
|
|
|
shutdownCtx: shutdownCtx,
|
|
|
|
shutdownCancelFn: shutdownCancelFn,
|
2022-01-07 20:23:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-08 12:47:07 +00:00
|
|
|
func (c *csiHook) Name() string {
|
|
|
|
return "csi_hook"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *csiHook) Prerun() error {
|
|
|
|
if !c.shouldRun() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-02-17 12:57:25 +00:00
|
|
|
volumes, err := c.claimVolumesFromAlloc()
|
2020-02-11 13:45:16 +00:00
|
|
|
if err != nil {
|
2020-03-10 14:22:42 +00:00
|
|
|
return fmt.Errorf("claim volumes: %v", err)
|
2020-02-11 13:45:16 +00:00
|
|
|
}
|
2020-08-06 18:51:46 +00:00
|
|
|
c.volumeRequests = volumes
|
2020-02-11 13:45:16 +00:00
|
|
|
|
|
|
|
mounts := make(map[string]*csimanager.MountInfo, len(volumes))
|
2020-02-17 11:10:12 +00:00
|
|
|
for alias, pair := range volumes {
|
2022-04-05 17:05:10 +00:00
|
|
|
|
2023-04-10 22:15:33 +00:00
|
|
|
// make sure the plugin is ready or becomes so quickly.
|
|
|
|
plugin := pair.volume.PluginID
|
|
|
|
pType := dynamicplugins.PluginTypeCSINode
|
|
|
|
if err := c.csimanager.WaitForPlugin(c.shutdownCtx, pType, plugin); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
c.logger.Debug("found CSI plugin", "type", pType, "name", plugin)
|
|
|
|
|
|
|
|
mounter, err := c.csimanager.MounterForPlugin(c.shutdownCtx, plugin)
|
2020-02-11 13:45:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-02-17 11:10:12 +00:00
|
|
|
usageOpts := &csimanager.UsageOptions{
|
|
|
|
ReadOnly: pair.request.ReadOnly,
|
2021-04-02 18:36:13 +00:00
|
|
|
AttachmentMode: pair.request.AttachmentMode,
|
|
|
|
AccessMode: pair.request.AccessMode,
|
2020-03-23 17:55:26 +00:00
|
|
|
MountOptions: pair.request.MountOptions,
|
2020-02-17 11:10:12 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 17:05:10 +00:00
|
|
|
mountInfo, err := mounter.MountVolume(
|
|
|
|
c.shutdownCtx, pair.volume, c.alloc, usageOpts, pair.publishContext)
|
2020-02-11 13:45:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
mounts[alias] = mountInfo
|
|
|
|
}
|
|
|
|
|
2023-04-03 15:03:36 +00:00
|
|
|
// make the mounts available to the taskrunner's volume_hook
|
|
|
|
c.hookResources.SetCSIMounts(mounts)
|
2020-02-11 13:45:16 +00:00
|
|
|
|
2020-01-08 12:47:07 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-08-06 18:51:46 +00:00
|
|
|
// Postrun sends an RPC to the server to unpublish the volume. This may
|
|
|
|
// forward client RPCs to the node plugins or to the controller plugins,
|
|
|
|
// depending on whether other allocations on this node have claims on this
|
|
|
|
// volume.
|
|
|
|
func (c *csiHook) Postrun() error {
|
|
|
|
if !c.shouldRun() {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-01-28 13:30:31 +00:00
|
|
|
var wg sync.WaitGroup
|
|
|
|
errs := make(chan error, len(c.volumeRequests))
|
2020-08-06 18:51:46 +00:00
|
|
|
|
|
|
|
for _, pair := range c.volumeRequests {
|
2022-01-28 13:30:31 +00:00
|
|
|
wg.Add(1)
|
2022-04-05 17:05:10 +00:00
|
|
|
// CSI RPCs can potentially take a long time. Split the work
|
|
|
|
// into goroutines so that operators could potentially reuse
|
|
|
|
// one of a set of volumes
|
2022-01-28 13:30:31 +00:00
|
|
|
go func(pair *volumeAndRequest) {
|
|
|
|
defer wg.Done()
|
2022-04-05 17:05:10 +00:00
|
|
|
err := c.unmountImpl(pair)
|
2022-01-28 13:30:31 +00:00
|
|
|
if err != nil {
|
2022-04-05 17:05:10 +00:00
|
|
|
// we can recover an unmount failure if the operator
|
|
|
|
// brings the plugin back up, so retry every few minutes
|
|
|
|
// but eventually give up. Don't block shutdown so that
|
|
|
|
// we don't block shutting down the client in -dev mode
|
|
|
|
go func(pair *volumeAndRequest) {
|
|
|
|
err := c.unmountWithRetry(pair)
|
|
|
|
if err != nil {
|
|
|
|
c.logger.Error("volume could not be unmounted")
|
|
|
|
}
|
|
|
|
err = c.unpublish(pair)
|
|
|
|
if err != nil {
|
|
|
|
c.logger.Error("volume could not be unpublished")
|
|
|
|
}
|
|
|
|
}(pair)
|
2022-01-28 13:30:31 +00:00
|
|
|
}
|
2020-11-11 18:06:30 +00:00
|
|
|
|
2022-01-28 13:30:31 +00:00
|
|
|
// we can't recover from this RPC error client-side; the
|
|
|
|
// volume claim GC job will have to clean up for us once
|
|
|
|
// the allocation is marked terminal
|
|
|
|
errs <- c.unpublish(pair)
|
|
|
|
}(pair)
|
|
|
|
}
|
2020-11-11 18:06:30 +00:00
|
|
|
|
2022-01-28 13:30:31 +00:00
|
|
|
wg.Wait()
|
|
|
|
close(errs) // so we don't block waiting if there were no errors
|
2021-03-18 19:35:11 +00:00
|
|
|
|
2022-01-28 13:30:31 +00:00
|
|
|
var mErr *multierror.Error
|
|
|
|
for err := range errs {
|
|
|
|
mErr = multierror.Append(mErr, err)
|
2020-08-06 18:51:46 +00:00
|
|
|
}
|
2022-01-28 13:30:31 +00:00
|
|
|
|
2020-08-06 18:51:46 +00:00
|
|
|
return mErr.ErrorOrNil()
|
|
|
|
}
|
|
|
|
|
2020-02-17 11:10:12 +00:00
|
|
|
type volumeAndRequest struct {
|
|
|
|
volume *structs.CSIVolume
|
|
|
|
request *structs.VolumeRequest
|
2020-02-17 12:57:25 +00:00
|
|
|
|
|
|
|
// When volumeAndRequest was returned from a volume claim, this field will be
|
|
|
|
// populated for plugins that require it.
|
|
|
|
publishContext map[string]string
|
|
|
|
}
|
|
|
|
|
|
|
|
// claimVolumesFromAlloc is used by the pre-run hook to fetch all of the volume
|
|
|
|
// metadata and claim it for use by this alloc/node at the same time.
|
|
|
|
func (c *csiHook) claimVolumesFromAlloc() (map[string]*volumeAndRequest, error) {
|
|
|
|
result := make(map[string]*volumeAndRequest)
|
|
|
|
tg := c.alloc.Job.LookupTaskGroup(c.alloc.TaskGroup)
|
2022-06-22 14:43:43 +00:00
|
|
|
supportsVolumes := false
|
2020-02-17 12:57:25 +00:00
|
|
|
|
2022-06-22 14:43:43 +00:00
|
|
|
for _, task := range tg.Tasks {
|
|
|
|
caps, err := c.taskCapabilityGetter.GetTaskDriverCapabilities(task.Name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("could not validate task driver capabilities: %v", err)
|
|
|
|
}
|
2020-05-21 13:18:02 +00:00
|
|
|
|
2022-06-22 14:43:43 +00:00
|
|
|
if caps.MountConfigs == drivers.MountConfigSupportNone {
|
|
|
|
continue
|
|
|
|
}
|
2020-05-21 13:18:02 +00:00
|
|
|
|
2022-06-22 14:43:43 +00:00
|
|
|
supportsVolumes = true
|
|
|
|
break
|
|
|
|
}
|
2020-05-21 13:18:02 +00:00
|
|
|
|
2022-06-22 14:43:43 +00:00
|
|
|
if !supportsVolumes {
|
|
|
|
return nil, fmt.Errorf("no task supports CSI")
|
|
|
|
}
|
2020-05-21 13:18:02 +00:00
|
|
|
|
2022-06-22 14:43:43 +00:00
|
|
|
// Initially, populate the result map with all of the requests
|
|
|
|
for alias, volumeRequest := range tg.Volumes {
|
|
|
|
if volumeRequest.Type == structs.VolumeTypeCSI {
|
2020-02-17 12:57:25 +00:00
|
|
|
result[alias] = &volumeAndRequest{request: volumeRequest}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Iterate over the result map and upsert the volume field as each volume gets
|
|
|
|
// claimed by the server.
|
|
|
|
for alias, pair := range result {
|
|
|
|
claimType := structs.CSIVolumeClaimWrite
|
|
|
|
if pair.request.ReadOnly {
|
|
|
|
claimType = structs.CSIVolumeClaimRead
|
|
|
|
}
|
|
|
|
|
2021-03-18 19:35:11 +00:00
|
|
|
source := pair.request.Source
|
|
|
|
if pair.request.PerAlloc {
|
|
|
|
source = source + structs.AllocSuffix(c.alloc.Name)
|
|
|
|
}
|
|
|
|
|
2020-02-17 12:57:25 +00:00
|
|
|
req := &structs.CSIVolumeClaimRequest{
|
2021-04-02 18:36:13 +00:00
|
|
|
VolumeID: source,
|
|
|
|
AllocationID: c.alloc.ID,
|
|
|
|
NodeID: c.alloc.NodeID,
|
|
|
|
Claim: claimType,
|
|
|
|
AccessMode: pair.request.AccessMode,
|
|
|
|
AttachmentMode: pair.request.AttachmentMode,
|
2020-08-11 17:08:39 +00:00
|
|
|
WriteRequest: structs.WriteRequest{
|
|
|
|
Region: c.alloc.Job.Region,
|
|
|
|
Namespace: c.alloc.Job.Namespace,
|
2022-01-07 20:23:47 +00:00
|
|
|
AuthToken: c.nodeSecret,
|
2020-08-11 17:08:39 +00:00
|
|
|
},
|
2020-02-17 12:57:25 +00:00
|
|
|
}
|
|
|
|
|
2022-02-24 15:39:07 +00:00
|
|
|
resp, err := c.claimWithRetry(req)
|
|
|
|
if err != nil {
|
2022-01-07 20:23:47 +00:00
|
|
|
return nil, fmt.Errorf("could not claim volume %s: %w", req.VolumeID, err)
|
2020-02-17 12:57:25 +00:00
|
|
|
}
|
|
|
|
if resp.Volume == nil {
|
|
|
|
return nil, fmt.Errorf("Unexpected nil volume returned for ID: %v", pair.request.Source)
|
|
|
|
}
|
|
|
|
|
2021-04-02 18:36:13 +00:00
|
|
|
result[alias].request = pair.request
|
2020-02-17 12:57:25 +00:00
|
|
|
result[alias].volume = resp.Volume
|
|
|
|
result[alias].publishContext = resp.PublishContext
|
|
|
|
}
|
|
|
|
|
|
|
|
return result, nil
|
2020-02-17 11:10:12 +00:00
|
|
|
}
|
|
|
|
|
2022-02-24 15:39:07 +00:00
|
|
|
// claimWithRetry tries to claim the volume on the server, retrying
|
|
|
|
// with exponential backoff capped to a maximum interval
|
|
|
|
func (c *csiHook) claimWithRetry(req *structs.CSIVolumeClaimRequest) (*structs.CSIVolumeClaimResponse, error) {
|
|
|
|
|
2022-04-05 17:05:10 +00:00
|
|
|
ctx, cancel := context.WithTimeout(c.shutdownCtx, c.maxBackoffDuration)
|
2022-02-24 15:39:07 +00:00
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
var resp structs.CSIVolumeClaimResponse
|
|
|
|
var err error
|
|
|
|
backoff := c.minBackoffInterval
|
|
|
|
t, stop := helper.NewSafeTimer(0)
|
|
|
|
defer stop()
|
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return nil, err
|
|
|
|
case <-t.C:
|
|
|
|
}
|
|
|
|
|
|
|
|
err = c.rpcClient.RPC("CSIVolume.Claim", req, &resp)
|
|
|
|
if err == nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
if !isRetryableClaimRPCError(err) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
if backoff < c.maxBackoffInterval {
|
|
|
|
backoff = backoff * 2
|
|
|
|
if backoff > c.maxBackoffInterval {
|
|
|
|
backoff = c.maxBackoffInterval
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.logger.Debug(
|
2022-03-29 13:44:00 +00:00
|
|
|
"volume could not be claimed because it is in use", "retry_in", backoff)
|
2022-02-24 15:39:07 +00:00
|
|
|
t.Reset(backoff)
|
|
|
|
}
|
|
|
|
return &resp, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// isRetryableClaimRPCError looks for errors where we need to retry
|
|
|
|
// with backoff because we expect them to be eventually resolved.
|
|
|
|
func isRetryableClaimRPCError(err error) bool {
|
|
|
|
|
|
|
|
// note: because these errors are returned via RPC which breaks error
|
|
|
|
// wrapping, we can't check with errors.Is and need to read the string
|
|
|
|
errMsg := err.Error()
|
|
|
|
if strings.Contains(errMsg, structs.ErrCSIVolumeMaxClaims.Error()) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if strings.Contains(errMsg, structs.ErrCSIClientRPCRetryable.Error()) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if strings.Contains(errMsg, "no servers") {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
if strings.Contains(errMsg, structs.ErrNoLeader.Error()) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2021-12-20 10:44:21 +00:00
|
|
|
func (c *csiHook) shouldRun() bool {
|
|
|
|
tg := c.alloc.Job.LookupTaskGroup(c.alloc.TaskGroup)
|
2020-01-08 12:47:07 +00:00
|
|
|
for _, vol := range tg.Volumes {
|
|
|
|
if vol.Type == structs.VolumeTypeCSI {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|
2022-01-28 13:30:31 +00:00
|
|
|
|
|
|
|
func (c *csiHook) unpublish(pair *volumeAndRequest) error {
|
|
|
|
|
|
|
|
mode := structs.CSIVolumeClaimRead
|
|
|
|
if !pair.request.ReadOnly {
|
|
|
|
mode = structs.CSIVolumeClaimWrite
|
|
|
|
}
|
|
|
|
|
|
|
|
source := pair.request.Source
|
|
|
|
if pair.request.PerAlloc {
|
|
|
|
// NOTE: PerAlloc can't be set if we have canaries
|
|
|
|
source = source + structs.AllocSuffix(c.alloc.Name)
|
|
|
|
}
|
|
|
|
|
|
|
|
req := &structs.CSIVolumeUnpublishRequest{
|
|
|
|
VolumeID: source,
|
|
|
|
Claim: &structs.CSIVolumeClaim{
|
|
|
|
AllocationID: c.alloc.ID,
|
|
|
|
NodeID: c.alloc.NodeID,
|
|
|
|
Mode: mode,
|
|
|
|
State: structs.CSIVolumeClaimStateUnpublishing,
|
|
|
|
},
|
|
|
|
WriteRequest: structs.WriteRequest{
|
|
|
|
Region: c.alloc.Job.Region,
|
|
|
|
Namespace: c.alloc.Job.Namespace,
|
|
|
|
AuthToken: c.nodeSecret,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return c.rpcClient.RPC("CSIVolume.Unpublish",
|
|
|
|
req, &structs.CSIVolumeUnpublishResponse{})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// unmountWithRetry tries to unmount/unstage the volume, retrying with
|
|
|
|
// exponential backoff capped to a maximum interval
|
|
|
|
func (c *csiHook) unmountWithRetry(pair *volumeAndRequest) error {
|
|
|
|
|
2022-04-05 17:05:10 +00:00
|
|
|
ctx, cancel := context.WithTimeout(c.shutdownCtx, c.maxBackoffDuration)
|
2022-01-28 13:30:31 +00:00
|
|
|
defer cancel()
|
|
|
|
var err error
|
2022-02-24 15:39:07 +00:00
|
|
|
backoff := c.minBackoffInterval
|
2022-02-22 18:43:06 +00:00
|
|
|
t, stop := helper.NewSafeTimer(0)
|
|
|
|
defer stop()
|
2022-01-28 13:30:31 +00:00
|
|
|
for {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
return err
|
2022-02-22 18:43:06 +00:00
|
|
|
case <-t.C:
|
2022-01-28 13:30:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = c.unmountImpl(pair)
|
|
|
|
if err == nil {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
|
|
|
if backoff < c.maxBackoffInterval {
|
|
|
|
backoff = backoff * 2
|
|
|
|
if backoff > c.maxBackoffInterval {
|
|
|
|
backoff = c.maxBackoffInterval
|
|
|
|
}
|
|
|
|
}
|
2022-03-29 13:44:00 +00:00
|
|
|
c.logger.Debug("volume could not be unmounted", "retry_in", backoff)
|
2022-02-22 18:43:06 +00:00
|
|
|
t.Reset(backoff)
|
2022-01-28 13:30:31 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// unmountImpl implements the call to the CSI plugin manager to
|
|
|
|
// unmount the volume. Each retry will write an "Unmount volume"
|
|
|
|
// NodeEvent
|
|
|
|
func (c *csiHook) unmountImpl(pair *volumeAndRequest) error {
|
|
|
|
|
2022-04-05 17:05:10 +00:00
|
|
|
mounter, err := c.csimanager.MounterForPlugin(c.shutdownCtx, pair.volume.PluginID)
|
2022-01-28 13:30:31 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
usageOpts := &csimanager.UsageOptions{
|
|
|
|
ReadOnly: pair.request.ReadOnly,
|
|
|
|
AttachmentMode: pair.request.AttachmentMode,
|
|
|
|
AccessMode: pair.request.AccessMode,
|
|
|
|
MountOptions: pair.request.MountOptions,
|
|
|
|
}
|
|
|
|
|
2022-04-05 17:05:10 +00:00
|
|
|
return mounter.UnmountVolume(c.shutdownCtx,
|
2022-01-28 13:30:31 +00:00
|
|
|
pair.volume.ID, pair.volume.RemoteID(), c.alloc.ID, usageOpts)
|
|
|
|
}
|
2022-04-05 17:05:10 +00:00
|
|
|
|
|
|
|
// Shutdown will get called when the client is gracefully
|
|
|
|
// stopping. Cancel our shutdown context so that we don't block client
|
|
|
|
// shutdown while in the CSI RPC retry loop.
|
|
|
|
func (c *csiHook) Shutdown() {
|
|
|
|
c.logger.Trace("shutting down hook")
|
|
|
|
c.shutdownCancelFn()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Destroy will get called when an allocation gets GC'd on the client
|
|
|
|
// or when a -dev mode client is stopped. Cancel our shutdown context
|
|
|
|
// so that we don't block client shutdown while in the CSI RPC retry
|
|
|
|
// loop.
|
|
|
|
func (c *csiHook) Destroy() {
|
|
|
|
c.logger.Trace("destroying hook")
|
|
|
|
c.shutdownCancelFn()
|
|
|
|
}
|