Skip to content

Commit df17885

Browse files
committed
validate tags early during volume creation
1 parent b340fa9 commit df17885

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
@@ -274,6 +274,14 @@ func (s *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolu
274274
return nil, file.StatusError(err)
275275
}
276276

277+
// If tags are used, check if they exist
278+
if tags, ok := req.GetParameters()[cloud.ParameterKeyResourceTags]; ok {
279+
_, err = s.config.tagManager.ValidateResourceTags(ctx, "CreateVolumeRequest", tags)
280+
if err != nil {
281+
return nil, status.Error(codes.InvalidArgument, err.Error())
282+
}
283+
}
284+
277285
if filer != nil {
278286
klog.V(4).Infof("Found existing instance %+v, current instance %+v\n", filer, newFiler)
279287
// 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
@@ -714,6 +714,13 @@ func TestCreateVolume(t *testing.T) {
714714
for _, test := range cases {
715715
cs := initTestController(t).(*controllerServer)
716716
cs.config.features = test.features
717+
718+
if tags, ok := test.req.GetParameters()[cloud.ParameterKeyResourceTags]; ok {
719+
cs.config.tagManager.(*cloud.FakeTagServiceManager).
720+
On("ValidateResourceTags", context.TODO(), tags).
721+
Return(nil, nil)
722+
}
723+
717724
cs.config.tagManager.(*cloud.FakeTagServiceManager).
718725
On("AttachResourceTags", context.TODO(), cloud.FilestoreInstance, testCSIVolume, testLocation, test.req.GetName(), test.req.GetParameters()).
719726
Return(nil)

0 commit comments

Comments
 (0)