@@ -113,44 +113,52 @@ func (d *Driver) NodePublishVolume(ctx context.Context, req *csi.NodePublishVolu
113
113
}
114
114
}
115
115
116
- enableKataCCMount := d .isKataNode && d .enableKataCCMount
117
- if enableKataCCMount && context [podNameField ] != "" && context [podNamespaceField ] != "" {
118
- runtimeClass , err := getRuntimeClassForPodFunc (ctx , d .kubeClient , context [podNameField ], context [podNamespaceField ])
119
- if err != nil {
120
- return nil , status .Errorf (codes .Internal , "failed to get runtime class for pod %s/%s: %v" , context [podNamespaceField ], context [podNameField ], err )
121
- }
122
- klog .V (2 ).Infof ("NodePublishVolume: volume(%s) mount on %s with runtimeClass %s" , volumeID , target , runtimeClass )
123
- runtimeClassHandler := getValueInMap (context , runtimeClassHandlerField )
124
- if runtimeClassHandler == "" {
125
- runtimeClassHandler = defaultRuntimeClassHandler
126
- }
127
- isConfidentialRuntimeClass , err := isConfidentialRuntimeClassFunc (ctx , d .kubeClient , runtimeClass , runtimeClassHandler )
128
- if err != nil {
129
- return nil , status .Errorf (codes .Internal , "failed to check if runtime class %s is confidential: %v" , runtimeClass , err )
116
+ if d .enableKataCCMount && context [podNameField ] != "" && context [podNamespaceField ] != "" {
117
+ enableKataCCMount := d .isKataNode
118
+ confidentialContainerLabel := getValueInMap (context , confidentialContainerLabelField )
119
+ if ! enableKataCCMount && confidentialContainerLabel != "" {
120
+ klog .V (2 ).Infof ("NodePublishVolume: checking if node %s is a kata node with confidential container label %s" , d .NodeID , confidentialContainerLabel )
121
+ enableKataCCMount = isKataNode (ctx , d .NodeID , confidentialContainerLabel , d .kubeClient )
130
122
}
131
- if isConfidentialRuntimeClass {
132
- klog .V (2 ).Infof ("NodePublishVolume for volume(%s) where runtimeClass is %s" , volumeID , runtimeClass )
133
- source := req .GetStagingTargetPath ()
134
- if len (source ) == 0 {
135
- return nil , status .Error (codes .InvalidArgument , "Staging target not provided" )
136
- }
137
- // Load the mount info from staging area
138
- mountInfo , err := d .directVolume .VolumeMountInfo (source )
123
+
124
+ if enableKataCCMount {
125
+ runtimeClass , err := getRuntimeClassForPodFunc (ctx , d .kubeClient , context [podNameField ], context [podNamespaceField ])
139
126
if err != nil {
140
- return nil , status .Errorf (codes .Internal , "failed to load mount info from %s : %v" , source , err )
127
+ return nil , status .Errorf (codes .Internal , "failed to get runtime class for pod %s/%s : %v" , context [ podNamespaceField ], context [ podNameField ] , err )
141
128
}
142
- if mountInfo == nil {
143
- return nil , status .Errorf (codes .Internal , "mount info is nil for volume %s" , volumeID )
129
+ klog .V (2 ).Infof ("NodePublishVolume: volume(%s) mount on %s with runtimeClass %s" , volumeID , target , runtimeClass )
130
+ runtimeClassHandler := getValueInMap (context , runtimeClassHandlerField )
131
+ if runtimeClassHandler == "" {
132
+ runtimeClassHandler = defaultRuntimeClassHandler
144
133
}
145
- data , err := json . Marshal ( mountInfo )
134
+ isConfidentialRuntimeClass , err := isConfidentialRuntimeClassFunc ( ctx , d . kubeClient , runtimeClass , runtimeClassHandler )
146
135
if err != nil {
147
- return nil , status .Errorf (codes .Internal , "failed to marshal mount info %s : %v" , source , err )
136
+ return nil , status .Errorf (codes .Internal , "failed to check if runtime class %s is confidential : %v" , runtimeClass , err )
148
137
}
149
- if err = d .directVolume .Add (target , string (data )); err != nil {
150
- return nil , status .Errorf (codes .Internal , "failed to save mount info %s: %v" , target , err )
138
+ if isConfidentialRuntimeClass {
139
+ klog .V (2 ).Infof ("NodePublishVolume for volume(%s) where runtimeClass is %s" , volumeID , runtimeClass )
140
+ source := req .GetStagingTargetPath ()
141
+ if len (source ) == 0 {
142
+ return nil , status .Error (codes .InvalidArgument , "Staging target not provided" )
143
+ }
144
+ // Load the mount info from staging area
145
+ mountInfo , err := d .directVolume .VolumeMountInfo (source )
146
+ if err != nil {
147
+ return nil , status .Errorf (codes .Internal , "failed to load mount info from %s: %v" , source , err )
148
+ }
149
+ if mountInfo == nil {
150
+ return nil , status .Errorf (codes .Internal , "mount info is nil for volume %s" , volumeID )
151
+ }
152
+ data , err := json .Marshal (mountInfo )
153
+ if err != nil {
154
+ return nil , status .Errorf (codes .Internal , "failed to marshal mount info %s: %v" , source , err )
155
+ }
156
+ if err = d .directVolume .Add (target , string (data )); err != nil {
157
+ return nil , status .Errorf (codes .Internal , "failed to save mount info %s: %v" , target , err )
158
+ }
159
+ klog .V (2 ).Infof ("NodePublishVolume: direct volume mount %s at %s successfully" , source , target )
160
+ return & csi.NodePublishVolumeResponse {}, nil
151
161
}
152
- klog .V (2 ).Infof ("NodePublishVolume: direct volume mount %s at %s successfully" , source , target )
153
- return & csi.NodePublishVolumeResponse {}, nil
154
162
}
155
163
}
156
164
}
0 commit comments