Skip to content

Commit

Permalink
Return 400 when can't create backup uri
Browse files Browse the repository at this point in the history
  • Loading branch information
hsadoyan authored and saikat-royc committed Jun 13, 2023
1 parent a174f15 commit 49c2f53
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 3 additions & 2 deletions pkg/cloud_provider/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,8 @@ func (manager *gcfsServiceManager) GetBackup(ctx context.Context, backupUri stri
func (manager *gcfsServiceManager) CreateBackup(ctx context.Context, obj *ServiceInstance, backupName string, backupLocation string) (*filev1beta1.Backup, error) {
backupUri, region, err := CreateBackupURI(obj, backupName, backupLocation)
if err != nil {
return nil, err
klog.Errorf("Failed to create backup URI from given name %s and location %s, error: %v", backupName, backupLocation, err.Error())
return nil, status.Error(codes.InvalidArgument, err.Error())
}

backupSource := fmt.Sprintf("projects/%s/locations/%s/instances/%s", obj.Project, obj.Location, obj.Name)
Expand Down Expand Up @@ -743,7 +744,7 @@ func CodeForError(err error) *codes.Code {
}

// This function returns the backup URI, the region that was picked to be the backup resource location and error.
func CreateBackupURI(obj *ServiceInstance, backupName, backupLocation string) (string, string, error) {
func CreateBackupURI(obj *ServiceInstance, backupName string, backupLocation string) (string, string, error) {
region, err := deduceRegion(obj, backupLocation)
if err != nil {
return "", "", err
Expand Down
6 changes: 4 additions & 2 deletions pkg/csi_driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -868,9 +868,11 @@ func (s *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateSn
}

// Check for existing snapshot
backupUri, _, err := file.CreateBackupURI(filer, req.Name, util.GetBackupLocation(req.GetParameters()))
backupLocation := util.GetBackupLocation(req.GetParameters())
backupUri, _, err := file.CreateBackupURI(filer, req.Name, backupLocation)
if err != nil {
return nil, err
klog.Errorf("Failed to create backup URI from given name %s and location %s, error: %v", req.Name, backupLocation, err.Error())
return nil, status.Error(codes.InvalidArgument, err.Error())
}
backupInfo, err := s.config.fileService.GetBackup(ctx, backupUri)
if err != nil {
Expand Down

0 comments on commit 49c2f53

Please sign in to comment.