@@ -59,22 +59,37 @@ type nodeService struct {
59
59
csi.UnimplementedNodeServer
60
60
}
61
61
62
+ // driver/node_service.go – trimmed to the relevant bits
62
63
func newNodeService (driverOptions * DriverOptions ) nodeService {
63
- klog .V (5 ).InfoS ("[Debug] Retrieving node info from metadata service" )
64
64
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
+ }
68
85
}
69
- klog .InfoS ("regionFromSession Node service" , "region" , metadata .GetRegion ())
70
86
71
87
nodeMounter , err := newNodeMounter ()
72
88
if err != nil {
73
89
panic (err )
74
90
}
75
91
76
92
// Remove taint from node to indicate driver startup success
77
- // This is done in the background as a goroutine to allow for driver startup
78
93
go removeTaintInBackground (cloud .DefaultKubernetesAPIClient , removeNotReadyTaint )
79
94
80
95
return nodeService {
@@ -242,12 +257,12 @@ func (d *nodeService) NodeGetCapabilities(ctx context.Context, req *csi.NodeGetC
242
257
return & csi.NodeGetCapabilitiesResponse {Capabilities : caps }, nil
243
258
}
244
259
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
251
266
}
252
267
253
268
// isMounted checks if target is mounted. It does NOT return an error if target
0 commit comments