Skip to content

Commit 06ead76

Browse files
authored
Merge pull request #784 from cvvz/support-blobfuse2
feat: support blobfuse2 on Ubuntu 22.04 node
2 parents e37f947 + 7cb82b7 commit 06ead76

28 files changed

+3680
-6
lines changed

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ require (
3838
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.1.1
3939
github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/keyvault/armkeyvault v1.0.0
4040
github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v0.4.1
41+
github.com/go-ini/ini v1.67.0
42+
github.com/pkg/errors v0.9.1
4143
github.com/satori/go.uuid v1.2.0
4244
k8s.io/apiserver v0.25.2
4345
)
@@ -85,7 +87,6 @@ require (
8587
github.com/opencontainers/runc v1.0.2 // indirect
8688
github.com/opencontainers/selinux v1.8.2 // indirect
8789
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 // indirect
88-
github.com/pkg/errors v0.9.1 // indirect
8990
github.com/pmezard/go-difflib v1.0.0 // indirect
9091
github.com/prometheus/client_golang v1.12.1 // indirect
9192
github.com/prometheus/client_model v0.2.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm
239239
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
240240
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20191125211704-12ad95a8df72/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
241241
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20200222043503-6f7a984d4dc4/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
242+
github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A=
243+
github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
242244
github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
243245
github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
244246
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=

pkg/blobfuse-proxy/init.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ then
3131
cp /blobfuse-proxy/packages-microsoft-prod.deb /host/etc/
3232
$HOST_CMD dpkg -i /etc/packages-microsoft-prod.deb && \
3333
$HOST_CMD apt update && \
34-
$HOST_CMD apt-get install -y fuse blobfuse="${BLOBFUSE_VERSION}" && \
34+
$HOST_CMD apt-get install -y fuse blobfuse2 blobfuse="${BLOBFUSE_VERSION}" && \
3535
$HOST_CMD rm -f /etc/packages-microsoft-prod.deb
3636
fi
3737

pkg/blobfuse-proxy/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323

2424
"k8s.io/klog/v2"
2525

26-
server "sigs.k8s.io/blob-csi-driver/pkg/blobfuse-proxy/server"
26+
"sigs.k8s.io/blob-csi-driver/pkg/blobfuse-proxy/server"
2727
csicommon "sigs.k8s.io/blob-csi-driver/pkg/csi-common"
2828
)
2929

pkg/blobfuse-proxy/server/server.go

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,30 @@ import (
2727
"google.golang.org/grpc"
2828
"k8s.io/klog/v2"
2929
mount_azure_blob "sigs.k8s.io/blob-csi-driver/pkg/blobfuse-proxy/pb"
30+
"sigs.k8s.io/blob-csi-driver/pkg/util"
3031
)
3132

3233
var (
3334
mutex sync.Mutex
3435
)
3536

37+
type BlobfuseVersion int
38+
39+
const (
40+
BlobfuseV1 BlobfuseVersion = iota
41+
BlobfuseV2
42+
)
43+
3644
type MountServer struct {
45+
blobfuseVersion BlobfuseVersion
3746
mount_azure_blob.UnimplementedMountServiceServer
3847
}
3948

4049
// NewMountServer returns a new Mountserver
4150
func NewMountServiceServer() *MountServer {
42-
return &MountServer{}
51+
mountServer := &MountServer{}
52+
mountServer.blobfuseVersion = getBlobfuseVersion()
53+
return mountServer
4354
}
4455

