Skip to content

Commit 48b456b

Browse files
committed
feat(obs): change parallelized file system to obs Bucket
1 parent b082aad commit 48b456b

File tree

13 files changed

+227
-154
lines changed

13 files changed

+227
-154
lines changed

cluster/images/obs-csi-plugin/Dockerfile

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@ LABEL description="HuaweiCloud CSI Plugin"
55

66
WORKDIR /obs-csi
77

8-
COPY obsfs_CentOS7.6_amd64.tar.gz ./
9-
COPY obsfs_Ubuntu16.04_amd64.tar.gz ./
108
COPY entrypoint.sh entrypoint.sh
119
COPY nsenter /nsenter
1210
COPY csi-connector-server ./
1311
COPY csi-connector.service ./
1412
COPY obs-csi-plugin obs-csi-plugin
15-
COPY install_obsfs.sh ./
13+
COPY install_s3fs.sh ./
1614
COPY stop-server.sh ./
17-
COPY huaweicloud-obs-obsfs.tar.gz ./
1815

1916
RUN chmod +x obs-csi-plugin
2017
RUN chmod +x entrypoint.sh

cluster/images/obs-csi-plugin/csi-connector-server.go

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const (
2525
region = "region"
2626
cloud = "cloud"
2727
credential = "credential"
28-
defaultOpts = "-o big_writes -o max_write=131072 -o use_ino"
28+
defaultOpts = "-o nonempty -o big_writes -o max_write=131072"
2929
)
3030

