-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Kopia storage filesystem opts (#2656)
* Add safecli dependency * add new flag implementations based on the safecli package for the Kopia CLI * apply go fmt Signed-off-by: pavel.larkin <pavel.larkin@veeam.com> * Add common Kopia args and flags * Add Kopia storage core flags * Add kopia filesystem storage flags * cleanup storage tests * Fix Apply and test.Suit Signed-off-by: pavel.larkin <pavel.larkin@veeam.com> * Remove variadic args for Common and Cache flags Signed-off-by: pavel.larkin <pavel.larkin@veeam.com> * pkg/kopia/cli/internal/flag is implemented in the safecli@v0.0.4 now Signed-off-by: pavel.larkin <pavel.larkin@veeam.com> * Add pkg/kopia/cli package Signed-off-by: pavel.larkin <pavel.larkin@veeam.com> * go mod tidy Signed-off-by: pavel.larkin <pavel.larkin@veeam.com> * Add Kopia storage helpers Signed-off-by: pavel.larkin <pavel.larkin@veeam.com> * Implement Kopia storage Filesystem opts Signed-off-by: pavel.larkin <pavel.larkin@veeam.com> * Add (c) headers Signed-off-by: pavel.larkin <pavel.larkin@veeam.com> * Remove unused error Signed-off-by: pavel.larkin <pavel.larkin@veeam.com> * Reorganize imports Signed-off-by: pavel.larkin <pavel.larkin@veeam.com> * Convert common flags from vars to funcs Signed-off-by: pavel.larkin <pavel.larkin@veeam.com> * Add safecli dependency * add new flag implementations based on the safecli package for the Kopia CLI * apply go fmt Signed-off-by: pavel.larkin <pavel.larkin@veeam.com> * Fix Apply and test.Suit Signed-off-by: pavel.larkin <pavel.larkin@veeam.com> * pkg/kopia/cli/internal/flag is implemented in the safecli@v0.0.4 now Signed-off-by: pavel.larkin <pavel.larkin@veeam.com> * Add pkg/kopia/cli package Signed-off-by: pavel.larkin <pavel.larkin@veeam.com> * go mod tidy Signed-off-by: pavel.larkin <pavel.larkin@veeam.com> * Update safecli to v0.0.5 Signed-off-by: pavel.larkin <pavel.larkin@veeam.com> * Update safecli to v0.0.6 Signed-off-by: pavel.larkin <pavel.larkin@veeam.com> * Fix tests Signed-off-by: pavel.larkin <pavel.larkin@veeam.com> * Add Location.IsPointInTypeSupported Signed-off-by: pavel.larkin <pavel.larkin@veeam.com> * Add tests for Location.IsPointInTypeSupported Signed-off-by: pavel.larkin <pavel.larkin@veeam.com> * Fix formatting Signed-off-by: pavel.larkin <pavel.larkin@veeam.com> * organize imports Signed-off-by: pavel.larkin <pavel.larkin@veeam.com> * organize imports Signed-off-by: pavel.larkin <pavel.larkin@veeam.com> --------- Signed-off-by: pavel.larkin <pavel.larkin@veeam.com>
- Loading branch information
Showing
5 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2024 The Kanister Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package fs | ||
|
||
import ( | ||
"github.com/kanisterio/safecli/command" | ||
|
||
"github.com/kanisterio/kanister/pkg/kopia/cli" | ||
"github.com/kanisterio/kanister/pkg/kopia/cli/internal" | ||
"github.com/kanisterio/kanister/pkg/log" | ||
) | ||
|
||
const ( | ||
defaultFSMountPath = "/mnt/data" | ||
) | ||
|
||
// New creates a new subcommand for the filesystem storage. | ||
func New(location internal.Location, repoPathPrefix string, _ log.Logger) command.Applier { | ||
path, err := generateFileSystemMountPath(location.Prefix(), repoPathPrefix) | ||
if err != nil { | ||
return command.NewErrorArgument(err) | ||
} | ||
return command.NewArguments(subcmdFilesystem, optRepoPath(path)) | ||
} | ||
|
||
// generateFileSystemMountPath generates the mount path for the filesystem storage. | ||
func generateFileSystemMountPath(locPrefix, repoPrefix string) (string, error) { | ||
fullRepoPath := internal.GenerateFullRepoPath(locPrefix, repoPrefix) | ||
if fullRepoPath == "" { | ||
return "", cli.ErrInvalidRepoPath | ||
} | ||
return defaultFSMountPath + "/" + fullRepoPath, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2024 The Kanister Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package fs | ||
|
||
import ( | ||
"github.com/kanisterio/safecli/command" | ||
|
||
"github.com/kanisterio/kanister/pkg/kopia/cli" | ||
) | ||
|
||
var ( | ||
subcmdFilesystem = command.NewArgument("filesystem") | ||
) | ||
|
||
// optRepoPath creates a new path option with a given path. | ||
// If the path is empty, it returns an error. | ||
func optRepoPath(path string) command.Applier { | ||
if path == "" { | ||
return command.NewErrorArgument(cli.ErrInvalidRepoPath) | ||
} | ||
return command.NewOptionWithArgument("--path", path) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2024 The Kanister Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package fs | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/kanisterio/safecli/command" | ||
"github.com/kanisterio/safecli/test" | ||
"gopkg.in/check.v1" | ||
|
||
"github.com/kanisterio/kanister/pkg/kopia/cli" | ||
) | ||
|
||
func TestFilesystemOptions(t *testing.T) { check.TestingT(t) } | ||
|
||
var _ = check.Suite(&test.ArgumentSuite{Cmd: "cmd", Arguments: []test.ArgumentTest{ | ||
{ | ||
Name: "optRepoPath", | ||
Argument: command.NewArguments(optRepoPath("/path/to/repo")), | ||
ExpectedCLI: []string{"cmd", "--path=/path/to/repo"}, | ||
}, | ||
{ | ||
Name: "Invalid RepoPath", | ||
Argument: command.NewArguments(optRepoPath("")), | ||
ExpectedErr: cli.ErrInvalidRepoPath, | ||
}, | ||
}}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Copyright 2024 The Kanister Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package fs | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/kanisterio/safecli/command" | ||
"github.com/kanisterio/safecli/test" | ||
"gopkg.in/check.v1" | ||
|
||
"github.com/kanisterio/kanister/pkg/kopia/cli" | ||
"github.com/kanisterio/kanister/pkg/kopia/cli/internal" | ||
) | ||
|
||
func TestNewFilesystem(t *testing.T) { check.TestingT(t) } | ||
|
||
func newFilesystem(prefix, repoPath string) command.Applier { | ||
l := internal.Location{ | ||
"prefix": []byte(prefix), | ||
} | ||
return New(l, repoPath, nil) | ||
} | ||
|
||
var _ = check.Suite(&test.ArgumentSuite{Cmd: "cmd", Arguments: []test.ArgumentTest{ | ||
{ | ||
Name: "NewFilesystem", | ||
Argument: newFilesystem("prefix", "repoPath"), | ||
ExpectedCLI: []string{"cmd", "filesystem", "--path=/mnt/data/prefix/repoPath/"}, | ||
}, | ||
{ | ||
Name: "NewFilesystem with empty repoPath", | ||
Argument: newFilesystem("prefix", ""), | ||
ExpectedCLI: []string{"cmd", "filesystem", "--path=/mnt/data/prefix/"}, | ||
}, | ||
{ | ||
Name: "NewFilesystem with empty local prefix and repo prefix should return error", | ||
Argument: newFilesystem("", ""), | ||
ExpectedErr: cli.ErrInvalidRepoPath, | ||
}, | ||
}}) |