Skip to content

Commit 3fc0055

Browse files
committed
add mountpoint mounter
Signed-off-by: Alexander <[email protected]>
1 parent de5e8b3 commit 3fc0055

File tree

4 files changed

+173
-4
lines changed

4 files changed

+173
-4
lines changed

Dockerfile

+38-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,44 @@
1-
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.6-941 as s3fs-builder
1+
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.6-941 as mountpoint-builder
22

33
ARG RHSM_PASS=blank
44
ARG RHSM_USER=blank
55

66
ENV RHSM_PASS "${RHSM_PASS}"
77
ENV RHSM_USER "${RHSM_USER}"
88

9+
ADD register-sys.sh /usr/bin/
10+
RUN microdnf update --setopt=tsflags=nodocs && \
11+
microdnf install -y --nodocs hostname subscription-manager
12+
RUN hostname; chmod 755 /usr/bin/register-sys.sh && /usr/bin/register-sys.sh
13+
# Install build tools
14+
RUN microdnf update --setopt=tsflags=nodocs && \
15+
microdnf install -y --nodocs \
16+
fuse \
17+
fuse-devel \
18+
cmake3 \
19+
clang \
20+
git \
21+
pkgconf && \
22+
microdnf clean all
23+
24+
# Install rust
25+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \
26+
source "$HOME/.cargo/env"
27+
28+
# Build mountpoint-s3
29+
RUN git clone --recurse-submodules https://github.com/awslabs/mountpoint-s3.git && \
30+
source "$HOME/.cargo/env" && \
31+
cd mountpoint-s3 && \
32+
cargo build --release
33+
34+
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.6-941 as s3fs-builder
35+
36+
ARG RHSM_PASS="[email protected]"
37+
ARG RHSM_USER="bonbon14011401!!"
38+
39+
ENV RHSM_PASS "${RHSM_PASS}"
40+
ENV RHSM_USER "${RHSM_USER}"
41+
942
ADD register-sys.sh /usr/bin/
1043
RUN microdnf update --setopt=tsflags=nodocs && \
1144
microdnf install -y --nodocs hostname subscription-manager
@@ -35,9 +68,9 @@ ENV GO_VERSION=1.19
3568
RUN echo $ARCH $GO_VERSION
3669

3770
RUN wget -q https://dl.google.com/go/go$GO_VERSION.linux-$ARCH.tar.gz && \
38-
tar -xf go$GO_VERSION.linux-$ARCH.tar.gz && \
39-
rm go$GO_VERSION.linux-$ARCH.tar.gz && \
40-
mv go /usr/local
71+
tar -xf go$GO_VERSION.linux-$ARCH.tar.gz && \
72+
rm go$GO_VERSION.linux-$ARCH.tar.gz && \
73+
mv go /usr/local
4174

4275
ENV GOROOT /usr/local/go
4376
ENV GOPATH /go
@@ -61,6 +94,7 @@ LABEL description="IBM CSI Object Storage Plugin"
6194
LABEL build-date=${build_date}
6295
LABEL git-commit-id=${git_commit_id}
6396
RUN yum update -y && yum install fuse fuse-libs fuse3 fuse3-libs -y
97+
COPY --from=mountpoint-builder /mountpoint-s3/target/release/mount-s3 /usr/bin/mount-s3
6498
COPY --from=s3fs-builder /usr/local/bin/s3fs /usr/bin/s3fs
6599
COPY --from=rclone-builder /usr/local/bin/rclone /usr/bin/rclone
66100
COPY ibm-object-csi-driver ibm-object-csi-driver