3131
type ResponseBody struct {
@@ -119,7 +119,7 @@ func main() {
119119
//nolint:errcheck
120120
flag.CommandLine.Parse([]string{})
121121

122-
initObsfsUtil()
122+
initS3fsUtil()
123123
if checkFileExists(obs.SocketPath) {
124124
if err := os.Remove(obs.SocketPath); err != nil {
125125
log.Fatalf("Failed to remove path: %s, err: %v", obs.SocketPath, err)
@@ -153,26 +153,27 @@ func mountHandler(parameters map[string]string) error {
153153
if parameters[cloud] == "prod-cloud-ocb.orange-business.com" {
154154
obsName = "oss"
155155
}
156-
157156
mountOpts := parameters[mountFlags]
158157
if mountOpts == "" {
159158
mountOpts = defaultOpts
160159
}
160+
161161
options := []string{
162-
"obsfs",
163162
parameters[bucketName],
164163
parameters[targetPath],
165-
fmt.Sprintf("-o url=%s.%s.%s", obsName, parameters[region], parameters[cloud]),
166-
fmt.Sprintf("-o passwd_file=%s", credentialFile),
167-
mountOpts,
164+
"-o",
165+
fmt.Sprintf("url=https://%s.%s.%s", obsName, parameters[region], parameters[cloud]),
166+
"-o",
167+
fmt.Sprintf("passwd_file=%s", credentialFile),
168168
}
169+
mntOptsArr := strings.Split(mountOpts, " ")
170+
options = append(options, mntOptsArr...)
169171

170-
cmd := exec.Command("sh", "-c")
171-
cmd.Args = append(cmd.Args, strings.Join(options, " "))
172+
cmd := exec.Command("s3fs", options...)
172173
out, err := cmd.CombinedOutput()
173174
if err != nil {
174-
log.Errorf("failed to mount CMD: obsfs %s, output: %s, error: %v", strings.Join(options, " "), string(out), err)
175-
return fmt.Errorf("failed to mount CMD: obsfs %s, output: %s, error: %v", strings.Join(options, " "), string(out), err)
175+
log.Errorf("failed to mount bucket to node, CMD: s3fs %s, output: %s, error: %v", strings.Join(options, " "), string(out), err)
176+
return fmt.Errorf("failed to mount bucket to node, CMD: s3fs %s, output: %s, error: %v", strings.Join(options, " "), string(out), err)
176177
}
177178
log.Infof("success to mount CMD: %s", strings.Join(options, " "))
178179
return nil
@@ -186,11 +187,11 @@ func deleteCredential(credential string) {
186187
}
187188
}
188189

189-
func initObsfsUtil() {
190-
cmd := fmt.Sprintf("sh %s/install_obsfs.sh >> %s/connector.log 2>&1 &", credentialDir, credentialDir)
190+
func initS3fsUtil() {
191+
cmd := fmt.Sprintf("sh %s/install_s3fs.sh > %s/connector.log 2>&1 &", credentialDir, credentialDir)
191192
out, err := exec.Command("sh", "-c", cmd).CombinedOutput()
192-
log.Infof("install obsfs %s", string(out))
193+
log.Infof("install s3fs %s", string(out))
193194
if err != nil {
194-
log.Errorf("error install obsfs: %s", err)
195+
log.Errorf("error install s3fs: %s", err)
195196
}
196197
}

cluster/images/obs-csi-plugin/entrypoint.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@
33
HOST_CMD="/nsenter --mount=/proc/1/ns/mnt"
44
mkdir -p /var/lib/csi/
55

6-
cp -f /obs-csi/huaweicloud-obs-obsfs.tar.gz /var/lib/csi/huaweicloud-obs-obsfs.tar.gz
7-
cp -f /obs-csi/obsfs_CentOS7.6_amd64.tar.gz /var/lib/csi/obsfs_CentOS7.6_amd64.tar.gz
8-
cp -f /obs-csi/obsfs_Ubuntu16.04_amd64.tar.gz /var/lib/csi/obsfs_Ubuntu16.04_amd64.tar.gz
9-
cp -f /obs-csi/install_obsfs.sh /var/lib/csi/install_obsfs.sh
6+
cp -f /obs-csi/install_s3fs.sh /var/lib/csi/install_s3fs.sh
107

118
echo "Starting install obs csi-connector-server...."
129
$HOST_CMD systemctl stop csi-connector.service
-1.13 MB
Binary file not shown.

cluster/images/obs-csi-plugin/install_obsfs.sh

Lines changed: 0 additions & 96 deletions
This file was deleted.
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#!/bin/bash
2+
3+
packageCmd=("yum" "dnf" "apt")
4+
5+
checkS3fsInstalled() {
6+
echo "[INFO] Check version and check if it works"
7+
isInstalled=1
8+
command -v s3fs >/dev/null 2>&1 || { isInstalled=0; }
9+
if [ ${isInstalled} = 0 ]; then
10+
echo "[WARN] has no command named s3fs"
11+
return ${isInstalled}
12+
fi
13+
echo "[INFO] s3fs has been installed"
14+
return ${isInstalled}
15+
}
16+
17+
checkLinuxOS() {
18+
if grep -i -q "EulerOS" /etc/os-release; then
19+
# EulerOS
20+
return 5
21+
elif [ -f "/etc/redhat-release" ]; then
22+
# CentOS or RHEL or EulerOS
23+
if grep -i -q "CentOS" /etc/redhat-release; then
24+
return 1
25+
elif grep -i -q "Fedora" /etc/redhat-release; then
26+
return 4
27+
elif grep -i -q "EulerOS" /etc/redhat-release; then
28+
return 5
29+
fi
30+
elif [ -f "/etc/issue" ]; then
31+
# Ubuntu or Debian or Euler
32+
if grep -i -q "ubuntu" /etc/issue; then
33+
return 2
34+
elif grep -i -q "debian" /etc/issue; then
35+
return 3
36+
elif grep -i -q "Euler" /etc/os-release; then
37+
return 5
38+
fi
39+
elif [ -f "/etc/fedora-release" ]; then
40+
# Fedora
41+
if grep -i -q "Fedora" /etc/fedora-release; then
42+
return 4
43+
fi
44+
else
45+
# unknown OS
46+
return 0
47+
fi
48+
}
49+
50+
installS3fs() {
51+
echo "[INFO] Install dependencies and s3fs"
52+
pgkManageCmd=${1}
53+
54+
if which yum >/dev/null 2>&1 && [ ${pgkManageCmd} = "yum" ]; then
55+
echo "[INFO] command 'yum' is available, trying to install s3fs with yum"
56+
sudo yum -y install epel-release
57+
sudo yum -y install s3fs-fuse
58+
return
59+
elif which apt >/dev/null 2>&1 && [ ${pgkManageCmd} = "apt" ]; then
60+
echo "[INFO] command 'apt' is available, trying to install s3fs with apt"
61+
sudo apt -y install s3fs
62+
return
63+
elif which dnf >/dev/null 2>&1 && [ ${pgkManageCmd} = "dnf" ]; then
64+
echo "[INFO] command 'dnf' is available, trying to install s3fs with dnf"
65+
sudo dnf -y install s3fs-fuse
66+
return
67+
else
68+
echo "[ERROR] unsupported systems, please install s3fs manually"
69+
fi
70+
}
71+
72+
# pre install
73+
checkS3fsInstalled
74+
isInstalled=$?
75+
if [ ${isInstalled} = 1 ]; then
76+
exit 1
77+
fi
78+
79+
# install
80+
checkLinuxOS
81+
osCode=$?
82+
echo "[INFO] OS Code is ${osCode}"
83+
84+
if [ ${osCode} = 1 ] || [ ${osCode} = 5 ]; then
85+
echo "[INFO] OS is CentOS or EulerOS, use yum to install s3fs"
86+
installS3fs "yum"
87+
elif [ ${osCode} = 2 ] || [ ${osCode} = 3 ]; then
88+
echo "[INFO] OS is Ubuntu or Debian, use apt to install s3fs"
89+
installS3fs "apt"
90+
elif [ ${osCode} = 4 ]; then
91+
echo "[INFO] OS is Fedora, use dnf to install s3fs"
92+
installS3fs "dnf"
93+
else
94+
echo "[WARN] Unknown OS, try to force installation of s3fs"
95+
for cmd in ${packageCmd[@]}; do
96+
installS3fs ${cmd}
97+
checkS3fsInstalled
98+
isInstalled=$?
99+
if [ ${isInstalled} = 1 ]; then
100+
exit 1
101+
fi
102+
done
103+
fi
104+
105+
# post install
106+
checkS3fsInstalled
107+
isInstalled=$?
108+
if [ ${isInstalled} = 1 ]; then
109+
exit 1
110+
fi
111+
echo "[ERROR] failed to install s3fs, please install s3fs manually"
-2.11 MB
Binary file not shown.
-2.27 MB
Binary file not shown.

pkg/obs/controllerserver.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func (cs *controllerServer) CreateVolume(_ context.Context, req *csi.CreateVolum
4343
return nil, err
4444
}
4545

46-
if volume, err := services.GetParallelFSBucket(credentials, volName); err != nil && status.Code(err) != codes.NotFound {
46+
if volume, err := services.GetObsBucket(credentials, volName); err != nil && status.Code(err) != codes.NotFound {
4747
return nil, err
4848
} else if volume != nil {
4949
log.Infof("Volume %s existence, skip creating", volName)
@@ -61,7 +61,7 @@ func (cs *controllerServer) CreateVolume(_ context.Context, req *csi.CreateVolum
6161
}
6262
}
6363

64-
volume, err := services.GetParallelFSBucket(credentials, volName)
64+
volume, err := services.GetObsBucket(credentials, volName)
6565
if err != nil {
6666
return nil, err
6767
}
@@ -80,7 +80,7 @@ func (cs *controllerServer) DeleteVolume(_ context.Context, req *csi.DeleteVolum
8080
}
8181

8282
credentials := cs.Driver.cloud
83-
volume, err := services.GetParallelFSBucket(credentials, volName)
83+
volume, err := services.GetObsBucket(credentials, volName)
8484
if err != nil {
8585
if common.IsNotFound(err) {
8686
log.Infof("Volume %s does not exist, skip deleting", volName)
@@ -115,7 +115,7 @@ func (cs *controllerServer) ControllerGetVolume(_ context.Context, req *csi.Cont
115115
return nil, status.Error(codes.InvalidArgument, "Validation failed, volume ID cannot be empty")
116116
}
117117

118-
bucket, err := services.GetParallelFSBucket(cs.Driver.cloud, volumeID)
118+
bucket, err := services.GetObsBucket(cs.Driver.cloud, volumeID)
119119
if err != nil {
120120
return nil, err
121121
}
@@ -216,7 +216,7 @@ func (cs *controllerServer) ValidateVolumeCapabilities(_ context.Context, req *c
216216
if len(volumeID) == 0 {
217217
return nil, status.Error(codes.InvalidArgument, "Validation failed, volume ID cannot be empty")
218218
}
219-
if _, err := services.GetParallelFSBucket(cs.Driver.cloud, volumeID); err != nil {
219+
if _, err := services.GetObsBucket(cs.Driver.cloud, volumeID); err != nil {
220220
return nil, err
221221
}
222222

@@ -263,7 +263,7 @@ func (cs *controllerServer) ControllerExpandVolume(_ context.Context, req *csi.C
263263
"Validation failed, after round-up volume size %v exceeds the max size %v", sizeBytes, maxSizeBytes)
264264
}
265265

266-
volume, err := services.GetParallelFSBucket(cc, volumeID)
266+
volume, err := services.GetObsBucket(cc, volumeID)
267267
if err != nil {
268268
return nil, err
269269
}

pkg/obs/mount.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ func sendCommand(cmd CommandRPC, mountClient http.Client) error {
2626
if err != nil {
2727
return err
2828
}
29-
log.Infof("Start sending command: %s", string(marshal))
3029
response, err := mountClient.Post("http://unix", "application/json", bytes.NewReader(marshal))
3130
if err != nil {
3231
return status.Errorf(codes.Internal, "Failed to post command, err: %v", err)
3332
}
3433
defer response.Body.Close()
3534
if response.StatusCode != http.StatusOK {
3635
respBody, err := ioutil.ReadAll(response.Body)
36+
log.Infof("start to mount bucket, cmd: %v", string(respBody))
3737
if err != nil {
3838
return status.Errorf(codes.Internal, "Failed to read responseBody, err: %v", err)
3939
}

0 commit comments

Comments
 (0)