Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Kopia storage filesystem opts #2656

Merged
merged 48 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
680e782
Add safecli dependency
plar Feb 3, 2024
72011e7
add new flag implementations based on the safecli package for the Kop…
plar Feb 3, 2024
0f635ad
apply go fmt
plar Feb 4, 2024
d0a6dd1
Add common Kopia args and flags
plar Feb 6, 2024
ca853c1
Add Kopia storage core flags
plar Feb 6, 2024
2d44961
Add kopia filesystem storage flags
plar Feb 6, 2024
8f363ed
cleanup storage tests
plar Feb 6, 2024
9850f4a
Fix Apply and test.Suit
plar Feb 12, 2024
246e1c1
Remove variadic args for Common and Cache flags
plar Feb 12, 2024
419652c
Merge branch 'kopia-cli-core-infra' into kopia-cli-common-flags
plar Feb 12, 2024
24707e5
pkg/kopia/cli/internal/flag is implemented in the safecli@v0.0.4 now
plar Feb 17, 2024
c029fc1
Merge branch 'master' into kopia-cli-core-infra
plar Feb 17, 2024
cff7220
Re-implement Kopia common args and opts; Sync with the master
plar Feb 17, 2024
550d124
Add pkg/kopia/cli package
plar Feb 17, 2024
fc918a0
go mod tidy
plar Feb 17, 2024
9530c91
Merge branch 'kopia-cli-core-infra' into kopia-cli-common-flags
plar Feb 17, 2024
75fb036
Merge branch 'kopia-cli-common-flags' into kopia-cli-storage-core-flags
plar Feb 17, 2024
9fdf94b
Add Kopia storage helpers
plar Feb 17, 2024
6e7963a
Merge branch 'kopia-cli-storage-core-flags' into kopia-cli-storage-fs…
plar Feb 17, 2024
57adfc2
Implement Kopia storage Filesystem opts
plar Feb 17, 2024
18d8dd6
Add (c) headers
plar Feb 17, 2024
e1bf966
Remove unused error
plar Feb 17, 2024
e51868b
Reorganize imports
plar Feb 17, 2024
2c6cb6e
Convert common flags from vars to funcs
plar Feb 26, 2024
1a3ee2d
Add safecli dependency
plar Feb 3, 2024
386e7e9
add new flag implementations based on the safecli package for the Kop…
plar Feb 3, 2024
b815f63
apply go fmt
plar Feb 4, 2024
bcafabb
Fix Apply and test.Suit
plar Feb 12, 2024
6d61bb4
pkg/kopia/cli/internal/flag is implemented in the safecli@v0.0.4 now
plar Feb 17, 2024
e6ddb8f
Add pkg/kopia/cli package
plar Feb 17, 2024
4e7ffd7
go mod tidy
plar Feb 17, 2024
f16aea7
Update safecli to v0.0.5
plar Feb 27, 2024
dcd6425
Update safecli to v0.0.6
plar Feb 28, 2024
d3dfb31
Sync with upstream
plar Feb 28, 2024
d2ac987
Merge branch 'kopia-cli-common-flags' into kopia-cli-storage-core-flags
plar Feb 28, 2024
dfa748c
Merge branch 'kopia-cli-storage-core-flags' into kopia-cli-storage-fs…
plar Feb 28, 2024
b093421
Fix tests
plar Feb 28, 2024
6e71143
Merge branch 'kopia-cli-common-flags' into kopia-cli-storage-core-flags
plar Feb 28, 2024
de3a52b
Add Location.IsPointInTypeSupported
plar Feb 28, 2024
722b279
Add tests for Location.IsPointInTypeSupported
plar Feb 28, 2024
71a5aa5
Merge branch 'kopia-cli-storage-core-flags' into kopia-cli-storage-fs…
plar Feb 28, 2024
44c133e
Fix formatting
plar Feb 29, 2024
1897a1e
Merge branch 'kopia-cli-core-infra' into kopia-cli-common-flags
plar Feb 29, 2024
33b1342
organize imports
plar Feb 29, 2024
83292af
Merge branch 'kopia-cli-common-flags' into kopia-cli-storage-core-flags
plar Feb 29, 2024
516a14c
organize imports
plar Feb 29, 2024
9d7d01d
Merge branch 'kopia-cli-storage-core-flags' into kopia-cli-storage-fs…
plar Feb 29, 2024
7cb521a
Merge branch 'master' into kopia-cli-storage-fs-flags
plar Mar 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/kopia/cli/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ var (
var (
// ErrUnsupportedStorage is returned when the storage is not supported.
ErrUnsupportedStorage = errors.New("unsupported storage")
// ErrInvalidRepoPath is returned when the repoPath is empty.
ErrInvalidRepoPath = errors.New("repository path cannot be empty")
)
45 changes: 45 additions & 0 deletions pkg/kopia/cli/repository/storage/fs/fs.go
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
}
34 changes: 34 additions & 0 deletions pkg/kopia/cli/repository/storage/fs/fs_opts.go
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)
}
40 changes: 40 additions & 0 deletions pkg/kopia/cli/repository/storage/fs/fs_opts_test.go
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,
},
}})
53 changes: 53 additions & 0 deletions pkg/kopia/cli/repository/storage/fs/fs_test.go
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,
},
}})