@@ -20,7 +20,6 @@ import (
20
20
"encoding/json"
21
21
"fmt"
22
22
"math"
23
- "reflect"
24
23
"runtime/debug"
25
24
"strings"
26
25
"time"
@@ -190,6 +189,9 @@ func (gr *GenericResources) Cleanup(aw *arbv1.AppWrapper, awr *arbv1.AppWrapperG
190
189
return name , gvk , err
191
190
}
192
191
192
+ //SyncQueueJob uses dynamic clients to unwrap (spawn) items inside genericItems block, it is used to create resources inside etcd and return errors when
193
+ //unwrapping fails.
194
+ //More context here: https://github.com/project-codeflare/multi-cluster-app-dispatcher/issues/598
193
195
func (gr * GenericResources ) SyncQueueJob (aw * arbv1.AppWrapper , awr * arbv1.AppWrapperGenericResource ) (podList []* v1.Pod , err error ) {
194
196
startTime := time .Now ()
195
197
defer func () {
@@ -234,27 +236,32 @@ func (gr *GenericResources) SyncQueueJob(aw *arbv1.AppWrapper, awr *arbv1.AppWra
234
236
return []* v1.Pod {}, err
235
237
}
236
238
237
- _ , apiresourcelist , err := dd .ServerGroupsAndResources ()
238
- if err != nil {
239
- if derr , ok := err .(* discovery.ErrGroupDiscoveryFailed ); ok {
240
- klog .Warning ("Discovery failed for some groups, %d failing: %v" , len (derr .Groups ), err )
241
- } else {
242
- klog .Errorf ("Error getting supported groups and resources, err=%#v" , err )
243
- return []* v1.Pod {}, err
244
- }
245
- }
239
+ //TODO: Simplified apiresourcelist discovery, the assumption is we will always deploy namespaced objects
240
+ //We dont intend to install CRDs like KubeRay, Spark-Operator etc through MCAD, I think such objects are typically
241
+ //cluster scoped. May be for Multi-Cluster or inference use case we need such deep discovery, so for now commenting code.
242
+
243
+ // _, apiresourcelist, err := dd.ServerGroupsAndResources()
244
+ // if err != nil {
245
+ // if derr, ok := err.(*discovery.ErrGroupDiscoveryFailed); ok {
246
+ // klog.Warning("Discovery failed for some groups, %d failing: %v", len(derr.Groups), err)
247
+ // } else {
248
+ // klog.Errorf("Error getting supported groups and resources, err=%#v", err)
249
+ // return []*v1.Pod{}, err
250
+ // }
251
+ // }
246
252
247
253
rsrc := mapping .Resource
248
- for _ , apiresourcegroup := range apiresourcelist {
249
- if apiresourcegroup .GroupVersion == join (mapping .GroupVersionKind .Group , "/" , mapping .GroupVersionKind .Version ) {
250
- for _ , apiresource := range apiresourcegroup .APIResources {
251
- if apiresource .Name == mapping .Resource .Resource && apiresource .Kind == mapping .GroupVersionKind .Kind {
252
- rsrc = mapping .Resource
253
- namespaced = apiresource .Namespaced
254
- }
255
- }
256
- }
257
- }
254
+
255
+ // for _, apiresourcegroup := range apiresourcelist {
256
+ // if apiresourcegroup.GroupVersion == join(mapping.GroupVersionKind.Group, "/", mapping.GroupVersionKind.Version) {
257
+ // for _, apiresource := range apiresourcegroup.APIResources {
258
+ // if apiresource.Name == mapping.Resource.Resource && apiresource.Kind == mapping.GroupVersionKind.Kind {
259
+ // rsrc = mapping.Resource
260
+ // namespaced = apiresource.Namespaced
261
+ // }
262
+ // }
263
+ // }
264
+ // }
258
265
var unstruct unstructured.Unstructured
259
266
unstruct .Object = make (map [string ]interface {})
260
267
var blob interface {}
@@ -307,6 +314,9 @@ func (gr *GenericResources) SyncQueueJob(aw *arbv1.AppWrapper, awr *arbv1.AppWra
307
314
newName = newName [:63 ]
308
315
}
309
316
unstruct .SetName (newName )
317
+ //Asumption object is always namespaced
318
+ //Refer to comment on line 238
319
+ namespaced = true
310
320
err = createObject (namespaced , namespace , newName , rsrc , unstruct , dclient )
311
321
if err != nil {
312
322
if errors .IsAlreadyExists (err ) {
@@ -319,29 +329,30 @@ func (gr *GenericResources) SyncQueueJob(aw *arbv1.AppWrapper, awr *arbv1.AppWra
319
329
}
320
330
321
331
// Get the related resources of created object
322
- var thisObj * unstructured.Unstructured
323
- var err1 error
324
- if namespaced {
325
- thisObj , err1 = dclient .Resource (rsrc ).Namespace (namespace ).Get (context .Background (), name , metav1.GetOptions {})
326
- } else {
327
- thisObj , err1 = dclient .Resource (rsrc ).Get (context .Background (), name , metav1.GetOptions {})
328
- }
329
- if err1 != nil {
330
- klog .Errorf ("Could not get created resource with error %v" , err1 )
331
- return []* v1.Pod {}, err1
332
- }
333
- thisOwnerRef := metav1 .NewControllerRef (thisObj , thisObj .GroupVersionKind ())
334
-
335
- podL , _ := gr .clients .CoreV1 ().Pods ("" ).List (context .Background (), metav1.ListOptions {})
336
- pods := []* v1.Pod {}
337
- for _ , pod := range (* podL ).Items {
338
- parent := metav1 .GetControllerOf (& pod )
339
- if reflect .DeepEqual (thisOwnerRef , parent ) {
340
- pods = append (pods , & pod )
341
- }
342
- klog .V (10 ).Infof ("[SyncQueueJob] pod %s created from a Generic Item\n " , pod .Name )
343
- }
344
- return pods , nil
332
+ // var thisObj *unstructured.Unstructured
333
+ //var err1 error
334
+ // if namespaced {
335
+ // thisObj, err1 = dclient.Resource(rsrc).Namespace(namespace).Get(context.Background(), name, metav1.GetOptions{})
336
+ // } else {
337
+ // thisObj, err1 = dclient.Resource(rsrc).Get(context.Background(), name, metav1.GetOptions{})
338
+ // }
339
+ // if err1 != nil {
340
+ // klog.Errorf("Could not get created resource with error %v", err1)
341
+ // return []*v1.Pod{}, err1
342
+ // }
343
+ // thisOwnerRef := metav1.NewControllerRef(thisObj, thisObj.GroupVersionKind())
344
+
345
+ // podL, _ := gr.clients.CoreV1().Pods("").List(context.Background(), metav1.ListOptions{})
346
+ // pods := []*v1.Pod{}
347
+ // for _, pod := range (*podL).Items {
348
+ // parent := metav1.GetControllerOf(&pod)
349
+ // if reflect.DeepEqual(thisOwnerRef, parent) {
350
+ // pods = append(pods, &pod)
351
+ // }
352
+ // klog.V(10).Infof("[SyncQueueJob] pod %s created from a Generic Item\n", pod.Name)
353
+ // }
354
+ // return pods, nil
355
+ return []* v1.Pod {}, nil
345
356
}
346
357
347
358
// checks if object has pod template spec and add new labels
0 commit comments