Skip to content

add mountpoint mounter #139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: aws-s3mount
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,39 @@ ARG RHSM_USER=blank
ENV RHSM_PASS "${RHSM_PASS}"
ENV RHSM_USER "${RHSM_USER}"

ADD register-sys.sh /usr/bin/
RUN microdnf update --setopt=tsflags=nodocs && \
microdnf install -y --nodocs hostname subscription-manager
RUN hostname; chmod 755 /usr/bin/register-sys.sh && /usr/bin/register-sys.sh
# Install build tools
RUN microdnf update --setopt=tsflags=nodocs && \
microdnf install -y --nodocs \
fuse \
fuse-devel \
cmake3 \
clang \
git \
pkgconf && \
microdnf clean all

# Install rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y && \
source "$HOME/.cargo/env"

# Build mountpoint-s3
RUN git clone --recurse-submodules https://github.com/awslabs/mountpoint-s3.git && \
source "$HOME/.cargo/env" && \
cd mountpoint-s3 && \
cargo build --release

FROM registry.access.redhat.com/ubi8/ubi-minimal:8.6-941 as s3fs-builder

ARG RHSM_PASS="[email protected]"
ARG RHSM_USER="bonbon14011401!!"

ENV RHSM_PASS "${RHSM_PASS}"
ENV RHSM_USER "${RHSM_USER}"

ADD register-sys.sh /usr/bin/
RUN microdnf update --setopt=tsflags=nodocs && \
microdnf install -y --nodocs hostname subscription-manager
Expand Down Expand Up @@ -35,9 +68,9 @@ ENV GO_VERSION=1.24.1
RUN echo $ARCH $GO_VERSION

RUN wget -q https://dl.google.com/go/go$GO_VERSION.linux-$ARCH.tar.gz && \
tar -xf go$GO_VERSION.linux-$ARCH.tar.gz && \
rm go$GO_VERSION.linux-$ARCH.tar.gz && \
mv go /usr/local
tar -xf go$GO_VERSION.linux-$ARCH.tar.gz && \
rm go$GO_VERSION.linux-$ARCH.tar.gz && \
mv go /usr/local

