Skip to content

Commit 01a8927

Browse files
committed
Expose AWS_REGION on the node
default value for the node region read region from env variable
1 parent 43954a0 commit 01a8927

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

charts/aws-fsx-csi-driver/templates/node-daemonset.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ spec:
6767
valueFrom:
6868
fieldRef:
6969
fieldPath: spec.nodeName
70+
{{- with .Values.node.region }}
71+
- name: AWS_REGION
72+
value: {{ . }}
73+
{{- end }}
7074
volumeMounts:
7175
- name: kubelet-dir
7276
mountPath: /var/lib/kubelet

charts/aws-fsx-csi-driver/values.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ node:
8888
name: fsx-csi-node-sa
8989
annotations: {}
9090
podAnnotations: {}
91+
# AWS region to use. If not specified then the region will be looked up via the AWS EC2 metadata
92+
# service.
93+
# ---
94+
# region: us-east-1
95+
region:
9196
tolerateAllTaints: true
9297
tolerations:
9398
- operator: Exists

pkg/driver/node.go

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,37 @@ type nodeService struct {
5959
csi.UnimplementedNodeServer
6060
}
6161

62+
// driver/node_service.go – trimmed to the relevant bits
6263
func newNodeService(driverOptions *DriverOptions) nodeService {
63-
klog.V(5).InfoS("[Debug] Retrieving node info from metadata service")
6464
region := os.Getenv("AWS_REGION")
65-
metadata, err := cloud.NewMetadataService(cloud.DefaultEC2MetadataClient, cloud.DefaultKubernetesAPIClient, region)
66-
if err != nil {
67-
panic(err)
65+
66+
var (
67+
metadata cloud.MetadataService
68+
err error
69+
)
70+
71+
if region == "" {
72+
klog.V(5).InfoS("[Debug] Retrieving region from metadata service")
73+
metadata, err := cloud.NewMetadataService(cloud.DefaultEC2MetadataClient, cloud.DefaultKubernetesAPIClient, region)
74+
if err != nil {
75+
klog.ErrorS(err, "Could not determine region from any metadata service. The region can be manually supplied via the AWS_REGION environment variable.")
76+
panic(err)
77+
}
78+
region = metadata.GetRegion()
79+
} else {
80+
klog.InfoS("regionFromEnv Node service", "region", region)
81+
metadata, err = cloud.NewMetadataService(cloud.DefaultEC2MetadataClient, cloud.DefaultKubernetesAPIClient, region)
82+
if err != nil {
83+
panic(err)
84+
}
6885
}
69-
klog.InfoS("regionFromSession Node service", "region", metadata.GetRegion())
7086

7187
nodeMounter, err := newNodeMounter()
7288
if err != nil {
7389
panic(err)
7490
}
7591

7692
// Remove taint from node to indicate driver startup success
77-
// This is done in the background as a goroutine to allow for driver startup
7893
go removeTaintInBackground(cloud.DefaultKubernetesAPIClient, removeNotReadyTaint)
7994

8095
return nodeService{
@@ -242,12 +257,12 @@ func (d *nodeService) NodeGetCapabilities(ctx context.Context, req *csi.NodeGetC
242257
return &csi.NodeGetCapabilitiesResponse{Capabilities: caps}, nil
243258
}
244259

245-
func (d *nodeService) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) {
246-
klog.V(4).InfoS("NodeGetInfo: called", "args", util.SanitizeRequest(req))
247-
248-
return &csi.NodeGetInfoResponse{
249-
NodeId: d.metadata.GetInstanceID(),
250-
}, nil
260+
func (d *nodeService) NodeGetInfo(ctx context.Context, _ *csi.NodeGetInfoRequest) (*csi.NodeGetInfoResponse, error) {
261+
if id := os.Getenv("CSI_NODE_NAME"); id != "" {
262+
return &csi.NodeGetInfoResponse{NodeId: id}, nil
263+
}
264+
// Fallback – still works anywhere IAM roles are present
265+
return &csi.NodeGetInfoResponse{NodeId: d.metadata.GetInstanceID()}, nil
251266
}
252267

253268
// isMounted checks if target is mounted. It does NOT return an error if target

0 commit comments

Comments
 (0)