-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathutils.go
More file actions
117 lines (99 loc) · 3.38 KB
/
utils.go
File metadata and controls
117 lines (99 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package blockstorage
import (
"context"
"fmt"
"strings"
"sync/atomic"
"github.com/stackitcloud/cloud-provider-stackit/pkg/csi/util/mount"
"github.com/stackitcloud/cloud-provider-stackit/pkg/stackit"
stackitconfig "github.com/stackitcloud/cloud-provider-stackit/pkg/stackit/config"
"github.com/stackitcloud/cloud-provider-stackit/pkg/stackit/metadata"
"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/kubernetes-csi/csi-lib-utils/protosanitizer"
"google.golang.org/grpc"
"k8s.io/klog/v2"
)
var serverGRPCEndpointCallCounter atomic.Uint64
func NewControllerServiceCapability(rpcType csi.ControllerServiceCapability_RPC_Type) *csi.ControllerServiceCapability {
return &csi.ControllerServiceCapability{
Type: &csi.ControllerServiceCapability_Rpc{
Rpc: &csi.ControllerServiceCapability_RPC{
Type: rpcType,
},
},
}
}
func NewNodeServiceCapability(rpcType csi.NodeServiceCapability_RPC_Type) *csi.NodeServiceCapability {
return &csi.NodeServiceCapability{
Type: &csi.NodeServiceCapability_Rpc{
Rpc: &csi.NodeServiceCapability_RPC{
Type: rpcType,
},
},
}
}
func NewVolumeCapabilityAccessMode(mode csi.VolumeCapability_AccessMode_Mode) *csi.VolumeCapability_AccessMode {
return &csi.VolumeCapability_AccessMode{Mode: mode}
}
//revive:disable:unexported-return
func NewControllerServer(d *Driver, instance stackit.IaasClient) *controllerServer {
return &controllerServer{
Driver: d,
Instance: instance,
}
}
func NewIdentityServer(d *Driver) *identityServer {
return &identityServer{
Driver: d,
}
}
func NewNodeServer(d *Driver, mountProvider mount.IMount, metadataProvider metadata.IMetadata, opts stackitconfig.BlockStorageOpts) *nodeServer { //nolint:lll // looks weird when shortened
return &nodeServer{
Driver: d,
Mount: mountProvider,
Metadata: metadataProvider,
Opts: opts,
}
}
//revive:enable:unexported-return
func RunServicesInitialized(endpoint string, ids csi.IdentityServer, cs csi.ControllerServer, ns csi.NodeServer) {
s := NewNonBlockingGRPCServer()
s.Start(endpoint, ids, cs, ns)
s.Wait()
}
func ParseEndpoint(ep string) (proto, addr string, err error) {
if strings.HasPrefix(strings.ToLower(ep), "unix://") || strings.HasPrefix(strings.ToLower(ep), "tcp://") {
s := strings.SplitN(ep, "://", 2)
if s[1] != "" {
return s[0], s[1], nil
}
}
return "", "", fmt.Errorf("invalid endpoint: %v", ep)
}
func DetermineMaxVolumesByFlavor(flavor string) int64 {
flavorParts := strings.Split(flavor, ".")
// The following numbers were specified by the IaaS team. They are based on actual tests.
switch {
case strings.HasPrefix(flavor, "n"):
// Flavors starting with 'n' are nvidia GPU flavors, all GPU VM's can only mount 10 volumes
return 10
case strings.HasSuffix(flavorParts[0], "2a"):
// AMD 2nd Gen
return 159
default:
// All other flavors can mount 28 volumes
return 25
}
}
func logGRPC(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (any, error) {
callID := serverGRPCEndpointCallCounter.Add(1)
klog.V(3).Infof("[ID:%d] GRPC call: %s", callID, info.FullMethod)
klog.V(5).Infof("[ID:%d] GRPC request: %s", callID, protosanitizer.StripSecrets(req))
resp, err := handler(ctx, req)
if err != nil {
klog.Errorf("[ID:%d] GRPC error: %v", callID, err)
} else {
klog.V(5).Infof("[ID:%d] GRPC response: %s", callID, protosanitizer.StripSecrets(resp))
}
return resp, err
}