From 9c8cdbaf67cbbfe9bc390525597ef07cabf21464 Mon Sep 17 00:00:00 2001 From: abushwang Date: Mon, 9 Dec 2024 17:13:31 +0800 Subject: [PATCH] fusemanager: resolve review comments Signed-off-by: abushwang --- cmd/containerd-stargz-grpc/main.go | 19 +++++++------------ .../fusemanager/service.go | 2 +- .../keychain/keychainconfig/keychainconfig.go | 9 ++++----- 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/cmd/containerd-stargz-grpc/main.go b/cmd/containerd-stargz-grpc/main.go index 596002730..21c572bb7 100644 --- a/cmd/containerd-stargz-grpc/main.go +++ b/cmd/containerd-stargz-grpc/main.go @@ -46,7 +46,6 @@ import ( "github.com/pelletier/go-toml" "golang.org/x/sys/unix" "google.golang.org/grpc" - runtime "k8s.io/cri-api/pkg/apis/runtime/v1" ) const ( @@ -55,10 +54,10 @@ const ( defaultLogLevel = log.InfoLevel defaultRootDir = "/var/lib/containerd-stargz-grpc" defaultImageServiceAddress = "/run/containerd/containerd.sock" - defaultFuseManagerAddress = "/run/containerd-stargz-grpc/fuse-namanger.sock" + defaultFuseManagerAddress = "/run/containerd-stargz-grpc/fuse-manager.sock" fuseManagerBin = "stargz-fuse-manager" - fuseManagerAddress = "fuse-mananger.sock" + fuseManagerAddress = "fuse-manager.sock" ) var ( @@ -148,15 +147,6 @@ func main() { ImageServicePath: config.CRIKeychainConfig.ImageServicePath, } - credsFuncs, criServer, err := keychainconfig.ConfigKeychain(ctx, &keyChainConfig) - if err != nil { - log.G(ctx).WithError(err).Fatalf("failed to configure keychain") - } - - if config.Config.CRIKeychainConfig.EnableKeychain { - runtime.RegisterImageServiceServer(rpc, criServer) - } - var rs snapshots.Snapshotter if *detachFuseManager { fmPath := config.FuseManagerPath @@ -197,6 +187,11 @@ func main() { } log.G(ctx).Infof("Start snapshotter with fusemanager mode") } else { + credsFuncs, err := keychainconfig.ConfigKeychain(ctx, rpc, &keyChainConfig) + if err != nil { + log.G(ctx).WithError(err).Fatalf("failed to configure keychain") + } + fsConfig := fsopts.Config{ EnableIpfs: config.IPFS, MetadataStore: config.MetadataStore, diff --git a/cmd/stargz-fuse-manager/fusemanager/service.go b/cmd/stargz-fuse-manager/fusemanager/service.go index 9c8fc145a..41d9a17bc 100644 --- a/cmd/stargz-fuse-manager/fusemanager/service.go +++ b/cmd/stargz-fuse-manager/fusemanager/service.go @@ -136,7 +136,7 @@ func (fm *Server) Init(ctx context.Context, req *pb.InitRequest) (*pb.Response, ImageServicePath: config.Config.CRIKeychainConfig.ImageServicePath, } - credsFuncs, _, err := keychainconfig.ConfigKeychain(ctx, &keyChainConfig) + credsFuncs, err := keychainconfig.ConfigKeychain(ctx, fm.server, &keyChainConfig) if err != nil { log.G(ctx).WithError(err).Fatalf("failed to configure keychain") } diff --git a/service/keychain/keychainconfig/keychainconfig.go b/service/keychain/keychainconfig/keychainconfig.go index c28c23983..3cf973a1f 100644 --- a/service/keychain/keychainconfig/keychainconfig.go +++ b/service/keychain/keychainconfig/keychainconfig.go @@ -40,9 +40,8 @@ type Config struct { ImageServicePath string } -func ConfigKeychain(ctx context.Context, config *Config) ([]resolver.Credential, runtime.ImageServiceServer, error) { +func ConfigKeychain(ctx context.Context, rpc *grpc.Server, config *Config) ([]resolver.Credential, error) { credsFuncs := []resolver.Credential{dockerconfig.NewDockerconfigKeychain(ctx)} - var criServer runtime.ImageServiceServer if config.EnableKubeKeychain { var opts []kubeconfig.Option if kcp := config.KubeconfigPath; kcp != "" { @@ -63,12 +62,12 @@ func ConfigKeychain(ctx context.Context, config *Config) ([]resolver.Credential, } return runtime.NewImageServiceClient(conn), nil } - f, server := cri.NewCRIKeychain(ctx, connectCRI) + f, criServer := cri.NewCRIKeychain(ctx, connectCRI) + runtime.RegisterImageServiceServer(rpc, criServer) credsFuncs = append(credsFuncs, f) - criServer = server } - return credsFuncs, criServer, nil + return credsFuncs, nil } func newCRIConn(criAddr string) (*grpc.ClientConn, error) {