Skip to content

Commit 3e243d0

Browse files
authored
Merge pull request #125 from codenrhoden/node_id_required
Make NodeID required where needed
2 parents c0d8133 + 521c060 commit 3e243d0

File tree

13 files changed

+92
-122
lines changed

13 files changed

+92
-122
lines changed

README.md

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -247,17 +247,6 @@ environment variables:
247247
<p>Enabling this option sets <code>X_CSI_SPEC_REQ_VALIDATION=true</code></p>
248248
</td>
249249
</tr>
250-
<tr>
251-
<td><code>X_CSI_REQUIRE_NODE_ID</code></td>
252-
<td>
253-
<p>A flag that enables treating the following fields as required:</p>
254-
<ul>
255-
<li><code>ControllerPublishVolumeRequest.NodeId</code></li>
256-
<li><code>NodeGetIdResponse.NodeId</code></li>
257-
</ul>
258-
<p>Enabling this option sets <code>X_CSI_SPEC_REQ_VALIDATION=true</code></p>
259-
</td>
260-
</tr>
261250
<tr>
262251
<td><code>X_CSI_REQUIRE_VOL_CONTEXT</code></td>
263252
<td>

csc/cmd/controller_publish_volume.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,6 @@ func init() {
7373
"",
7474
"The ID of the node to which to publish the volume")
7575

76-
controllerPublishVolumeCmd.Flags().BoolVar(
77-
&root.withRequiresNodeID,
78-
"with-requires-node-id",
79-
false,
80-
`Marks the request's NodeId field as required.
81-
Enabling this option also enables --with-spec-validation.`)
82-
8376
flagReadOnly(
8477
controllerPublishVolumeCmd.Flags(), &controllerPublishVolume.readOnly)
8578

