@@ -20,7 +20,6 @@ import (
2020 "encoding/json"
2121 "fmt"
2222 "math"
23- "reflect"
2423 "runtime/debug"
2524 "strings"
2625 "time"
@@ -190,6 +189,9 @@ func (gr *GenericResources) Cleanup(aw *arbv1.AppWrapper, awr *arbv1.AppWrapperG
190189 return name , gvk , err
191190}
192191
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
193195func (gr * GenericResources ) SyncQueueJob (aw * arbv1.AppWrapper , awr * arbv1.AppWrapperGenericResource ) (podList []* v1.Pod , err error ) {
194196 startTime := time .Now ()
195197 defer func () {
@@ -234,27 +236,32 @@ func (gr *GenericResources) SyncQueueJob(aw *arbv1.AppWrapper, awr *arbv1.AppWra
234236 return []* v1.Pod {}, err
235237 }
236238
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+ // }
246252
247253 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+ // }
258265 var unstruct unstructured.Unstructured
259266 unstruct .Object = make (map [string ]interface {})
260267 var blob interface {}
@@ -307,6 +314,9 @@ func (gr *GenericResources) SyncQueueJob(aw *arbv1.AppWrapper, awr *arbv1.AppWra
307314 newName = newName [:63 ]
308315 }
309316 unstruct .SetName (newName )
317+ //Asumption object is always namespaced
318+ //Refer to comment on line 238
319+ namespaced = true
310320 err = createObject (namespaced , namespace , newName , rsrc , unstruct , dclient )
311321 if err != nil {
312322 if errors .IsAlreadyExists (err ) {
@@ -319,29 +329,30 @@ func (gr *GenericResources) SyncQueueJob(aw *arbv1.AppWrapper, awr *arbv1.AppWra
319329 }
320330
321331 // 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
345356}
346357
347358// checks if object has pod template spec and add new labels
0 commit comments