@@ -183,6 +183,106 @@ app.get("/api/queue/:name/yaml", async (req, res) => {
183183 }
184184} ) ;
185185
186+ app . put ( "/api/queues/:name" , express . json ( ) , async ( req , res ) => {
187+ const name = req . params . name ;
188+ const updatedBody = req . body ;
189+
190+ try {
191+ console . log (
192+ `Attempting to update queue ${ name } with:` ,
193+ JSON . stringify ( updatedBody ) ,
194+ ) ;
195+
196+ // Validate the request body
197+ if ( ! updatedBody . spec || Object . keys ( updatedBody . spec ) . length === 0 ) {
198+ return res . status ( 400 ) . json ( {
199+ error : "Bad Request" ,
200+ details : "spec object is required and cannot be empty" ,
201+ } ) ;
202+ }
203+
204+ // First, verify the queue exists
205+ try {
206+ await k8sApi . getClusterCustomObject ( {
207+ group : "scheduling.volcano.sh" ,
208+ version : "v1beta1" ,
209+ plural : "queues" ,
210+ name : name ,
211+ } ) ;
212+ console . log ( `Found existing queue ${ name } ` ) ;
213+ } catch ( err ) {
214+ console . error ( `Queue ${ name } not found:` , err ) ;
215+ return res . status ( 404 ) . json ( {
216+ error : "Not Found" ,
217+ details : `Queue ${ name } not found` ,
218+ } ) ;
219+ }
220+
221+ // Convert numeric fields in spec from string to integer if needed
222+ const numericFields = new Set ( [ "weight" ] ) ; // Add more fields here if needed
223+
224+ const patchOperations = [ ] ;
225+
226+ Object . entries ( updatedBody . spec ) . forEach ( ( [ key , value ] ) => {
227+ let val = value ;
228+
229+ if ( numericFields . has ( key ) && typeof val === "string" ) {
230+ const parsed = parseInt ( val , 10 ) ;
231+ if ( ! isNaN ( parsed ) ) {
232+ val = parsed ;
233+ }
234+ }
235+
236+ patchOperations . push ( {
237+ op : "replace" ,
238+ path : `/spec/${ key } ` ,
239+ value : val ,
240+ } ) ;
241+ } ) ;
242+
243+ console . log (
244+ "Using JSON Patch operations:" ,
245+ JSON . stringify ( patchOperations ) ,
246+ ) ;
247+
248+ // Apply the patch and capture the response
249+ const response = await k8sApi . patchClusterCustomObject ( {
250+ group : "scheduling.volcano.sh" ,
251+ version : "v1beta1" ,
252+ plural : "queues" ,
253+ name : name ,
254+ body : patchOperations ,
255+ options : {
256+ headers : {
257+ "Content-Type" : "application/json-patch+json" ,
258+ } ,
259+ } ,
260+ } ) ;
261+
262+ console . log ( "Patch response:" , JSON . stringify ( response . body , null , 2 ) ) ;
263+
264+ // Get and return the fully updated queue
265+ const updatedQueue = await k8sApi . getClusterCustomObject ( {
266+ group : "scheduling.volcano.sh" ,
267+ version : "v1beta1" ,
268+ plural : "queues" ,
269+ name : name ,
270+ } ) ;
271+
272+ res . json ( {
273+ message : `Successfully updated queue ${ name } ` ,
274+ patchResponse : response . body ,
275+ updatedQueue : updatedQueue . body ,
276+ } ) ;
277+ } catch ( err ) {
278+ console . error ( `Error updating queue ${ name } :` , err ) ;
279+ res . status ( 500 ) . json ( {
280+ error : `Failed to update queue ${ name } ` ,
281+ details : err . body ?. message || err . message ,
282+ rawError : err . toString ( ) ,
283+ } ) ;
284+ }
285+ } ) ;
186286// Get all Volcano Queues
187287app . get ( "/api/queues" , async ( req , res ) => {
188288 try {
0 commit comments