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

kubernetes-sigs / blob-csi-driver / 14642486131

24 Apr 2025 01:10PM UTC coverage: 78.052% (-0.03%) from 78.078%
14642486131

Pull #1964

github

andyzhangx
fix: incorrect metris log in NodeStageVolume
Pull Request #1964: fix: incorrect metris log in NodeStageVolume

0 of 1 new or added line in 1 file covered. (0.0%)

1 existing line in 1 file now uncovered.

2340 of 2998 relevant lines covered (78.05%)

7.56 hits per line

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

58.23
/pkg/blobfuse-proxy/server/server.go
1
/*
2
Copyright 2021 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 server
18

19
import (
20
        "context"
21
        "fmt"
22
        "net"
23
        "os"
24
        "os/exec"
25
        "strings"
26
        "sync"
27

28
        grpcprom "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus"
29
        "google.golang.org/grpc"
30
        "k8s.io/klog/v2"
31
        "sigs.k8s.io/blob-csi-driver/pkg/blob"
32
        mount_azure_blob "sigs.k8s.io/blob-csi-driver/pkg/blobfuse-proxy/pb"
33
        "sigs.k8s.io/blob-csi-driver/pkg/util"
34
)
35

36
var (
37
        mutex sync.Mutex
38
)
39

40
type BlobfuseVersion int
41

42
const (
43
        BlobfuseV1 BlobfuseVersion = iota
44
        BlobfuseV2
45
)
46

47
type MountServer struct {
48
        blobfuseVersion BlobfuseVersion
49
        mount_azure_blob.UnimplementedMountServiceServer
50
}
51

52
// NewMountServer returns a new Mountserver
53
func NewMountServiceServer() *MountServer {
1✔
54
        mountServer := &MountServer{}
1✔
55
        mountServer.blobfuseVersion = getBlobfuseVersion()
1✔
56
        return mountServer
1✔
57
}
1✔
58

59
// MountAzureBlob mounts an azure blob container to given location
60
func (server *MountServer) MountAzureBlob(_ context.Context,
61
        req *mount_azure_blob.MountAzureBlobRequest,
62
) (resp *mount_azure_blob.MountAzureBlobResponse, err error) {
1✔
63
        mutex.Lock()
1✔
64
        defer mutex.Unlock()
1✔
65

1✔
66
        args := req.GetMountArgs()
1✔
67
        authEnv := req.GetAuthEnv()
1✔
68
        protocol := req.GetProtocol()
1✔
69
        klog.V(2).Infof("received mount request: protocol: %s, server default blobfuseVersion: %v, mount args %v \n", protocol, server.blobfuseVersion, args)
1✔
70

1✔
71
        var cmd *exec.Cmd
1✔
72
        var result mount_azure_blob.MountAzureBlobResponse
1✔
73
        if protocol == blob.Fuse2 || server.blobfuseVersion == BlobfuseV2 {
2✔
74
                args = "mount " + args
1✔
75
                // add this arg for blobfuse2 to solve the issue:
1✔
76
                // https://github.com/Azure/azure-storage-fuse/issues/1015
1✔
77
                if !strings.Contains(args, "--ignore-open-flags") {
2✔
78
                        klog.V(2).Infof("append --ignore-open-flags=true to mount args")
1✔
79
                        args = args + " " + "--ignore-open-flags=true"
1✔
80
                }
1✔
81
                args = util.TrimDuplicatedSpace(args)
1✔
82
                klog.V(2).Infof("mount with v2, protocol: %s, args: %s", protocol, args)
1✔
83
                cmd = exec.Command("blobfuse2", strings.Split(args, " ")...)
1✔
84
        } else {
×
85
                args = util.TrimDuplicatedSpace(args)
×
86
                klog.V(2).Infof("mount with v1, protocol: %s, args: %s", protocol, args)
×
87
                cmd = exec.Command("blobfuse", strings.Split(args, " ")...)
×
88
        }
×
89

90
        cmd.Env = append(os.Environ(), authEnv...)
1✔
91
        output, err := cmd.CombinedOutput()
1✔
92
        if err != nil {
2✔
93
                klog.Error("blobfuse mount failed: with error:", err.Error())
1✔
94
        } else {
1✔
95
                klog.V(2).Infof("successfully mounted")
×
96
        }
×
97
        result.Output = string(output)
1✔
98
        klog.V(2).Infof("blobfuse output: %s\n", result.Output)
1✔
99
        if err != nil {
2✔
100
                return &result, fmt.Errorf("%w %s", err, result.Output)
1✔
101
        }
1✔
102
        return &result, nil
×
103
}
104

105
func RunGRPCServer(
106
        mountServer mount_azure_blob.MountServiceServer,
107
        enableTLS bool,
108
        listener net.Listener,
109
) error {
×
110
        serverOptions := []grpc.ServerOption{
×
111
                grpc.ChainUnaryInterceptor(
×
112
                        grpcprom.NewServerMetrics().UnaryServerInterceptor(),
×
113
                ),
×
114
        }
×
115

×
116
        grpcServer := grpc.NewServer(serverOptions...)
×
117

×
118
        mount_azure_blob.RegisterMountServiceServer(grpcServer, mountServer)
×
119

×
120
        klog.V(2).Infof("Start GRPC server at %s, TLS = %t", listener.Addr().String(), enableTLS)
×
121
        return grpcServer.Serve(listener)
×
122
}
×
123

124
func getBlobfuseVersion() BlobfuseVersion {
1✔
125
        osinfo, err := util.GetOSInfo("/etc/os-release")
1✔
126
        if err != nil {
1✔
127
                klog.Warningf("failed to get OS info: %v, default using blobfuse v1", err)
×
128
                return BlobfuseV1
×
129
        }
×
130

131
        if (strings.EqualFold(osinfo.Distro, "mariner") || strings.EqualFold(osinfo.Distro, "azurelinux")) && osinfo.Version >= "2.0" {
1✔
132
                klog.V(2).Info("proxy default using blobfuse V2 for mounting on azurelinux(mariner) 2.0+")
×
133
                return BlobfuseV2
×
134
        }
×
135

136
        if strings.EqualFold(osinfo.Distro, "rhcos") {
1✔
137
                klog.V(2).Info("proxy default using blobfuse V2 for mounting on RHCOS")
×
138
                return BlobfuseV2
×
139
        }
×
140

141
        if strings.EqualFold(osinfo.Distro, "ubuntu") && osinfo.Version >= "22.04" {
2✔
142
                klog.V(2).Info("proxy default using blobfuse V2 for mounting on Ubuntu 22.04+")
1✔
143
                return BlobfuseV2
1✔
144
        }
1✔
145

146
        klog.V(2).Info("proxy default using blobfuse V1 for mounting")
×
147
        return BlobfuseV1
×
148
}
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