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