Skip to content

Commit

Permalink
fusemanager: mv fusemanager to repo root
Browse files Browse the repository at this point in the history
Signed-off-by: abushwang <[email protected]>
Co-authored-by: Zuti He <[email protected]>
  • Loading branch information
wswsmao and ilyee committed Dec 12, 2024
1 parent c46cbf2 commit 1fe5463
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 35 deletions.
2 changes: 1 addition & 1 deletion cmd/containerd-stargz-grpc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"github.com/containerd/containerd/v2/pkg/sys"
"github.com/containerd/log"
"github.com/containerd/stargz-snapshotter/cmd/containerd-stargz-grpc/fsopts"
"github.com/containerd/stargz-snapshotter/cmd/stargz-fuse-manager/fusemanager"
"github.com/containerd/stargz-snapshotter/fusemanager"
"github.com/containerd/stargz-snapshotter/service"
"github.com/containerd/stargz-snapshotter/service/keychain/keychainconfig"
snbase "github.com/containerd/stargz-snapshotter/snapshot"
Expand Down
7 changes: 4 additions & 3 deletions cmd/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@ require (
github.com/coreos/go-systemd/v22 v22.5.0
github.com/docker/go-metrics v0.0.1
github.com/goccy/go-json v0.10.3
github.com/gogo/protobuf v1.3.2
github.com/hashicorp/go-multierror v1.1.1
github.com/klauspost/compress v1.17.11
github.com/moby/sys/mountinfo v0.7.2
github.com/opencontainers/go-digest v1.0.0
github.com/opencontainers/image-spec v1.1.0
github.com/opencontainers/runtime-spec v1.2.0
github.com/pelletier/go-toml v1.9.5
github.com/rs/xid v1.6.0
github.com/sirupsen/logrus v1.9.3
github.com/urfave/cli/v2 v2.27.5
go.etcd.io/bbolt v1.3.11
golang.org/x/sync v0.9.0
Expand Down Expand Up @@ -67,6 +64,7 @@ require (
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
Expand All @@ -89,6 +87,7 @@ require (
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/moby/locker v1.0.1 // indirect
github.com/moby/sys/mountinfo v0.7.2 // indirect
github.com/moby/sys/sequential v0.6.0 // indirect
github.com/moby/sys/signal v0.7.1 // indirect
github.com/moby/sys/symlink v0.3.0 // indirect
Expand All @@ -107,11 +106,13 @@ require (
github.com/opencontainers/runtime-tools v0.9.1-0.20221107090550-2e043c6bd626 // indirect
github.com/opencontainers/selinux v1.11.1 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/prometheus/client_golang v1.20.5 // indirect
github.com/prometheus/client_model v0.6.1 // indirect
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
Expand Down
34 changes: 33 additions & 1 deletion cmd/stargz-fuse-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,41 @@
package main

import (
fusemanager "github.com/containerd/stargz-snapshotter/cmd/stargz-fuse-manager/fusemanager"
"github.com/containerd/stargz-snapshotter/cmd/containerd-stargz-grpc/fsopts"
fusemanager "github.com/containerd/stargz-snapshotter/fusemanager"
"github.com/containerd/stargz-snapshotter/service"
"github.com/containerd/stargz-snapshotter/service/keychain/keychainconfig"
)

func init() {
fusemanager.RegisterConfigFunc(func(cc *fusemanager.ConfigContext) ([]service.Option, error) {
fsConfig := fsopts.Config{
EnableIpfs: cc.Config.IPFS,
MetadataStore: cc.Config.MetadataStore,
}
fsOpts, err := fsopts.ConfigFsOpts(cc.Ctx, cc.RootDir, &fsConfig)
if err != nil {
return nil, err
}
return []service.Option{service.WithFilesystemOptions(fsOpts...)}, nil
})

fusemanager.RegisterConfigFunc(func(cc *fusemanager.ConfigContext) ([]service.Option, error) {
keyChainConfig := keychainconfig.Config{
EnableKubeKeychain: cc.Config.Config.KubeconfigKeychainConfig.EnableKeychain,
EnableCRIKeychain: cc.Config.Config.CRIKeychainConfig.EnableKeychain,
KubeconfigPath: cc.Config.Config.KubeconfigKeychainConfig.KubeconfigPath,
DefaultImageServiceAddress: cc.Config.DefaultImageServiceAddress,
ImageServicePath: cc.Config.Config.CRIKeychainConfig.ImageServicePath,
}
credsFuncs, err := keychainconfig.ConfigKeychain(cc.Ctx, cc.Server, &keyChainConfig)
if err != nil {
return nil, err
}
return []service.Option{service.WithCredsFuncs(credsFuncs...)}, nil
})
}

func main() {
fusemanager.Run()
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"google.golang.org/grpc/backoff"
"google.golang.org/grpc/credentials/insecure"

pb "github.com/containerd/stargz-snapshotter/cmd/stargz-fuse-manager/fusemanager/api"
pb "github.com/containerd/stargz-snapshotter/fusemanager/api"
"github.com/containerd/stargz-snapshotter/snapshot"
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
"golang.org/x/sys/unix"
"google.golang.org/grpc"

pb "github.com/containerd/stargz-snapshotter/cmd/stargz-fuse-manager/fusemanager/api"
pb "github.com/containerd/stargz-snapshotter/fusemanager/api"
"github.com/containerd/stargz-snapshotter/version"
)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ import (
bolt "go.etcd.io/bbolt"
"google.golang.org/grpc"

"github.com/containerd/stargz-snapshotter/cmd/containerd-stargz-grpc/fsopts"
pb "github.com/containerd/stargz-snapshotter/cmd/stargz-fuse-manager/fusemanager/api"
pb "github.com/containerd/stargz-snapshotter/fusemanager/api"
"github.com/containerd/stargz-snapshotter/service"
"github.com/containerd/stargz-snapshotter/service/keychain/keychainconfig"
"github.com/containerd/stargz-snapshotter/snapshot"
)

Expand All @@ -52,6 +50,26 @@ type Config struct {
DefaultImageServiceAddress string `json:"default_image_service_address"`
}

type ConfigContext struct {
Ctx context.Context
Config *Config
RootDir string
Server *grpc.Server
}

var (
configFuncs []ConfigFunc
configMu sync.Mutex
)

type ConfigFunc func(cc *ConfigContext) ([]service.Option, error)

func RegisterConfigFunc(f ConfigFunc) {
configMu.Lock()
defer configMu.Unlock()
configFuncs = append(configFuncs, f)
}

type Server struct {
pb.UnimplementedStargzFuseManagerServiceServer

Expand Down Expand Up @@ -126,33 +144,23 @@ func (fm *Server) Init(ctx context.Context, req *pb.InitRequest) (*pb.Response,
fm.root = req.Root
fm.config = config

// Configure keychain
keyChainConfig := keychainconfig.Config{
EnableKubeKeychain: config.Config.KubeconfigKeychainConfig.EnableKeychain,
EnableCRIKeychain: config.Config.CRIKeychainConfig.EnableKeychain,
KubeconfigPath: config.Config.KubeconfigKeychainConfig.KubeconfigPath,
DefaultImageServiceAddress: config.DefaultImageServiceAddress,
ImageServicePath: config.Config.CRIKeychainConfig.ImageServicePath,
}

credsFuncs, err := keychainconfig.ConfigKeychain(ctx, fm.server, &keyChainConfig)
if err != nil {
log.G(ctx).WithError(err).Fatalf("failed to configure keychain")
return &pb.Response{}, err
cc := &ConfigContext{
Ctx: ctx,
Config: fm.config,
RootDir: fm.root,
Server: fm.server,
}

fsConfig := fsopts.Config{
EnableIpfs: config.IPFS,
MetadataStore: config.MetadataStore,
}
fsOpts, err := fsopts.ConfigFsOpts(ctx, fm.root, &fsConfig)
if err != nil {
log.G(ctx).WithError(err).Fatalf("failed to configure fs config")
return &pb.Response{}, err
var opts []service.Option
for _, configFunc := range configFuncs {
funcOpts, err := configFunc(cc)
if err != nil {
log.G(ctx).WithError(err).Errorf("failed to apply config function")
return &pb.Response{}, err
}
opts = append(opts, funcOpts...)
}

opts := []service.Option{service.WithCredsFuncs(credsFuncs...), service.WithFilesystemOptions(fsOpts...)}

fs, err := service.NewFileSystem(ctx, fm.root, fm.config.Config, opts...)
if err != nil {
return &pb.Response{}, err
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ require (
github.com/opencontainers/runtime-spec v1.2.0
github.com/prometheus/client_golang v1.20.5
github.com/rs/xid v1.6.0
github.com/sirupsen/logrus v1.9.3
go.etcd.io/bbolt v1.3.11
golang.org/x/sync v0.9.0
golang.org/x/sys v0.26.0
google.golang.org/grpc v1.68.0
Expand Down Expand Up @@ -90,15 +92,13 @@ require (
github.com/prometheus/common v0.55.0 // indirect
github.com/prometheus/procfs v0.15.1 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/syndtr/gocapability v0.0.0-20200815063812-42c35b437635 // indirect
github.com/urfave/cli/v2 v2.27.5 // indirect
github.com/vbatts/tar-split v0.11.6 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xrash/smetrics v0.0.0-20240521201337-686a1a2994c1 // indirect
go.etcd.io/bbolt v1.3.11 // indirect
go.opencensus.io v0.24.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 // indirect
go.opentelemetry.io/otel v1.31.0 // indirect
Expand Down

0 comments on commit 1fe5463

Please sign in to comment.