4556
// MountAzureBlob mounts an azure blob container to given location
@@ -53,8 +64,15 @@ func (server *MountServer) MountAzureBlob(ctx context.Context,
5364
authEnv := req.GetAuthEnv()
5465
klog.V(2).Infof("received mount request: Mounting with args %v \n", args)
5566

67+
var cmd *exec.Cmd
5668
var result mount_azure_blob.MountAzureBlobResponse
57-
cmd := exec.Command("blobfuse", strings.Split(args, " ")...)
69+
switch server.blobfuseVersion {
70+
case BlobfuseV1:
71+
cmd = exec.Command("blobfuse", strings.Split(args, " ")...)
72+
case BlobfuseV2:
73+
args = "mount " + args
74+
cmd = exec.Command("blobfuse2", strings.Split(args, " ")...)
75+
}
5876

5977
cmd.Env = append(cmd.Env, authEnv...)
6078
output, err := cmd.CombinedOutput()
@@ -84,3 +102,17 @@ func RunGRPCServer(
84102
klog.V(2).Infof("Start GRPC server at %s, TLS = %t", listener.Addr().String(), enableTLS)
85103
return grpcServer.Serve(listener)
86104
}
105+
106+
func getBlobfuseVersion() BlobfuseVersion {
107+
osinfo, err := util.GetOSInfo("/etc/lsb-release")
108+
if err != nil {
109+
klog.Warningf("failed to get OS info: %v, default using blobfuse v1", err)
110+
return BlobfuseV1
111+
}
112+
113+
if osinfo.Distro == "Ubuntu" && osinfo.Version >= "22.04" {
114+
return BlobfuseV2
115+
}
116+
117+
return BlobfuseV1
118+
}

pkg/blobplugin/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ ARG ARCH=amd64
3434
RUN if [ "$ARCH" = "amd64" ] ; then \
3535
clean-install libcurl4-gnutls-dev && \
3636
wget -O /blobfuse-proxy/packages-microsoft-prod.deb https://packages.microsoft.com/config/ubuntu/18.04/packages-microsoft-prod.deb && \
37-
dpkg -i /blobfuse-proxy/packages-microsoft-prod.deb && apt update && apt install blobfuse fuse -y && apt remove wget -y; fi
37+
dpkg -i /blobfuse-proxy/packages-microsoft-prod.deb && apt update && apt install blobfuse blobfuse2 fuse -y && apt remove wget -y; fi
3838
LABEL maintainers="andyzhangx"
3939
LABEL description="Azure Blob Storage CSI driver"
4040

pkg/util/util.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import (
2121
"os"
2222
"strings"
2323
"sync"
24+
25+
"github.com/go-ini/ini"
26+
"github.com/pkg/errors"
27+
"k8s.io/klog/v2"
2428
)
2529

2630
const (
@@ -155,3 +159,27 @@ func ConvertTagsToMap(tags string) (map[string]string, error) {
155159
}
156160
return m, nil
157161
}
162+
163+
type OsInfo struct {
164+
Distro string
165+
Version string
166+
}
167+
168+
const (
169+
keyDistribID = "DISTRIB_ID"
170+
keyDistribRelease = "DISTRIB_RELEASE"
171+
)
172+
173+
func GetOSInfo(f interface{}) (*OsInfo, error) {
174+
cfg, err := ini.Load(f)
175+
if err != nil {
176+
return nil, errors.Wrapf(err, "failed to read %q", f)
177+
}
178+
179+
oi := &OsInfo{}
180+
oi.Distro = cfg.Section("").Key(keyDistribID).String()
181+
oi.Version = cfg.Section("").Key(keyDistribRelease).String()
182+
183+
klog.V(2).Infof("get OS info: %v", oi)
184+
return oi, nil
185+
}

pkg/util/util_test.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package util
1919
import (
2020
"fmt"
2121
"os"
22+
"reflect"
2223
"testing"
2324
"time"
2425

@@ -248,3 +249,47 @@ func TestConvertTagsToMap2(t *testing.T) {
248249
assert.Equal(t, result, test.expected)
249250
}
250251
}
252+
253+
func TestGetOSInfo(t *testing.T) {
254+
type args struct {
255+
f interface{}
256+
}
257+
tests := []struct {
258+
name string
259+
args args
260+
want *OsInfo
261+
wantErr bool
262+
}{
263+
{
264+
name: "file not exist",
265+
args: args{
266+
f: "/not-exist/not-exist",
267+
},
268+
want: nil,
269+
wantErr: true,
270+
},
271+
{
272+
name: "parse os info correctly",
273+
args: args{
274+
f: []byte("DISTRIB_ID=Ubuntu\nDISTRIB_RELEASE=22.04"),
275+
},
276+
want: &OsInfo{
277+
Distro: "Ubuntu",
278+
Version: "22.04",
279+
},
280+
wantErr: false,
281+
},
282+
}
283+
for _, tt := range tests {
284+
t.Run(tt.name, func(t *testing.T) {
285+
got, err := GetOSInfo(tt.args.f)
286+
if (err != nil) != tt.wantErr {
287+
t.Errorf("GetOSInfo() error = %v, wantErr %v", err, tt.wantErr)
288+
return
289+
}
290+
if !reflect.DeepEqual(got, tt.want) {
291+
t.Errorf("GetOSInfo() = %v, want %v", got, tt.want)
292+
}
293+
})
294+
}
295+
}

test/e2e/testsuites/pre_provisioned_provided_credentials_tester.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ func (t *PreProvisionedProvidedCredentiasTest) Run(client clientset.Interface, n
8080

8181
// test for storage account SAS token
8282
ginkgo.By("Run for storage account SAS token")
83+
pod.Volumes[n].Attrib = map[string]string{
84+
"azurestorageauthtype": "SAS",
85+
}
8386
sasToken := GenerateSASToken(accountName, accountKey)
8487
secretData = map[string]string{
8588
"azurestorageaccountname": accountName,

test/e2e/testsuites/pre_provisioned_sastoken_tester.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ func (t *PreProvisionedSASTokenTest) Run(client clientset.Interface, namespace *
7171
pod.Volumes[n].Attrib["storageAccountName"] = accountName
7272
pod.Volumes[n].Attrib["keyVaultURL"] = *vault.Properties.VaultURI
7373
pod.Volumes[n].Attrib["keyVaultSecretName"] = *accountSASSecret.Name
74+
pod.Volumes[n].Attrib["azurestorageauthtype"] = "SAS"
7475

7576
tpod, cleanup := pod.SetupWithPreProvisionedVolumes(client, namespace, t.CSIDriver)
7677
// defer must be called here for resources not get removed before using them

0 commit comments

Comments
 (0)