Skip to content

Commit ffc8b65

Browse files
wswsmaoilyee
andcommitted
fusemanager: mv fusemanager to repo root
Signed-off-by: abushwang <[email protected]> Co-authored-by: Zuti He <[email protected]>
1 parent c46cbf2 commit ffc8b65

File tree

13 files changed

+111
-73
lines changed

13 files changed

+111
-73
lines changed

cmd/containerd-stargz-grpc/fsopts/fsopts.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ func ConfigFsOpts(ctx context.Context, rootDir string, config *Config) ([]fs.Opt
5050

5151
mt, err := getMetadataStore(rootDir, config)
5252
if err != nil {
53-
log.G(ctx).WithError(err).Fatalf("failed to configure metadata store")
54-
return nil, err
53+
return nil, fmt.Errorf("failed to configure metadata store: %w", err)
5554
}
5655
fsOpts = append(fsOpts, fs.WithMetadataStore(mt))
5756

cmd/containerd-stargz-grpc/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
"github.com/containerd/containerd/v2/pkg/sys"
3737
"github.com/containerd/log"
3838
"github.com/containerd/stargz-snapshotter/cmd/containerd-stargz-grpc/fsopts"
39-
"github.com/containerd/stargz-snapshotter/cmd/stargz-fuse-manager/fusemanager"
39+
"github.com/containerd/stargz-snapshotter/fusemanager"
4040
"github.com/containerd/stargz-snapshotter/service"
4141
"github.com/containerd/stargz-snapshotter/service/keychain/keychainconfig"
4242
snbase "github.com/containerd/stargz-snapshotter/snapshot"
@@ -165,7 +165,7 @@ func main() {
165165
if !filepath.IsAbs(fmAddr) {
166166
log.G(ctx).WithError(err).Fatalf("fuse manager address must be an absolute path: %s", fmAddr)
167167
}
168-
err := service.StartFuseManager(ctx, fmPath, fmAddr, filepath.Join(*rootDir, "fusestore.db"), *logLevel, filepath.Join(*rootDir, "stargz-fuse-manager.log"))
168+
err := fusemanager.StartFuseManager(ctx, fmPath, fmAddr, filepath.Join(*rootDir, "fusestore.db"), *logLevel, filepath.Join(*rootDir, "stargz-fuse-manager.log"))
169169
if err != nil {
170170
log.G(ctx).WithError(err).Fatalf("failed to start fusemanager")
171171
}

cmd/go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,13 @@ require (
1414
github.com/coreos/go-systemd/v22 v22.5.0
1515
github.com/docker/go-metrics v0.0.1
1616
github.com/goccy/go-json v0.10.3
17-
github.com/gogo/protobuf v1.3.2
1817
github.com/hashicorp/go-multierror v1.1.1
1918
github.com/klauspost/compress v1.17.11
20-
github.com/moby/sys/mountinfo v0.7.2
2119
github.com/opencontainers/go-digest v1.0.0
2220
github.com/opencontainers/image-spec v1.1.0
2321
github.com/opencontainers/runtime-spec v1.2.0
2422
github.com/pelletier/go-toml v1.9.5
2523
github.com/rs/xid v1.6.0
26-
github.com/sirupsen/logrus v1.9.3
2724
github.com/urfave/cli/v2 v2.27.5
2825
go.etcd.io/bbolt v1.3.11
2926
golang.org/x/sync v0.9.0
@@ -67,6 +64,7 @@ require (
6764
github.com/go-openapi/jsonreference v0.20.2 // indirect
6865
github.com/go-openapi/swag v0.22.4 // indirect
6966
github.com/godbus/dbus/v5 v5.1.0 // indirect
67+
github.com/gogo/protobuf v1.3.2 // indirect
7068
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
7169
github.com/golang/protobuf v1.5.4 // indirect
7270
github.com/google/gnostic-models v0.6.8 // indirect
@@ -89,6 +87,7 @@ require (
8987
github.com/minio/sha256-simd v1.0.1 // indirect
9088
github.com/mitchellh/go-homedir v1.1.0 // indirect
9189
github.com/moby/locker v1.0.1 // indirect
90+
github.com/moby/sys/mountinfo v0.7.2 // indirect
9291
github.com/moby/sys/sequential v0.6.0 // indirect
9392
github.com/moby/sys/signal v0.7.1 // indirect
9493
github.com/moby/sys/symlink v0.3.0 // indirect
@@ -107,11 +106,13 @@ require (
107106
github.com/opencontainers/runtime-tools v0.9.1-0.20221107090550-2e043c6bd626 // indirect
108107
github.com/opencontainers/selinux v1.11.1 // indirect
109108
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
109+
github.com/pkg/errors v0.9.1 // indirect
110110
github.com/prometheus/client_golang v1.20.5 // indirect
111111
github.com/prometheus/client_model v0.6.1 // indirect
112112
github.com/prometheus/common v0.55.0 // indirect
113113
github.com/prometheus/procfs v0.15.1 // indirect
114114
github.com/russross/blackfriday/v2 v2.1.0 // indirect
115+
github.com/sirupsen/logrus v1.9.3 // indirect
115116
github.com/spaolacci/murmur3 v1.1.0 // indirect
116117
github.com/spf13/pflag v1.0.5 // indirect
117118
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect

cmd/stargz-fuse-manager/main.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,41 @@
1717
package main
1818

1919
import (
20-
fusemanager "github.com/containerd/stargz-snapshotter/cmd/stargz-fuse-manager/fusemanager"
20+
"github.com/containerd/stargz-snapshotter/cmd/containerd-stargz-grpc/fsopts"
21+
fusemanager "github.com/containerd/stargz-snapshotter/fusemanager"
22+
"github.com/containerd/stargz-snapshotter/service"
23+
"github.com/containerd/stargz-snapshotter/service/keychain/keychainconfig"
2124
)
2225

26+
func init() {
27+
fusemanager.RegisterConfigFunc(func(cc *fusemanager.ConfigContext) ([]service.Option, error) {
28+
fsConfig := fsopts.Config{
29+
EnableIpfs: cc.Config.IPFS,
30+
MetadataStore: cc.Config.MetadataStore,
31+
}
32+
fsOpts, err := fsopts.ConfigFsOpts(cc.Ctx, cc.RootDir, &fsConfig)
33+
if err != nil {
34+
return nil, err
35+
}
36+
return []service.Option{service.WithFilesystemOptions(fsOpts...)}, nil
37+
})
38+
39+
fusemanager.RegisterConfigFunc(func(cc *fusemanager.ConfigContext) ([]service.Option, error) {
40+
keyChainConfig := keychainconfig.Config{
41+
EnableKubeKeychain: cc.Config.Config.KubeconfigKeychainConfig.EnableKeychain,
42+
EnableCRIKeychain: cc.Config.Config.CRIKeychainConfig.EnableKeychain,
43+
KubeconfigPath: cc.Config.Config.KubeconfigKeychainConfig.KubeconfigPath,
44+
DefaultImageServiceAddress: cc.Config.DefaultImageServiceAddress,
45+
ImageServicePath: cc.Config.Config.CRIKeychainConfig.ImageServicePath,
46+
}
47+
credsFuncs, err := keychainconfig.ConfigKeychain(cc.Ctx, cc.Server, &keyChainConfig)
48+
if err != nil {
49+
return nil, err
50+
}
51+
return []service.Option{service.WithCredsFuncs(credsFuncs...)}, nil
52+
})
53+
}
54+
2355
func main() {
2456
fusemanager.Run()
2557
}

cmd/stargz-fuse-manager/fusemanager/client.go renamed to fusemanager/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"google.golang.org/grpc/backoff"
2929
"google.golang.org/grpc/credentials/insecure"
3030

31-
pb "github.com/containerd/stargz-snapshotter/cmd/stargz-fuse-manager/fusemanager/api"
31+
pb "github.com/containerd/stargz-snapshotter/fusemanager/api"
3232
"github.com/containerd/stargz-snapshotter/snapshot"
3333
)
3434

cmd/stargz-fuse-manager/fusemanager/fusemanager.go renamed to fusemanager/fusemanager.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
"golang.org/x/sys/unix"
3434
"google.golang.org/grpc"
3535

36-
pb "github.com/containerd/stargz-snapshotter/cmd/stargz-fuse-manager/fusemanager/api"
36+
pb "github.com/containerd/stargz-snapshotter/fusemanager/api"
3737
"github.com/containerd/stargz-snapshotter/version"
3838
)
3939

@@ -234,3 +234,36 @@ func runFuseManager(ctx context.Context) error {
234234

235235
return err
236236
}
237+
238+
func StartFuseManager(ctx context.Context, executable, address, fusestore, logLevel, logPath string) error {
239+
// if socket exists, do not start it
240+
if _, err := os.Stat(address); err == nil {
241+
return nil
242+
} else if !os.IsNotExist(err) {
243+
return err
244+
}
245+
246+
if _, err := os.Stat(executable); err != nil {
247+
log.G(ctx).WithError(err).Errorf("failed to stat fusemanager binary: %s", executable)
248+
return err
249+
}
250+
251+
args := []string{
252+
"-action", "start",
253+
"-address", address,
254+
"-fusestore-path", fusestore,
255+
"-log-level", logLevel,
256+
"-log-path", logPath,
257+
}
258+
259+
cmd := exec.Command(executable, args...)
260+
if err := cmd.Start(); err != nil {
261+
return err
262+
}
263+
264+
if err := cmd.Wait(); err != nil {
265+
return err
266+
}
267+
268+
return nil
269+
}

0 commit comments

Comments
 (0)