Skip to content

Commit

Permalink
Merge pull request #3123 from olljanat/verify-nodeid
Browse files Browse the repository at this point in the history
CSI: Manager PublishVolume verify CSI node ID is not empty
  • Loading branch information
dperny committed Mar 15, 2023
2 parents a745a87 + 4dac22f commit e28e8ba
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions manager/csi/plugin.go
Expand Up @@ -6,11 +6,14 @@ import (
"fmt"

"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/docker/docker/pkg/plugingetter"
"github.com/moby/swarmkit/v2/api"
"github.com/moby/swarmkit/v2/internal/csi/capability"
"github.com/moby/swarmkit/v2/log"
)

// Plugin is the interface for a CSI controller plugin.
Expand Down Expand Up @@ -204,6 +207,11 @@ func (p *plugin) PublishVolume(ctx context.Context, v *api.Volume, nodeID string
if !p.publisher {
return nil, nil
}
csiNodeID := p.swarmToCSI[nodeID]
if csiNodeID == "" {
log.L.Errorf("CSI node ID not found for given Swarm node ID. Plugin: %s , Swarm node ID: %s", p.name, nodeID)
return nil, status.Error(codes.FailedPrecondition, "CSI node ID not found for given Swarm node ID")
}

req := p.makeControllerPublishVolumeRequest(v, nodeID)
c, err := p.Client(ctx)
Expand Down
4 changes: 2 additions & 2 deletions manager/csi/plugin_test.go
Expand Up @@ -310,15 +310,15 @@ var _ = Describe("Plugin manager", func() {
PublishStatus: []*api.VolumePublishStatus{
{
State: api.VolumePublishStatus_PENDING_PUBLISH,
NodeID: "node1",
NodeID: "swarmNode1",
},
},
}
plugin.AddNode("swarmNode1", "pluginNode1")
})

JustBeforeEach(func() {
publishContext, publishError = plugin.PublishVolume(context.Background(), v, "node1")
publishContext, publishError = plugin.PublishVolume(context.Background(), v, "swarmNode1")
})

It("should call the ControllerPublishVolume RPC", func() {
Expand Down

0 comments on commit e28e8ba

Please sign in to comment.