Skip to content

Commit a175586

Browse files
Abby DengPushkar Acharya
authored andcommitted
[CSI][i-cat] use DNS for ICAT datacenters
1 parent f997b18 commit a175586

6 files changed

Lines changed: 522 additions & 31 deletions

File tree

Dockerfile

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@ RUN make cross
2323
################################################################
2424

2525
# Dockerfile.goreleaser should be kept roughly in sync
26-
FROM alpine:3.20.3
26+
FROM ubuntu:24.04
2727

2828
# Need to get these updates for k8s mount-utils library to work properly
29-
RUN apk update && \
30-
apk add --no-cache e2fsprogs-extra~=1.47.0 && \
31-
apk add --no-cache blkid~=2.40.1 && \
32-
apk add --no-cache xfsprogs-extra~=6.8.0 && \
33-
rm -rf /var/cache/apk/*
29+
RUN apt-get update && \
30+
apt-get install -y --no-install-recommends \
31+
ca-certificates \
32+
e2fsprogs \
33+
nfs-common \
34+
util-linux \
35+
xfsprogs && \
36+
rm -rf /var/lib/apt/lists/*
3437

3538
COPY --from=builder /build/dist/crusoe-csi-driver /usr/local/go/bin/crusoe-csi-driver
3639

Dockerfile.goreleaser

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
################################################################
22
# STEP 2: build a small image and run crusoe-csi-driver binary #
33
################################################################
4-
FROM alpine:3.20.3
4+
FROM ubuntu:24.04
55

66
# Need to get these updates for k8s mount-utils library to work properly
7-
RUN apk update && \
8-
apk add --no-cache e2fsprogs-extra~=1.47.0 && \
9-
apk add --no-cache blkid~=2.40.1 && \
10-
apk add --no-cache xfsprogs-extra~=6.8.0 && \
11-
rm -rf /var/cache/apk/*
7+
RUN apt-get update && \
8+
apt-get install -y --no-install-recommends \
9+
ca-certificates \
10+
e2fsprogs \
11+
nfs-common \
12+
util-linux \
13+
xfsprogs && \
14+
rm -rf /var/lib/apt/lists/*
1215

1316
COPY crusoe-csi-driver /usr/local/go/bin/crusoe-csi-driver
1417

internal/crusoe/nfs_flag.go

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,31 +7,38 @@ import (
77
"fmt"
88
"io"
99
"net/http"
10+
11+
"k8s.io/klog/v2"
1012
)
1113

12-
const nfsFlagRouteTemplate = "%s/projects/%s/storage/nfs/is-using-nfs"
14+
const (
15+
nfsFlagRouteTemplate = "%s/projects/%s/storage/nfs/is-using-nfs"
16+
vastUseSecondaryClusterFlagRouteTemplate = "%s/projects/%s/storage/nfs/vast-use-secondary-cluster"
17+
DEBUG = 8
18+
)
1319

1420
var (
15-
errCreateNfsFlagRequest = errors.New("failed to create NFS flag request")
16-
errGetNfsFlag = errors.New("failed to get NFS flag")
17-
errReadNfsResponse = errors.New("failed to read NFS flag response")
18-
errUnmarshalNfsFlag = errors.New("failed to unmarshal NFS flag response")
21+
errCreateFlagRequest = errors.New("failed to create flag request")
22+
errGetFlag = errors.New("failed to get flag")
23+
errReadFlagResponse = errors.New("failed to read flag response")
24+
errUnmarshalFlag = errors.New("failed to unmarshal flag response")
1925
)
2026

2127
type NfsFlagResponse struct {
2228
Status bool `json:"status"`
2329
}
2430

25-
// GetNFSFlag returns true if the project has NFS enabled.
26-
func GetNFSFlag(ctx context.Context, crusoeHTTPClient *http.Client, apiEndpoint, projectID string) (bool, error) {
27-
nfsFlagRoute := fmt.Sprintf(nfsFlagRouteTemplate, apiEndpoint, projectID)
28-
req, err := http.NewRequestWithContext(ctx, http.MethodGet, nfsFlagRoute, http.NoBody)
31+
// getFlag is a helper function to fetch a boolean flag from the API.
32+
func getFlag(ctx context.Context, crusoeHTTPClient *http.Client, flagRoute string) (bool, error) {
33+
klog.Infof("Fetching flag from URL: %s", flagRoute)
34+
35+
req, err := http.NewRequestWithContext(ctx, http.MethodGet, flagRoute, http.NoBody)
2936
if err != nil {
30-
return false, fmt.Errorf("%w: %w", errCreateNfsFlagRequest, err)
37+
return false, fmt.Errorf("%w: %w", errCreateFlagRequest, err)
3138
}
3239
resp, err := crusoeHTTPClient.Do(req)
3340
if err != nil {
34-
return false, fmt.Errorf("%w: %w", errGetNfsFlag, err)
41+
return false, fmt.Errorf("%w: %w", errGetFlag, err)
3542
}
3643

3744
if resp != nil && resp.Body != nil {
@@ -40,15 +47,42 @@ func GetNFSFlag(ctx context.Context, crusoeHTTPClient *http.Client, apiEndpoint,
4047

4148
bodyBytes, err := io.ReadAll(resp.Body)
4249
if err != nil {
43-
return false, fmt.Errorf("%w: %w", errReadNfsResponse, err)
50+
return false, fmt.Errorf("%w: %w", errReadFlagResponse, err)
51+
}
52+
53+
klog.Infof("Flag API response - Status: %d, Content-Type: %s, Body length: %d bytes",
54+
resp.StatusCode, resp.Header.Get("Content-Type"), len(bodyBytes))
55+
klog.V(DEBUG).Infof("Flag API raw response body: %q", string(bodyBytes))
56+
57+
// Check HTTP status code before unmarshaling
58+
if resp.StatusCode != http.StatusOK {
59+
return false, fmt.Errorf("%w: HTTP %d: %s", errGetFlag, resp.StatusCode, string(bodyBytes))
4460
}
4561

46-
var nfsFlag NfsFlagResponse
62+
var flagResponse NfsFlagResponse
4763

48-
unmarshalErr := json.Unmarshal(bodyBytes, &nfsFlag)
64+
unmarshalErr := json.Unmarshal(bodyBytes, &flagResponse)
4965
if unmarshalErr != nil {
50-
return false, fmt.Errorf("%w: %w", errUnmarshalNfsFlag, unmarshalErr)
66+
return false, fmt.Errorf("%w: %w (response body: %q)", errUnmarshalFlag, unmarshalErr, string(bodyBytes))
5167
}
5268

53-
return nfsFlag.Status, nil
69+
return flagResponse.Status, nil
70+
}
71+
72+
// GetNFSFlag returns true if the project has NFS enabled.
73+
func GetNFSFlag(ctx context.Context, crusoeHTTPClient *http.Client, apiEndpoint, projectID string) (bool, error) {
74+
nfsFlagRoute := fmt.Sprintf(nfsFlagRouteTemplate, apiEndpoint, projectID)
75+
76+
return getFlag(ctx, crusoeHTTPClient, nfsFlagRoute)
77+
}
78+
79+
// GetVastUseSecondaryClusterFlag returns true if the project has the vast-use-secondary-cluster flag enabled.
80+
func GetVastUseSecondaryClusterFlag(
81+
ctx context.Context,
82+
crusoeHTTPClient *http.Client,
83+
apiEndpoint, projectID string,
84+
) (bool, error) {
85+
flagRoute := fmt.Sprintf(vastUseSecondaryClusterFlagRouteTemplate, apiEndpoint, projectID)
86+
87+
return getFlag(ctx, crusoeHTTPClient, flagRoute)
5488
}

internal/node/fs/fs_node.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ import (
1616
"k8s.io/mount-utils"
1717
)
1818

19+
const (
20+
crusoeCloudDNSNFSHost = "nfs.crusoecloudcompute.com"
21+
icatLocation = "eu-iceland1-a"
22+
dnsRemotePorts = "dns"
23+
)
24+
1925
type Node struct {
2026
csi.UnimplementedNodeServer
2127
CrusoeClient *crusoeapi.APIClient
@@ -72,7 +78,19 @@ func (d *Node) NodePublishVolume(ctx context.Context, request *csi.NodePublishVo
7278
mountOpts = append(mountOpts, node.ReadOnlyMountOption)
7379
}
7480

75-
err = nodePublishVolume(d.Mounter, d.Resizer, mountOpts, nfsEnabled, d.NFSRemotePorts, d.NFSHost, request)
81+
// Use DNS for ICAT locations instead of IP-based NFSHost
82+
nfsHost := d.NFSHost
83+
nfsRemotePorts := d.NFSRemotePorts
84+
klog.Infof("Host instance location: %q, checking against icatLocation: %q", d.HostInstance.Location, icatLocation)
85+
if d.useDNSForMount(ctx) {
86+
klog.Infof("Using DNS-based NFS host for ICAT location: %s", crusoeCloudDNSNFSHost)
87+
nfsHost = crusoeCloudDNSNFSHost
88+
nfsRemotePorts = dnsRemotePorts
89+
} else {
90+
klog.Infof("Using IP-based NFS host: %s with remote ports: %s", nfsHost, nfsRemotePorts)
91+
}
92+
93+
err = nodePublishVolume(d.Mounter, d.Resizer, mountOpts, nfsEnabled, nfsRemotePorts, nfsHost, request)
7694
if err != nil {
7795
klog.Errorf("failed to publish volume %s: %s", request.GetVolumeId(), err.Error())
7896

@@ -84,6 +102,18 @@ func (d *Node) NodePublishVolume(ctx context.Context, request *csi.NodePublishVo
84102
return &csi.NodePublishVolumeResponse{}, nil
85103
}
86104

105+
func (d *Node) useDNSForMount(ctx context.Context) bool {
106+
useSecondaryVast, err := crusoe.GetVastUseSecondaryClusterFlag(
107+
ctx, d.CrusoeHTTPClient, d.CrusoeAPIEndpoint, d.HostInstance.ProjectId)
108+
if err != nil {
109+
klog.Errorf("failed to fetch VastUseSecondaryCluster flag: %s", err.Error())
110+
111+
return false
112+
}
113+
114+
return useSecondaryVast && d.HostInstance.Location == icatLocation
115+
}
116+
87117
func (d *Node) NodeUnpublishVolume(_ context.Context, request *csi.NodeUnpublishVolumeRequest) (
88118
*csi.NodeUnpublishVolumeResponse,
89119
error,

0 commit comments

Comments
 (0)