@@ -43,7 +43,6 @@ import (
4343
4444var getRuntimeClassForPodFunc = getRuntimeClassForPod
4545var isConfidentialRuntimeClassFunc = isConfidentialRuntimeClass
46- var isKataNodeFunc = isKataNode
4746
4847// NodePublishVolume mount the volume from staging to target path
4948func (d * Driver ) NodePublishVolume (ctx context.Context , req * csi.NodePublishVolumeRequest ) (* csi.NodePublishVolumeResponse , error ) {
@@ -101,42 +100,40 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu
101100 }
102101 }
103102
104- if d .enableKataCCMount {
105- enableKataCCMount := isKataNodeFunc (ctx , d .NodeID , d .kubeClient )
106- if enableKataCCMount && context [podNameField ] != "" && context [podNamespaceField ] != "" {
107- runtimeClass , err := getRuntimeClassForPodFunc (ctx , d .kubeClient , context [podNameField ], context [podNamespaceField ])
103+ enableKataCCMount := d .isKataNode && d .enableKataCCMount
104+ if enableKataCCMount && context [podNameField ] != "" && context [podNamespaceField ] != "" {
105+ runtimeClass , err := getRuntimeClassForPodFunc (ctx , d .kubeClient , context [podNameField ], context [podNamespaceField ])
106+ if err != nil {
107+ return nil , status .Errorf (codes .Internal , "failed to get runtime class for pod %s/%s: %v" , context [podNamespaceField ], context [podNameField ], err )
108+ }
109+ klog .V (2 ).Infof ("NodePublishVolume: volume(%s) mount on %s with runtimeClass %s" , volumeID , target , runtimeClass )
110+ isConfidentialRuntimeClass , err := isConfidentialRuntimeClassFunc (ctx , d .kubeClient , runtimeClass )
111+ if err != nil {
112+ return nil , status .Errorf (codes .Internal , "failed to check if runtime class %s is confidential: %v" , runtimeClass , err )
113+ }
114+ if isConfidentialRuntimeClass {
115+ klog .V (2 ).Infof ("NodePublishVolume for volume(%s) where runtimeClass is %s" , volumeID , runtimeClass )
116+ source := req .GetStagingTargetPath ()
117+ if len (source ) == 0 {
118+ return nil , status .Error (codes .InvalidArgument , "Staging target not provided" )
119+ }
120+ // Load the mount info from staging area
121+ mountInfo , err := d .directVolume .VolumeMountInfo (source )
108122 if err != nil {
109- return nil , status .Errorf (codes .Internal , "failed to get runtime class for pod %s/%s: %v" , context [podNamespaceField ], context [podNameField ], err )
123+ return nil , status .Errorf (codes .Internal , "failed to load mount info from %s: %v" , source , err )
124+ }
125+ if mountInfo == nil {
126+ return nil , status .Errorf (codes .Internal , "mount info is nil for volume %s" , volumeID )
110127 }
111- klog .V (2 ).Infof ("NodePublishVolume: volume(%s) mount on %s with runtimeClass %s" , volumeID , target , runtimeClass )
112- isConfidentialRuntimeClass , err := isConfidentialRuntimeClassFunc (ctx , d .kubeClient , runtimeClass )
128+ data , err := json .Marshal (mountInfo )
113129 if err != nil {
114- return nil , status .Errorf (codes .Internal , "failed to check if runtime class %s is confidential : %v" , runtimeClass , err )
130+ return nil , status .Errorf (codes .Internal , "failed to marshal mount info %s : %v" , source , err )
115131 }
116- if isConfidentialRuntimeClass {
117- klog .V (2 ).Infof ("NodePublishVolume for volume(%s) where runtimeClass is %s" , volumeID , runtimeClass )
118- source := req .GetStagingTargetPath ()
119- if len (source ) == 0 {
120- return nil , status .Error (codes .InvalidArgument , "Staging target not provided" )
121- }
122- // Load the mount info from staging area
123- mountInfo , err := d .directVolume .VolumeMountInfo (source )
124- if err != nil {
125- return nil , status .Errorf (codes .Internal , "failed to load mount info from %s: %v" , source , err )
126- }
127- if mountInfo == nil {
128- return nil , status .Errorf (codes .Internal , "mount info is nil for volume %s" , volumeID )
129- }
130- data , err := json .Marshal (mountInfo )
131- if err != nil {
132- return nil , status .Errorf (codes .Internal , "failed to marshal mount info %s: %v" , source , err )
133- }
134- if err = d .directVolume .Add (target , string (data )); err != nil {
135- return nil , status .Errorf (codes .Internal , "failed to save mount info %s: %v" , target , err )
136- }
137- klog .V (2 ).Infof ("NodePublishVolume: direct volume mount %s at %s successfully" , source , target )
138- return & csi.NodePublishVolumeResponse {}, nil
132+ if err = d .directVolume .Add (target , string (data )); err != nil {
133+ return nil , status .Errorf (codes .Internal , "failed to save mount info %s: %v" , target , err )
139134 }
135+ klog .V (2 ).Infof ("NodePublishVolume: direct volume mount %s at %s successfully" , source , target )
136+ return & csi.NodePublishVolumeResponse {}, nil
140137 }
141138 }
142139 }
@@ -419,9 +416,9 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe
419416 }
420417 klog .V (2 ).Infof ("volume(%s) mount %s on %s succeeded" , volumeID , source , cifsMountPath )
421418 }
422- enableKataCCMount := isKataNodeFunc ( ctx , d . NodeID , d . kubeClient )
419+ enableKataCCMount := d . isKataNode && d . enableKataCCMount
423420 // If runtime OS is not windows and protocol is not nfs, save mountInfo.json
424- if d . enableKataCCMount && enableKataCCMount {
421+ if enableKataCCMount {
425422 if runtime .GOOS != "windows" && protocol != nfs {
426423 // Check if mountInfo.json is already present at the targetPath
427424 isMountInfoPresent , err := d .directVolume .VolumeMountInfo (cifsMountPath )
0 commit comments