• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

kubernetes-sigs / blob-csi-driver / 4961304539

12 May 2023 05:20PM UTC coverage: 80.672%. First build
4961304539

push

github

GitHub
chore(deps): bump golang.org/x/net from 0.9.0 to 0.10.0

1824 of 2261 relevant lines covered (80.67%)

5.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

71.93
/pkg/csi-common/server.go
1
/*
2
Copyright 2017 The Kubernetes Authors.
3

4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7

8
    http://www.apache.org/licenses/LICENSE-2.0
9

10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
*/
16

17
package csicommon
18

19
import (
20
        "net"
21
        "os"
22
        "sync"
23
        "time"
24

25
        "google.golang.org/grpc"
26
        "k8s.io/klog/v2"
27

28
        "github.com/container-storage-interface/spec/lib/go/csi"
29
)
30

31
// Defines Non blocking GRPC server interfaces
32
type NonBlockingGRPCServer interface {
33
        // Start services at the endpoint
34
        Start(endpoint string, ids csi.IdentityServer, cs csi.ControllerServer, ns csi.NodeServer, testMode bool)
35
        // Waits for the service to stop
36
        Wait()
37
        // Stops the service gracefully
38
        Stop()
39
        // Stops the service forcefully
40
        ForceStop()
41
}
42

43
func NewNonBlockingGRPCServer() NonBlockingGRPCServer {
2✔
44
        return &nonBlockingGRPCServer{}
2✔
45
}
2✔
46

47
// NonBlocking server
48
type nonBlockingGRPCServer struct {
49
        wg     sync.WaitGroup
50
        server *grpc.Server
51
}
52

53
func (s *nonBlockingGRPCServer) Start(endpoint string, ids csi.IdentityServer, cs csi.ControllerServer, ns csi.NodeServer, testMode bool) {
1✔
54
        s.wg.Add(1)
1✔
55
        go s.serve(endpoint, ids, cs, ns, testMode)
1✔
56
}
1✔
57

58
func (s *nonBlockingGRPCServer) Wait() {
1✔
59
        s.wg.Wait()
1✔
60
}
1✔
61

62
func (s *nonBlockingGRPCServer) Stop() {
1✔
63
        s.server.GracefulStop()
1✔
64
}
1✔
65

66
func (s *nonBlockingGRPCServer) ForceStop() {
1✔
67
        s.server.Stop()
1✔
68
}
1✔
69

70
func (s *nonBlockingGRPCServer) serve(endpoint string, ids csi.IdentityServer, cs csi.ControllerServer, ns csi.NodeServer, testMode bool) {
2✔
71
        proto, addr, err := ParseEndpoint(endpoint)
2✔
72
        if err != nil {
2✔
73
                klog.Fatal(err.Error())
×
74
        }
×
75

76
        if proto == "unix" {
2✔
77
                addr = "/" + addr
×
78
                if err := os.Remove(addr); err != nil && !os.IsNotExist(err) {
×
79
                        klog.Fatalf("Failed to remove %s, error: %s", addr, err.Error())
×
80
                }
×
81
        }
82

83
        listener, err := net.Listen(proto, addr)
2✔
84
        if err != nil {
2✔
85
                klog.Fatalf("Failed to listen: %v", err)
×
86
        }
×
87

88
        opts := []grpc.ServerOption{
2✔
89
                grpc.UnaryInterceptor(logGRPC),
2✔
90
        }
2✔
91
        server := grpc.NewServer(opts...)
2✔
92
        s.server = server
2✔
93

2✔
94
        if ids != nil {
2✔
95
                csi.RegisterIdentityServer(server, ids)
×
96
        }
×
97
        if cs != nil {
2✔
98
                csi.RegisterControllerServer(server, cs)
×
99
        }
×
100
        if ns != nil {
2✔
101
                csi.RegisterNodeServer(server, ns)
×
102
        }
×
103

104
        // Used to stop the server while running tests
105
        if testMode {
4✔
106
                s.wg.Done()
2✔
107
                go func() {
4✔
108
                        // make sure Serve() is called
2✔
109
                        s.wg.Wait()
2✔
110
                        time.Sleep(time.Millisecond * 1000)
2✔
111
                        s.server.GracefulStop()
2✔
112
                }()
2✔
113
        }
114
        klog.Infof("Listening for connections on address: %#v", listener.Addr())
2✔
115
        if err := server.Serve(listener); err != nil {
2✔
116
                klog.Errorf("Listening for connections on address: %#v, error: %v", listener.Addr(), err)
×
117
        }
×
118
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc