Skip to content

Commit 4b85283

Browse files
committed
validate tags early during volume creation
1 parent 25d2d7f commit 4b85283

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

pkg/csi_driver/controller.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,14 @@ func (s *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolu
285285
return nil, file.StatusError(err)
286286
}
287287

288+
// If tags are used, check if they exist
289+
if tags, ok := req.GetParameters()[cloud.ParameterKeyResourceTags]; ok {
290+
_, err = s.config.tagManager.ValidateResourceTags(ctx, "CreateVolumeRequest", tags)
291+
if err != nil {
292+
return nil, status.Error(codes.InvalidArgument, err.Error())
293+
}
294+
}
295+
288296
if filer != nil {
289297
klog.V(4).Infof("Found existing instance %+v, current instance %+v\n", filer, newFiler)
290298
// Instance already exists, check if it meets the request

pkg/csi_driver/controller_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,13 @@ func TestCreateVolume(t *testing.T) {
782782
for _, test := range cases {
783783
cs := initTestController(t).(*controllerServer)
784784
cs.config.features = test.features
785+
786+
if tags, ok := test.req.GetParameters()[cloud.ParameterKeyResourceTags]; ok {
787+
cs.config.tagManager.(*cloud.FakeTagServiceManager).
788+
On("ValidateResourceTags", context.TODO(), tags).
789+
Return(nil, nil)
790+
}
791+
785792
cs.config.tagManager.(*cloud.FakeTagServiceManager).
786793
On("AttachResourceTags", context.TODO(), cloud.FilestoreInstance, testCSIVolume, testLocation, test.req.GetName(), test.req.GetParameters()).
787794
Return(nil)

0 commit comments

Comments
 (0)