Skip to content

Commit d5df689

Browse files
Add MountEITBasedFileShare to mounter interface (#88)
* Add MountEITBasedFileShare to Mounter interface that calls MHC server over unix socket
1 parent 59170d9 commit d5df689

File tree

8 files changed

+130
-5
lines changed

8 files changed

+130
-5
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/IBM/ibm-csi-common
33
go 1.20
44

55
require (
6-
github.com/IBM/ibmcloud-volume-interface v1.2.2
6+
github.com/IBM/ibmcloud-volume-interface v1.2.4
77
github.com/IBM/ibmcloud-volume-vpc v1.1.7
88
github.com/IBM/secret-utils-lib v1.1.8
99
github.com/container-storage-interface/spec v1.8.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.6.7 h1:eHgfQl6IeSmzWUyiSi13CvoFYsovoyq
5454
github.com/IBM-Cloud/ibm-cloud-cli-sdk v0.6.7/go.mod h1:RiUvKuHKTBmBApDMUQzBL14pQUGKcx/IioKQPIcRQjs=
5555
github.com/IBM/go-sdk-core/v5 v5.9.1 h1:06pXbD9Rgmqqe2HA5YAeQbB4eYRRFgIoOT+Kh3cp1zo=
5656
github.com/IBM/go-sdk-core/v5 v5.9.1/go.mod h1:axE2JrRq79gIJTjKPBwV6gWHswvVptBjbcvvCPIxARM=
57-
github.com/IBM/ibmcloud-volume-interface v1.2.2 h1:BHF9grjuyUZEbKHgw/XZQhDztZfFpBkdQEEY1ticYlk=
58-
github.com/IBM/ibmcloud-volume-interface v1.2.2/go.mod h1:PMe4wOp+EEkVNwlo/iJahh+6/aIvjWo+nAdHB1oGBFE=
57+
github.com/IBM/ibmcloud-volume-interface v1.2.4 h1:4ULPklSo9ZN7S8d2bS/eBSV99HDowju55bnKT6pt+S0=
58+
github.com/IBM/ibmcloud-volume-interface v1.2.4/go.mod h1:PMe4wOp+EEkVNwlo/iJahh+6/aIvjWo+nAdHB1oGBFE=
5959
github.com/IBM/ibmcloud-volume-vpc v1.1.7 h1:j8X2swP5mDMiLPFZDge3zZwPTHqNQS6apvWaCX0oXas=
6060
github.com/IBM/ibmcloud-volume-vpc v1.1.7/go.mod h1:BLszLIqjzttg15YEw2JcbdnMUReYm7t+lagmGsUEikQ=
6161
github.com/IBM/secret-common-lib v1.1.8 h1:FX/fSN108phDwlMF9YhFdVCULTWCcHneeuT+dBH6wnk=

pkg/messages/messages_en.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,24 @@ var messagesEn = map[string]Message{
275275
Type: codes.Internal,
276276
Action: "Please check if volume is used by POD properly",
277277
},
278+
MountingTargetFailed: {
279+
Code: MountingTargetFailed,
280+
Description: "Failed to mount target.",
281+
Type: codes.Internal,
282+
Action: "Check node server logs for more details on mount failure.",
283+
},
284+
UnresponsiveMountHelperContainerUtility: {
285+
Code: UnresponsiveMountHelperContainerUtility,
286+
Description: "Failed to mount target because unable to make connection to mount helper container service.",
287+
Type: codes.Unavailable,
288+
Action: "Check if EIT is enabled from storage operator. Run command 'kubectl edit configmap addon-vpc-file-csi-driver-configmap -n kube-system' and set 'ENABLE_EIT' flag to 'true'.",
289+
},
290+
MetadataServiceNotEnabled: {
291+
Code: MetadataServiceNotEnabled,
292+
Description: "Failed to mount target.",
293+
Type: codes.Internal,
294+
Action: "Metadata service might not be enabled for worker node. Make sure to use IKS>=1.30 or ROKS>=4.16 cluster.",
295+
},
278296
ListVolumesFailed: {
279297
Code: ListVolumesFailed,
280298
Description: "Failed to list volumes",

pkg/messages/reason_code.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,15 @@ const (
144144
// CreateMountTargetFailed ...
145145
CreateMountTargetFailed = "CreateMountTargetFailed"
146146

147+
// MountingTargetFailed ...
148+
MountingTargetFailed = "MountingTargetFailed"
149+
150+
// UnresponsiveMountHelperContainerUtility ...
151+
UnresponsiveMountHelperContainerUtility = "UnresponsiveMountHelperContainerUtility"
152+
153+
// MetadataServiceNotEnabled ...
154+
MetadataServiceNotEnabled = "MetadataServiceNotEnabled"
155+
147156
// ListVolumesFailed ...
148157
ListVolumesFailed = "ListVolumesFailed"
149158

pkg/mountmanager/fake-safe-mounter.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222

2323
mount "k8s.io/mount-utils"
2424
exec "k8s.io/utils/exec"
25-
testExec "k8s.io/utils/exec/testing"
2625
testingexec "k8s.io/utils/exec/testing"
2726
)
2827

@@ -31,6 +30,11 @@ type FakeNodeMounter struct {
3130
*mount.SafeFormatAndMount
3231
}
3332

33+
// MountEITBasedFileShare implements Mounter.
34+
func (*FakeNodeMounter) MountEITBasedFileShare(mountPath string, targetPath string, fsType string, requestID string) (string, error) {
35+
return "", nil
36+
}
37+
3438
// NewFakeNodeMounter ...
3539
func NewFakeNodeMounter() Mounter {
3640
//Have to make changes here to pass the Mock functions
@@ -50,7 +54,7 @@ func NewFakeSafeMounter() *mount.SafeFormatAndMount {
5054
}},
5155
}
5256

53-
var fakeExec exec.Interface = &testExec.FakeExec{
57+
var fakeExec exec.Interface = &testingexec.FakeExec{
5458
DisableScripts: true,
5559
}
5660

@@ -92,6 +96,11 @@ type FakeNodeMounterWithCustomActions struct {
9296
actionList []testingexec.FakeCommandAction
9397
}
9498

99+
// MountEITBasedFileShare implements Mounter.
100+
func (*FakeNodeMounterWithCustomActions) MountEITBasedFileShare(mountPath string, targetPath string, fsType string, requestID string) (string, error) {
101+
return "", nil
102+
}
103+
95104
// NewFakeNodeMounterWithCustomActions ...
96105
func NewFakeNodeMounterWithCustomActions(actionList []testingexec.FakeCommandAction) Mounter {
97106
fakeSafeMounter := NewFakeSafeMounterWithCustomActions(actionList)

pkg/mountmanager/mount_linux.go

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,42 @@
2121
package mountmanager
2222

2323
import (
24+
"context"
25+
"encoding/json"
26+
"fmt"
27+
"io"
28+
"net"
29+
"net/http"
2430
"os"
31+
"strings"
32+
"time"
2533

2634
mount "k8s.io/mount-utils"
2735
)
2836

37+
const (
38+
//socket path
39+
defaultSocketPath = "/tmp/mysocket.sock"
40+
// mount url
41+
urlMountPath = "http://unix/api/mount"
42+
// debug url
43+
urlDebugPath = "http://unix/api/debugLogs"
44+
// http timeout
45+
timeout = 3 * time.Minute
46+
)
47+
48+
// MountEITBasedFileShare mounts EIT based FileShare on host system
49+
func (m *NodeMounter) MountEITBasedFileShare(mountPath string, targetPath string, fsType string, requestID string) (string, error) {
50+
// Create payload
51+
payload := fmt.Sprintf(`{"mountPath":"%s","targetPath":"%s","fsType":"%s","requestID":"%s"}`, mountPath, targetPath, fsType, requestID)
52+
errResponse, err := createMountHelperContainerRequest(payload, urlMountPath)
53+
54+
if err != nil {
55+
return errResponse, err
56+
}
57+
return "", nil
58+
}
59+
2960
// MakeFile creates an empty file.
3061
func (m *NodeMounter) MakeFile(path string) error {
3162
f, err := os.OpenFile(path, os.O_CREATE, os.FileMode(0644))
@@ -75,3 +106,55 @@ func (m *NodeMounter) Resize(devicePath string, deviceMountPath string) (bool, e
75106
}
76107
return true, nil
77108
}
109+
110+
// createMountHelperContainerRequest creates a request to mount-helper-container server over UNIX socket and returns errors if any.
111+
func createMountHelperContainerRequest(payload string, url string) (string, error) {
112+
// Get socket path
113+
socketPath := os.Getenv("SOCKET_PATH")
114+
if socketPath == "" {
115+
socketPath = defaultSocketPath
116+
}
117+
// Create a custom dialer function for Unix socket connection
118+
dialer := func(ctx context.Context, network, addr string) (net.Conn, error) {
119+
return net.Dial("unix", socketPath)
120+
}
121+
122+
// Create an HTTP client with the Unix socket transport
123+
client := &http.Client{
124+
Transport: &http.Transport{
125+
DialContext: dialer,
126+
},
127+
Timeout: timeout,
128+
}
129+
130+
//Create POST request
131+
req, err := http.NewRequest("POST", url, strings.NewReader(payload))
132+
if err != nil {
133+
return "", err
134+
}
135+
req.Header.Set("Content-Type", "application/json")
136+
response, err := client.Do(req)
137+
if err != nil {
138+
return "", err
139+
}
140+
defer response.Body.Close()
141+
body, err := io.ReadAll(response.Body)
142+
if err != nil {
143+
return "", err
144+
}
145+
146+
// Unmarshell json response
147+
var responseBody struct {
148+
MountExitCode string `json:"MountExitCode"`
149+
ExitDescription string `json:"Description"`
150+
}
151+
err = json.Unmarshal(body, &responseBody)
152+
if err != nil {
153+
return "", err
154+
}
155+
156+
if response.StatusCode != http.StatusOK {
157+
return responseBody.ExitDescription, fmt.Errorf("Response from mount-helper-container -> Exit Status Code: %s ,ResponseCode: %v", responseBody.MountExitCode, response.StatusCode)
158+
}
159+
return "", nil
160+
}

pkg/mountmanager/mount_unsupported.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,8 @@ func (m *NodeMounter) GetSafeFormatAndMount() *mount.SafeFormatAndMount {
5252
func (m *NodeMounter) Resize(devicePath string, deviceMountPath string) (bool, error) {
5353
return true, errors.New("not implemented")
5454
}
55+
56+
// MountEITBasedFileShare ...
57+
func (m *NodeMounter) MountEITBasedFileShare(mountPath string, targetPath string, fsType string, requestID string) (string, error) {
58+
return "", nil
59+
}

pkg/mountmanager/safe-mounter.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type mountInterface = mount.Interface
2828
type Mounter interface {
2929
mountInterface
3030

31+
MountEITBasedFileShare(mountPath string, targetPath string, fsType string, requestID string) (string, error)
3132
GetSafeFormatAndMount() *mount.SafeFormatAndMount
3233
MakeFile(path string) error
3334
MakeDir(path string) error

0 commit comments

Comments
 (0)