mirror of
https://github.com/hanzoai/s3-csi.git
synced 2026-09-30 23:52:32 +00:00
Fork of seaweedfs/seaweedfs-csi-driver, renamed seaweedfs -> s3 throughout and ported off protobuf entirely. WHY a fork was unavoidable: hanzoai/s3 serves HanzoFiler over the native ZAP transport on the port still named "grpc" (18888) — s3/command/filer.go binds it with transport.ListenStream and says it "replaces the legacy gRPC HanzoFiler server: the whole filer (28 unary + 5 streaming RPCs) now answers over ZAP, no gRPC". RegisterHanzoFilerServer exists nowhere in that tree. So the upstream driver's gRPC client cannot connect at all; it fails as `Unimplemented: unknown service filer_pb.SeaweedFiler`, which LOOKS like a service-name mismatch but is a gRPC client hitting a non-gRPC port. Renaming the service in the client would not have helped. pkg/filer is the only place this driver touches storage, and it speaks ZAP: Mkdir -> CreateEntry (CreateVolume) Remove -> DeleteEntry (DeleteVolume) Exists -> LookupDirectoryEntry (ValidateVolumeCapabilities) One shared, concurrency-safe client multiplexes over a single ZAP connection, dials lazily so controller start does not depend on filer readiness, and redials exactly once on a transport fault (covers a filer restart closing an idle conn without becoming a retry storm against a struggling backend). pkg/driver/volume.go Quota() likewise moves to s3/wire/mount — the fork generates no mount_pb at all. Dead gRPC plumbing (WithFilerClient, AdjustedUrl, grpcDialOption) is deleted rather than left inert. The kubelet-facing side stays CSI gRPC: that is the Kubernetes contract between kubelet and any CSI driver, not a Hanzo choice. Zero protobuf call sites remain. Whole module compiles clean. Co-authored-by: Hanzo Dev <[email protected]>
96 lines
2.0 KiB
Go
96 lines
2.0 KiB
Go
package driver
|
|
|
|
import (
|
|
"net"
|
|
"os"
|
|
"sync"
|
|
|
|
"github.com/hanzoai/s3/s3/glog"
|
|
"google.golang.org/grpc"
|
|
|
|
"github.com/container-storage-interface/spec/lib/go/csi"
|
|
)
|
|
|
|
// Defines Non blocking GRPC server interfaces
|
|
type NonBlockingGRPCServer interface {
|
|
// Start services at the endpoint
|
|
Start(endpoint string, ids csi.IdentityServer, cs csi.ControllerServer, ns csi.NodeServer)
|
|
// Waits for the service to stop
|
|
Wait()
|
|
// Stops the service gracefully
|
|
Stop()
|
|
// Stops the service forcefully
|
|
ForceStop()
|
|
}
|
|
|
|
func NewNonBlockingGRPCServer() NonBlockingGRPCServer {
|
|
return &nonBlockingGRPCServer{}
|
|
}
|
|
|
|
// NonBlocking server
|
|
type nonBlockingGRPCServer struct {
|
|
wg sync.WaitGroup
|
|
server *grpc.Server
|
|
}
|
|
|
|
func (s *nonBlockingGRPCServer) Start(endpoint string, ids csi.IdentityServer, cs csi.ControllerServer, ns csi.NodeServer) {
|
|
s.wg.Add(1)
|
|
|
|
go func() {
|
|
defer s.wg.Done()
|
|
s.serve(endpoint, ids, cs, ns)
|
|
}()
|
|
}
|
|
|
|
func (s *nonBlockingGRPCServer) Wait() {
|
|
s.wg.Wait()
|
|
}
|
|
|
|
func (s *nonBlockingGRPCServer) Stop() {
|
|
s.server.GracefulStop()
|
|
}
|
|
|
|
func (s *nonBlockingGRPCServer) ForceStop() {
|
|
s.server.Stop()
|
|
}
|
|
|
|
func (s *nonBlockingGRPCServer) serve(endpoint string, ids csi.IdentityServer, cs csi.ControllerServer, ns csi.NodeServer) {
|
|
|
|
proto, addr, err := ParseEndpoint(endpoint)
|
|
if err != nil {
|
|
glog.Fatal(err.Error())
|
|
}
|
|
|
|
if proto == "unix" {
|
|
addr = "/" + addr
|
|
if err := os.Remove(addr); err != nil && !os.IsNotExist(err) {
|
|
glog.Fatalf("Failed to remove %s, error: %s", addr, err.Error())
|
|
}
|
|
}
|
|
|
|
listener, err := net.Listen(proto, addr)
|
|
if err != nil {
|
|
glog.Fatalf("Failed to listen: %v", err)
|
|
}
|
|
|
|
opts := []grpc.ServerOption{
|
|
grpc.UnaryInterceptor(logGRPC),
|
|
}
|
|
server := grpc.NewServer(opts...)
|
|
s.server = server
|
|
|
|
if ids != nil {
|
|
csi.RegisterIdentityServer(server, ids)
|
|
}
|
|
if cs != nil {
|
|
csi.RegisterControllerServer(server, cs)
|
|
}
|
|
if ns != nil {
|
|
csi.RegisterNodeServer(server, ns)
|
|
}
|
|
|
|
glog.Infof("Listening for connections on address: %#v", listener.Addr())
|
|
|
|
server.Serve(listener)
|
|
}
|