ENV GOROOT /usr/local/go
ENV GOPATH /go
Expand All @@ -61,6 +94,7 @@ LABEL description="IBM CSI Object Storage Plugin"
LABEL build-date=${build_date}
LABEL git-commit-id=${git_commit_id}
RUN yum update -y && yum install fuse fuse-libs fuse3 fuse3-libs -y
COPY --from=mountpoint-builder /mountpoint-s3/target/release/mount-s3 /usr/bin/mount-s3
COPY --from=s3fs-builder /usr/local/bin/s3fs /usr/bin/s3fs
COPY --from=rclone-builder /usr/local/bin/rclone /usr/bin/rclone
COPY ibm-object-csi-driver ibm-object-csi-driver
Expand Down
1 change: 1 addition & 0 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const (

S3FS = "s3fs"
RClone = "rclone"
MNTS3 = "mountpoint"
DefaultNamespace = "default"

IAMEP = "https://private.iam.cloud.ibm.com/identity/token"
Expand Down
2 changes: 2 additions & 0 deletions pkg/mounter/fake_mounter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func (f *FakeMounterFactory) NewMounter(attrib map[string]string, secretMap map[
return fakenewS3fsMounter(f.IsFailedMount)
case constants.RClone:
return fakenewRcloneMounter(f.IsFailedMount)
case constants.MNTS3:
return fakenewMountpointMounter(f.IsFailedMount)
default:
return fakenewS3fsMounter(f.IsFailedMount)
}
Expand Down
34 changes: 34 additions & 0 deletions pkg/mounter/fake_mounter_mountpoint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package mounter

import "errors"

type fakemountpointMounter struct {
bucketName string
objPath string
endPoint string
accessKey string
secretKey string
isFailedMount bool
}

func fakenewMountpointMounter(isFailedMount bool) Mounter {
return &fakemountpointMounter{
bucketName: bucketName,
objPath: objPath,
endPoint: endPoint,
accessKey: keys,
secretKey: keys,
isFailedMount: isFailedMount,
}
}

func (mnpt *fakemountpointMounter) Mount(source string, target string) error {
if mnpt.isFailedMount {
return errors.New("failed to mount mountpoint")
}
return nil
}

func (mnpt *fakemountpointMounter) Unmount(target string) error {
return nil
}
127 changes: 127 additions & 0 deletions pkg/mounter/mounter-mountpoint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/*******************************************************************************
* IBM Confidential
* OCO Source Materials
* IBM Cloud Kubernetes Service, 5737-D43
* (C) Copyright IBM Corp. 2023 All Rights Reserved.
* The source code for this program is not published or otherwise divested of
* its trade secrets, irrespective of what has been deposited with
* the U.S. Copyright Office.
******************************************************************************/

// Package mounter
package mounter

import (
"crypto/sha256"
"fmt"
"os"
"path"

// "github.com/IBM/ibm-object-csi-driver/pkg/constants"
"github.com/IBM/ibm-object-csi-driver/pkg/mounter/utils"
"k8s.io/klog/v2"
)

// Mounter interface defined in mounter.go
// MountpointMounter Implements Mounter
type MountpointMounter struct {
BucketName string //From Secret in SC
ObjPath string //From Secret in SC
EndPoint string //From Secret in SC
AccessKey string
SecretKey string
MountOptions []string
MounterUtils utils.MounterUtils
}

func NewMountpointMounter(secretMap map[string]string, mountOptions []string, mounterUtils utils.MounterUtils) Mounter {
klog.Info("-newMountpointMounter-")

var (
val string
check bool
mounter *MountpointMounter
)

mounter = &MountpointMounter{}

if val, check = secretMap["cosEndpoint"]; check {
mounter.EndPoint = val
}
if val, check = secretMap["bucketName"]; check {
mounter.BucketName = val
}
if val, check = secretMap["objPath"]; check {
mounter.ObjPath = val
}
if val, check = secretMap["accessKey"]; check {
mounter.AccessKey = val
}
if val, check = secretMap["secretKey"]; check {
mounter.SecretKey = val
}

klog.Infof("newMntS3Mounter args:\n\tbucketName: [%s]\n\tobjPath: [%s]\n\tendPoint: [%s]",
mounter.BucketName, mounter.ObjPath, mounter.EndPoint)

mounter.MountOptions = mountOptions
mounter.MounterUtils = mounterUtils

return mounter
}

const (
mntS3Cmd = "mount-s3"
metaRootMntS3 = "/var/lib/ibmc-mntS3"
)

func (mntS3 *MountpointMounter) Stage(stagePath string) error {
return nil
}
func (mntS3 *MountpointMounter) Unstage(stagePath string) error {
return nil
}
func (mntS3 *MountpointMounter) Mount(source string, target string) error {
klog.Info("-MountpointMounter Mount-")
klog.Infof("Mount args:\n\tsource: <%s>\n\ttarget: <%s>", source, target)
var pathExist bool
var err error
metaPath := path.Join(metaRootMntS3, fmt.Sprintf("%x", sha256.Sum256([]byte(target))))

if pathExist, err = checkPath(metaPath); err != nil {
klog.Errorf("MountpointMounter Mount: Cannot stat directory %s: %v", metaPath, err)
return err
}

if !pathExist {
if err = mkdirAll(metaPath, 0755); // #nosec G301: used for mntS3
err != nil {
klog.Errorf("MountpointMounter Mount: Cannot create directory %s: %v", metaPath, err)
return err
}
}

os.Setenv("AWS_ACCESS_KEY_ID", mntS3.AccessKey)
os.Setenv("AWS_SECRET_ACCESS_KEY", mntS3.SecretKey)

args := []string{
fmt.Sprintf("--endpoint-url=%v", mntS3.EndPoint),
mntS3.BucketName,
target,
}

if mntS3.ObjPath != "" {
args = append(args, fmt.Sprintf("--prefix %s", mntS3.ObjPath))
}
return mntS3.MounterUtils.FuseMount(target, mntS3Cmd, args)
}
func (mntS3 *MountpointMounter) Unmount(target string) error {
klog.Info("-MountpointMounter Unmount-")
metaPath := path.Join(metaRootMntS3, fmt.Sprintf("%x", sha256.Sum256([]byte(target))))
err := os.RemoveAll(metaPath)
if err != nil {
return err
}

return mntS3.MounterUtils.FuseUnmount(target)
}
Loading