pkg/constants/constants.go

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const (
88

99
S3FS = "s3fs"
1010
RClone = "rclone"
11+
MNTS3 = "mountpoint"
1112

1213
IAMEP = "https://private.iam.cloud.ibm.com/identity/token"
1314
ResourceConfigEPPrivate = "https://config.private.cloud-object-storage.cloud.ibm.com/v1"

pkg/mounter/mounter-mountpoint.go

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/*******************************************************************************
2+
* IBM Confidential
3+
* OCO Source Materials
4+
* IBM Cloud Kubernetes Service, 5737-D43
5+
* (C) Copyright IBM Corp. 2023 All Rights Reserved.
6+
* The source code for this program is not published or otherwise divested of
7+
* its trade secrets, irrespective of what has been deposited with
8+
* the U.S. Copyright Office.
9+
******************************************************************************/
10+
11+
// Package mounter
12+
package mounter
13+
14+
import (
15+
"crypto/sha256"
16+
"fmt"
17+
"os"
18+
"path"
19+
20+
// "github.com/IBM/ibm-object-csi-driver/pkg/constants"
21+
"github.com/IBM/ibm-object-csi-driver/pkg/mounter/utils"
22+
"k8s.io/klog/v2"
23+
)
24+
25+
// Mounter interface defined in mounter.go
26+
// mntS3Mounter Implements Mounter
27+
type mntS3Mounter struct {
28+
bucketName string //From Secret in SC
29+
objPath string //From Secret in SC
30+
endPoint string //From Secret in SC
31+
locConstraint string //From Secret in SC
32+
authType string
33+
accessKey string
34+
secretKey string
35+
mountOptions []string
36+
MounterUtils utils.MounterUtils
37+
}
38+
39+
func NewMntS3Mounter(secretMap map[string]string, mountOptions []string, mounterUtils utils.MounterUtils) Mounter {
40+
klog.Info("-newMntS3Mounter-")
41+
42+
var (
43+
val string
44+
check bool
45+
mounter *mntS3Mounter
46+
)
47+
48+
mounter = &mntS3Mounter{}
49+
50+
if val, check = secretMap["cosEndpoint"]; check {
51+
mounter.endPoint = val
52+
}
53+
if val, check = secretMap["locationConstraint"]; check {
54+
mounter.locConstraint = val
55+
}
56+
if val, check = secretMap["bucketName"]; check {
57+
mounter.bucketName = val
58+
}
59+
if val, check = secretMap["objPath"]; check {
60+
mounter.objPath = val
61+
}
62+
if val, check = secretMap["accessKey"]; check {
63+
mounter.accessKey = val
64+
}
65+
if val, check = secretMap["secretKey"]; check {
66+
mounter.secretKey = val
67+
}
68+
69+
klog.Infof("newMntS3Mounter args:\n\tbucketName: [%s]\n\tobjPath: [%s]\n\tendPoint: [%s]\n\tlocationConstraint: [%s]\n\tauthType: [%s]",
70+
mounter.bucketName, mounter.objPath, mounter.endPoint, mounter.locConstraint, mounter.authType)
71+
72+
mounter.mountOptions = mountOptions
73+
mounter.MounterUtils = mounterUtils
74+
75+
return mounter
76+
}
77+
78+
const (
79+
mntS3Cmd = "mount-s3"
80+
metaRootMntS3 = "/var/lib/ibmc-mntS3"
81+
)
82+
83+
func (mntS3 *mntS3Mounter) Stage(stagePath string) error {
84+
return nil
85+
}
86+
func (mntS3 *mntS3Mounter) Unstage(stagePath string) error {
87+
return nil
88+
}
89+
func (mntS3 *mntS3Mounter) Mount(source string, target string) error {
90+
klog.Info("-MntS3Mounter Mount-")
91+
klog.Infof("Mount args:\n\tsource: <%s>\n\ttarget: <%s>", source, target)
92+
var pathExist bool
93+
var err error
94+
metaPath := path.Join(metaRootMntS3, fmt.Sprintf("%x", sha256.Sum256([]byte(target))))
95+
96+
if pathExist, err = checkPath(metaPath); err != nil {
97+
klog.Errorf("MntS3Mounter Mount: Cannot stat directory %s: %v", metaPath, err)
98+
return err
99+
}
100+
101+
if !pathExist {
102+
if err = os.MkdirAll(metaPath, 0755); // #nosec G301: used for mntS3
103+
err != nil {
104+
klog.Errorf("MntS3Mounter Mount: Cannot create directory %s: %v", metaPath, err)
105+
return err
106+
}
107+
}
108+
109+
os.Setenv("AWS_ACCESS_KEY_ID", mntS3.accessKey)
110+
os.Setenv("AWS_SECRET_ACCESS_KEY", mntS3.secretKey)
111+
112+
args := []string{
113+
fmt.Sprintf("--endpoint-url=%v", mntS3.endPoint),
114+
mntS3.bucketName,
115+
target,
116+
}
117+
118+
if mntS3.objPath != "" {
119+
args = append(args, fmt.Sprintf("--prefix %s", mntS3.objPath))
120+
}
121+
return mntS3.MounterUtils.FuseMount(target, mntS3Cmd, args)
122+
}
123+
func (mntS3 *mntS3Mounter) Unmount(target string) error {
124+
klog.Info("-MntS3Mounter Unmount-")
125+
metaPath := path.Join(metaRootMntS3, fmt.Sprintf("%x", sha256.Sum256([]byte(target))))
126+
err := os.RemoveAll(metaPath)
127+
if err != nil {
128+
return err
129+
}
130+
131+
return mntS3.MounterUtils.FuseUnmount(target)
132+
}

pkg/mounter/mounter.go

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ func (s *CSIMounterFactory) NewMounter(attrib map[string]string, secretMap map[s
4747
return NewS3fsMounter(secretMap, mountFlags, mounterUtils)
4848
case constants.RClone:
4949
return NewRcloneMounter(secretMap, mountFlags, mounterUtils)
50+
case constants.MNTS3:
51+
return NewMntS3Mounter(secretMap, mountFlags, mounterUtils)
5052
default:
5153
// default to s3fs
5254
return NewS3fsMounter(secretMap, mountFlags, mounterUtils)

0 commit comments

Comments
 (0)