csc/cmd/interceptors.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ func getClientInterceptorsDialOpt() grpc.DialOption {
4242
// Configure the spec validator.
4343
root.withSpecValidator = root.withSpecValidator ||
4444
root.withRequiresCreds ||
45-
root.withRequiresNodeID ||
4645
root.withRequiresVolContext ||
4746
root.withRequiresPubContext
4847
if root.withSpecValidator {
@@ -57,11 +56,6 @@ func getClientInterceptorsDialOpt() grpc.DialOption {
5756
specvalidator.WithRequiresNodePublishVolumeSecrets())
5857
log.Debug("enabled spec validator opt: requires creds")
5958
}
60-
if root.withRequiresNodeID {
61-
specOpts = append(specOpts,
62-
specvalidator.WithRequiresNodeID())
63-
log.Debug("enabled spec validator opt: requires node ID")
64-
}
6559
if root.withRequiresVolContext {
6660
specOpts = append(specOpts,
6761
specvalidator.WithRequiresVolumeContext())

csc/cmd/node_get_info.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,4 @@ var nodeGetInfoCmd = &cobra.Command{
2929

3030
func init() {
3131
nodeCmd.AddCommand(nodeGetInfoCmd)
32-
33-
nodeGetInfoCmd.Flags().BoolVar(
34-
&root.withRequiresNodeID,
35-
"with-requires-node-id",
36-
false,
37-
"marks the response's node ID as a required field")
3832
}

csc/cmd/root.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ var root struct {
3939

4040
withSpecValidator bool
4141
withRequiresCreds bool
42-
withRequiresNodeID bool
4342
withRequiresVolContext bool
4443
withRequiresPubContext bool
4544
}

envvars.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,6 @@ const (
114114
// a code of "Internal."
115115
EnvVarSpecRepValidation = "X_CSI_SPEC_REP_VALIDATION"
116116

117-
// EnvVarRequireNodeID is the name of the environment variable used
118-
// to determine whether or not the node ID value is required for
119-
// requests that accept it and responses that return it such as
120-
// ControllerPublishVolume and GetNodeId.
121-
EnvVarRequireNodeID = "X_CSI_REQUIRE_NODE_ID"
122-
123117
// EnvVarRequireStagingTargetPath is the name of the environment variable
124118
// used to determine whether or not the NodePublishVolume request field
125119
// StagingTargetPath is required.

middleware.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ func (sp *StoragePlugin) initInterceptors(ctx context.Context) {
2828
withSerialVol = sp.getEnvBool(ctx, EnvVarSerialVolAccess)
2929
withSpec = sp.getEnvBool(ctx, EnvVarSpecValidation)
3030
withStgTgtPath = sp.getEnvBool(ctx, EnvVarRequireStagingTargetPath)
31-
withNodeID = sp.getEnvBool(ctx, EnvVarRequireNodeID)
3231
withVolContext = sp.getEnvBool(ctx, EnvVarRequireVolContext)
3332
withPubContext = sp.getEnvBool(ctx, EnvVarRequirePubContext)
3433
withCreds = sp.getEnvBool(ctx, EnvVarCreds)
@@ -62,7 +61,6 @@ func (sp *StoragePlugin) initInterceptors(ctx context.Context) {
6261
if !withSpecReq {
6362
withSpecReq = withCreds ||
6463
withStgTgtPath ||
65-
withNodeID ||
6664
withVolContext ||
6765
withPubContext
6866
log.WithField("withSpecReq", withSpecReq).Debug(
@@ -162,11 +160,6 @@ func (sp *StoragePlugin) initInterceptors(ctx context.Context) {
162160
log.Debug("enabled spec validator opt: " +
163161
"requires starging target path")
164162
}
165-
if withNodeID {
166-
specOpts = append(specOpts,
167-
specvalidator.WithRequiresNodeID())
168-
log.Debug("enabled spec validator opt: requires node ID")
169-
}
170163
if withVolContext {
171164
specOpts = append(specOpts,
172165
specvalidator.WithRequiresVolumeContext())

middleware/specvalidator/spec_validator.go

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ type opts struct {
2525
reqValidation bool
2626
repValidation bool
2727
requiresStagingTargetPath bool
28-
requiresNodeID bool
2928
requiresVolContext bool
3029
requiresPubContext bool
3130
requiresCtlrNewVolSecrets bool
@@ -50,15 +49,6 @@ func WithResponseValidation() Option {
5049
}
5150
}
5251

53-
// WithRequiresNodeID is a Option that indicates
54-
// ControllerPublishVolume requests and NodeGetInfo responses must
55-
// contain non-empty node ID data.
56-
func WithRequiresNodeID() Option {
57-
return func(o *opts) {
58-
o.requiresNodeID = true
59-
}
60-
}
61-
6252
// WithRequiresStagingTargetPath is a Option that indicates
6353
// NodePublishVolume requests must have non-empty StagingTargetPath
6454
// fields.
@@ -264,9 +254,6 @@ func (s *interceptor) handle(
264254
type interceptorHasVolumeID interface {
265255
GetVolumeId() string
266256
}
267-
type interceptorHasNodeID interface {
268-
NodeGetId() string
269-
}
270257
type interceptorHasUserCredentials interface {
271258
GetUserCredentials() map[string]string
272259
}
@@ -302,17 +289,6 @@ func (s *interceptor) validateRequest(
302289
}
303290
}
304291

305-
// Check to see if the request has a node ID and if it is set.
306-
// If the node ID is not set then return an error.
307-
if s.opts.requiresNodeID {
308-
if treq, ok := req.(interceptorHasNodeID); ok {
309-
if treq.NodeGetId() == "" {
310-
return status.Error(
311-
codes.InvalidArgument, "required: NodeID")
312-
}
313-
}
314-
}
315-
316292
// Check to see if the request has volume context and if they're
317293
// required. If the volume context is required by no attributes are
318294
// specified then return an error.
@@ -459,6 +435,11 @@ func (s *interceptor) validateControllerPublishVolumeRequest(
459435
}
460436
}
461437

438+
if req.NodeId == "" {
439+
return status.Error(
440+
codes.InvalidArgument, "required: NodeID")
441+
}
442+
462443
return validateVolumeCapabilityArg(req.VolumeCapability, true)
463444
}
464445

@@ -674,9 +655,10 @@ func (s *interceptor) validateGetPluginInfoResponse(
674655
func (s *interceptor) validateNodeGetInfoResponse(
675656
ctx context.Context,
676657
rep csi.NodeGetInfoResponse) error {
677-
if s.opts.requiresNodeID && rep.NodeId == "" {
658+
if rep.NodeId == "" {
678659
return status.Error(codes.Internal, "empty: NodeID")
679660
}
661+
680662
return nil
681663
}
682664

mock/provider/provider.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ func New() gocsi.StoragePluginProvider {
3939
// Enable request and response validation.
4040
gocsi.EnvVarSpecValidation + "=true",
4141

42-
// Treat the following fields as required:
43-
// * ControllerPublishVolumeRequest.NodeId
44-
// * NodeGetNodeIdResponse.NodeId
45-
gocsi.EnvVarRequireNodeID + "=true",
46-
4742
// Treat the following fields as required:
4843
// * ControllerPublishVolumeResponse.PublishContext
4944
// * NodeStageVolumeRequest.PublishContext

mock/service/controller.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"math"
66
"path"
77
"strconv"
8+
"strings"
89

910
log "github.com/sirupsen/logrus"
1011
"golang.org/x/net/context"
@@ -125,13 +126,24 @@ func (s *service) ControllerUnpublishVolume(
125126
// to the specified node.
126127
devPathKey := path.Join(req.NodeId, "dev")
127128

128-
// Check to see if the volume is already unpublished.
129-
if v.VolumeContext[devPathKey] == "" {
130-
return &csi.ControllerUnpublishVolumeResponse{}, nil
131-
}
129+
// if NodeID is not blank, unpublish from just that node
130+
if req.NodeId != "" {
131+
// Check to see if the volume is already unpublished.
132+
if v.VolumeContext[devPathKey] == "" {
133+
return &csi.ControllerUnpublishVolumeResponse{}, nil
134+
}
132135

133-
// Unpublish the volume.
134-
delete(v.VolumeContext, devPathKey)
136+
// Unpublish the volume.
137+
delete(v.VolumeContext, devPathKey)
138+
} else {
139+
// NodeID is blank, unpublish from all nodes, which can be identified by
140+
// ending with "/dev"
141+
for k, _ := range v.VolumeContext {
142+
if strings.HasSuffix(k, devPathKey) {
143+
delete(v.VolumeContext, k)
144+
}
145+
}
146+
}
135147
s.vols[i] = v
136148

137149
return &csi.ControllerUnpublishVolumeResponse{}, nil

0 commit comments

Comments
 (0)